:root {
    --text-color: #1f2933;
    --bg-light: #fdfaf6;
    --surface: #ffffff;
    --panel-bg: #263238;
    --panel-text: #ffffff;
    --border: rgba(0, 0, 0, 0.15);
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.14);
    --radius-lg: 16px;
    --radius-md: 10px;
}

html[data-theme="dark"] {
    --text-color: #ffd700;
    --bg-light: #1e1e1e;
    --surface: #242424;
    --panel-bg: #121212;
    --panel-text: #ffd700;
    --border: rgba(255, 215, 0, 0.25);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    background-color: var(--bg-light);
    color: var(--text-color);
}

/* ============================================================
   SHARED PARTS MENU
   Uses the same part images as CAD Parts Repair.
   ============================================================ */


.conveyor-part-menu-content {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.conveyor-part-menu-thumb {
    width: 36px;
    height: 36px;
    object-fit: contain;
    flex: 0 0 36px;
    pointer-events: none;
}

.shared-part-menu-item {
    text-align: left;
}

.shared-part-menu-item span {
    pointer-events: none;
}

.conveyor-app {
    width: min(1400px, 100%);
    margin: 0 auto;
    padding: 1rem;
}

.conveyor-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
}

.conveyor-header h1 {
    margin: 0;
}

.conveyor-header p {
    margin: 0.35rem 0 0;
}

.back-link {
    font-weight: 800;
    color: #0d6efd;
    text-decoration: none;
}

.zone-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: end;
    padding: 1rem;
    margin-bottom: 1rem;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.zone-toolbar label {
    flex: 1 1 360px;
    font-weight: 800;
    text-align: left;
}

.zone-toolbar input {
    width: 100%;
    margin-top: 0.35rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font: inherit;
}

.zone-toolbar button,
.zone-properties-panel button {
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 999px;
    background-color: #0d6efd;
    color: white;
    font-weight: 800;
    cursor: pointer;
}

.conveyor-layout {
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr) 260px;
    gap: 1rem;
    align-items: start;
}

.conveyor-menu,
.zone-properties-panel {
    padding: 1rem;
    background-color: var(--panel-bg);
    color: var(--panel-text);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.conveyor-menu h2,
.zone-properties-panel h2 {
    margin-top: 0;
    font-size: 1rem;
}

.conveyor-menu-item {
    display: block;
    width: 100%;
    margin-bottom: 0.65rem;
    padding: 0.75rem;
    border: none;
    border-radius: var(--radius-md);
    background-color: #3d4a57;
    color: white;
    font-weight: 800;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.zone-board-wrap {
    overflow: auto;
}

.zone-board {
    position: relative;
    width: 1000px;
    height: 650px;
    background:
        linear-gradient(rgba(0, 0, 0, 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 0, 0, 0.06) 1px, transparent 1px),
        #f4f4f4;
    background-size: 25px 25px;
    border: 3px solid #263238;
    border-radius: var(--radius-lg);
    overflow: hidden;
    touch-action: none;
    box-shadow: var(--shadow);
}

.zone-board-hint {
    position: absolute;
    left: 1rem;
    top: 1rem;
    margin: 0;
    color: #777;
    font-weight: 800;
    pointer-events: none;
}

.zone-item,
.zone-preview {
    position: absolute;
    width: 220px;
    height: 70px;
    border: 2px solid #1f2933;
    border-radius: var(--radius-md);
    background-color: #d9e7f7;
    color: #111;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    cursor: grab;
    user-select: none;
    touch-action: none;
    box-shadow: 0 5px 14px rgba(0, 0, 0, 0.22);
}

.zone-item.selected {
    outline: 4px solid #ffd700;
}

.zone-preview {
    position: fixed;
    pointer-events: none;
    opacity: 0.75;
    z-index: 9999;
}

.zone-item[data-type="curve-90"] {
    border-radius: 50% 12px 12px 50%;
}

.zone-item[data-type="merge"],
.zone-item[data-type="divert"] {
    background-color: #ffe1a8;
}

.zone-item[data-type="photoeye"],
.zone-item[data-type="motor"],
.zone-item[data-type="e-stop"] {
    width: 90px;
    height: 55px;
    background-color: #d6f5d6;
    font-size: 0.8rem;
}

.zone-properties-panel label {
    display: block;
    margin-bottom: 0.75rem;
    font-weight: 800;
}

.zone-properties-panel input,
.zone-properties-panel textarea {
    width: 100%;
    margin-top: 0.35rem;
    padding: 0.65rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    font: inherit;
}

.zone-properties-panel textarea {
    min-height: 90px;
    resize: vertical;
}

@media (max-width: 1000px) {
    .conveyor-layout {
        grid-template-columns: 1fr;
    }

    .conveyor-menu,
    .zone-properties-panel {
        width: 100%;
    }
}


.property-button-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.zone-item {
    transform-origin: center center;
}

.zone-item[data-type="straight-belt"]::after,
.zone-item[data-type="roller"]::after,
.zone-item[data-type="merge"]::after,
.zone-item[data-type="divert"]::after {
    content: "➜";
    position: absolute;
    right: 0.65rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.3rem;
    opacity: 0.7;
}

/* ============================================================
   ATTACHED PART INDICATOR
   Shows when a part is mounted to a conveyor.
   ============================================================ */

.zone-item[data-kind="part"].attached-to-conveyor {
    outline: 3px solid #198754;
    box-shadow:
        0 0 0 4px rgba(25, 135, 84, 0.2),
        0 5px 14px rgba(0, 0, 0, 0.22);
}

.zone-item[data-kind="part"].attached-to-conveyor::before {
    content: "●";
    position: absolute;
    top: -0.55rem;
    right: -0.55rem;

    width: 1.1rem;
    height: 1.1rem;

    display: flex;
    align-items: center;
    justify-content: center;

    background-color: #198754;
    color: #ffffff;

    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 900;
}

/* ============================================================
   CONVEYOR RESIZE HANDLE
   Allows conveyors to be stretched to match real-world layouts.
   ============================================================ */

.zone-item-label {
    pointer-events: none;
    padding: 0.25rem 1.25rem 0.25rem 0.5rem;
    text-align: center;
}

.zone-resize-handle {
    position: absolute;
    right: -0.55rem;
    bottom: -0.55rem;

    width: 1.15rem;
    height: 1.15rem;

    border: 2px solid #ffffff;
    border-radius: 50%;

    background-color: #0d6efd;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);

    cursor: nwse-resize;
    touch-action: none;
    z-index: 20;
}

.zone-resize-handle:hover {
    transform: scale(1.15);
}

.zone-preview .zone-resize-handle {
    display: none;
}

/* ============================================================
   ZONE ITEM IMAGES
   Shows shared catalog part images on Conveyor Locations CAD.
   ============================================================ */

.zone-item-image {
    pointer-events: none;
}

.zone-item[data-kind="part"] {
    width: 90px;
    height: 55px;
    background-color: #d6f5d6;
    font-size: 0.75rem;
}

.zone-item[data-kind="part"] .zone-item-label {
    padding: 0.15rem;
}

/* ============================================================
   CONVEYOR CAD SHARED PARTS MENU FORMATTING
   Makes the shared parts catalog visually match the conveyor menu.
   ============================================================ */

.conveyor-parts-menu-tree {
    max-height: 360px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

/* Main dropdown category wrapper */
.conveyor-parts-menu-tree .parts-category {
    margin-bottom: 0.55rem;
}

/* Dropdown category headers: Sensors, Motors, Controls, etc. */
.conveyor-parts-menu-tree .parts-category > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;

    width: 100%;
    padding: 0.75rem;

    border-radius: var(--radius-md);
    background-color: #3d4a57;
    color: #ffffff;

    font-weight: 800;
    cursor: pointer;
    user-select: none;

    list-style: none;
}

/* Remove default browser triangle */
.conveyor-parts-menu-tree .parts-category > summary::-webkit-details-marker {
    display: none;
}

/* Custom dropdown arrow */
.conveyor-parts-menu-tree .parts-category > summary::after {
    content: "▸";
    font-size: 0.85rem;
    transition: transform 0.2s ease;
}

/* Rotate arrow when open */
.conveyor-parts-menu-tree .parts-category[open] > summary::after {
    transform: rotate(90deg);
}

/* Hover effect for category headers */
.conveyor-parts-menu-tree .parts-category > summary:hover {
    background-color: #4b5a68;
}

/* Nested content area */
.conveyor-parts-menu-tree .parts-children {
    margin-top: 0.45rem;
    margin-left: 0.45rem;
    padding-left: 0.55rem;

    border-left: 2px solid rgba(255, 255, 255, 0.18);
}

/* Nested categories should be slightly smaller/subdued */
.conveyor-parts-menu-tree .parts-children .parts-category > summary {
    padding: 0.65rem 0.7rem;
    background-color: #33414d;
    font-size: 0.9rem;
}

/* Actual draggable shared part buttons */
.conveyor-parts-menu-tree .shared-part-menu-item {
    display: block;
    width: 100%;

    margin-bottom: 0.5rem;
    padding: 0.6rem 0.65rem;

    border: none;
    border-radius: var(--radius-md);

    background-color: #263238;
    color: #ffffff;

    font-weight: 800;
    text-align: left;

    cursor: grab;
    touch-action: none;
    user-select: none;

    transition:
        background-color 0.2s ease,
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.conveyor-parts-menu-tree .shared-part-menu-item:hover {
    background-color: #0d6efd;
    transform: translateY(-1px);
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.25);
}

.conveyor-parts-menu-tree .shared-part-menu-item:active {
    cursor: grabbing;
    transform: translateY(0);
}

/* Thumbnail + label layout */
.conveyor-part-menu-content {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
}

/* Part thumbnails */
.conveyor-part-menu-thumb {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;

    object-fit: contain;

    background-color: rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    padding: 0.2rem;

    pointer-events: none;
}

/* Prevent image/text inside button from stealing pointer events */
.conveyor-part-menu-content,
.conveyor-part-menu-content span,
.conveyor-part-menu-thumb {
    pointer-events: none;
}

/* Scrollbar cleanup for the shared parts list */
.conveyor-parts-menu-tree::-webkit-scrollbar {
    width: 8px;
}

.conveyor-parts-menu-tree::-webkit-scrollbar-track {
    background-color: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
}

.conveyor-parts-menu-tree::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.28);
    border-radius: 999px;
}

.conveyor-parts-menu-tree::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.42);
}

/* ============================================================
   CONVEYOR / PART LAYERING
   ------------------------------------------------------------
   Conveyors are the base layer.
   Mounted parts sit above conveyors.
   Selected parts sit above everything else.
   ============================================================ */

/* Base conveyor layer */
.zone-item[data-kind="conveyor"] {
    z-index: 10;
}

/* Mounted parts should always appear above conveyors */
.zone-item[data-kind="part"] {
    z-index: 40;
}

/* Selected conveyor should highlight, but still stay below parts */
.zone-item[data-kind="conveyor"].selected {
    z-index: 20;
}

/* Selected parts should rise above everything */
.zone-item[data-kind="part"].selected {
    z-index: 70;
}

/* Attached parts should also stay above conveyors */
.zone-item[data-kind="part"].attached-to-conveyor {
    z-index: 60;
}

/* Resize handle needs to stay clickable on conveyors */
.zone-item[data-kind="conveyor"] .zone-resize-handle {
    z-index: 25;
}

/* Drag preview should always be on top while dragging */
.zone-preview {
    z-index: 9999;
}

/* ============================================================
   CONVEYOR IMAGE DISPLAY
   ------------------------------------------------------------
   Conveyor images fill the conveyor block.
   Part images stay small and readable.
   ============================================================ */

.zone-item {
    overflow: visible;
}

/* Conveyor blocks become image containers */
.zone-item[data-kind="conveyor"] {
    background-color: transparent;
}

/* Main conveyor image */
.zone-conveyor-image {
    position: absolute;
    inset: 0;

    width: 100%;
    height: 100%;

    object-fit: fill;
    pointer-events: none;

    border-radius: var(--radius-md);
}

/* Conveyor label sits on top of the conveyor image */
.zone-item[data-kind="conveyor"] .zone-item-label {
    position: relative;
    z-index: 12;

    padding: 0.25rem 0.55rem;

    background-color: rgba(255, 255, 255, 0.82);
    color: #111111;

    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 900;

    text-shadow: none;
}

/* Part image stays compact */
.zone-part-image {
    max-width: 42px;
    max-height: 42px;
    object-fit: contain;
    margin-right: 0.35rem;
    pointer-events: none;
}

/* Keep resize handle above the conveyor image */
.zone-item[data-kind="conveyor"] .zone-resize-handle {
    z-index: 30;
}

/* Keep selected outline visible above conveyor image */
.zone-item.selected {
    z-index: 80;
}


