/*
  3DT GUI - the one common stylesheet for every page shown in the GUI's
  content frame. Two page types share it:
    - map page      (.map-page): full-bleed Leaflet map + right-hand panel
                    (CIRCUITS > TRACK LIBRARY, CIRCUITS > WHITELINE EDITOR)
    - content page  (CONFIG > ONBOARD): panel without a map
  A page keeps only what is truly its own (map markers, special widgets).

  Colours: never written here as values. Layer 1 is the official palette
  (colors.css); layer 2 below gives each colour its ROLE. To restyle, change a
  colour in colors.css, or point a role at another palette colour here.
*/
@import "colors.css";

/* ---- Layer 2: roles ---- */
:root {
    --ui-page-bg:        var(--3dt-dark-grey);    /* every page = the selected subnav item (styles.css) */
    --ui-panel-bg:       var(--3dt-dark-grey);    /* right-hand panel, map page shell */
    --ui-section-bg:     var(--3dt-dark-grey);    /* cards (grouped by their border) */
    --ui-highlight-bg:   var(--3dt-black);        /* hover / active tab, toggle hover */
    --ui-line:           var(--3dt-medium-grey);  /* borders: tabs, map controls, collapse button */
    --ui-soft-line:      color-mix(in srgb, var(--3dt-medium-grey) 40%, transparent); /* discreet border: cards, fields and values (owner, 2026-09-30) */
    --ui-divider:        var(--3dt-medium-grey);  /* separators */
    --ui-scroll:         var(--3dt-medium-grey);  /* scrollbar thumb */
    --ui-text:           var(--3dt-white);        /* content: values, fields, choices, headings */
    --ui-label:          var(--3dt-light-grey);   /* labels and information (e.g. "DB file: ...", status lines) */
    --ui-muted:          var(--3dt-medium-grey);  /* read-only / disabled values (on black fields) */
    --ui-input-bg:       var(--3dt-black);
    --ui-accent:         var(--3dt-orange);       /* active tab (as the nav's active item) */
    --ui-select:         var(--3dt-blue);         /* selected option (checkboxes, radios) */
    --ui-btn-text:       var(--3dt-white);
    --ui-btn-primary:    var(--3dt-dark-green);   /* add / load / update / export */
    --ui-btn-danger:     var(--3dt-red);          /* remove / reject */
    --ui-btn-neutral:    var(--3dt-black);        /* secondary actions */
    --ui-btn-gap:        10px;                    /* between buttons side by side (ADD CIRCUIT | ADD LAYOUT | REMOVE) */
    --ui-ok:             var(--3dt-green);
    --ui-fail:           var(--3dt-red);
    --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ---- Base ---- */
html, body {
    height: 100%;
    margin: 0;
    background-color: var(--ui-page-bg);
    color: var(--ui-text);
    font-family: var(--ui-font);
    font-size: 13px;
}
body:has(> .map-page) { overflow: hidden; } /* map pages fill the frame exactly; content pages scroll */
input, select, button, textarea { accent-color: var(--ui-select); }
:focus, :focus-visible { outline: none; }  /* no focus ring on fields/buttons (owner, 2026-09-30) */

/* Plain form fields anywhere (login, content pages); field rows refine the layout. */
input[type="text"], input[type="password"], input[type="number"], select, textarea {
    background-color: var(--ui-input-bg);
    color: var(--ui-text);
    border: 1px solid var(--ui-soft-line);
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 12px;
    font-family: inherit;
}
/* Chrome autofill paints fields light blue: keep them black with white text. */
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px var(--ui-input-bg) inset;
    -webkit-text-fill-color: var(--ui-text);
    caret-color: var(--ui-text);
}

/* ---- Map page shell: map + right-hand panel ---- */
.map-page {
    position: relative; /* anchors .rhs-toggle */
    display: flex;
    height: 100vh;
    overflow: hidden;
    background-color: var(--ui-panel-bg);
    /* Twice the left navbar's 250px - one value for the panel width and the
       toggle's distance from the right edge, so the button always sits on
       the map/panel boundary. */
    --rhs-width: 500px;
}
.map-canvas { flex: 1; min-width: 0; height: 100%; }

/* Collapse button: floats over the map on the map/panel boundary, stays
   clickable while the panel is collapsed. Above Leaflet's controls (1000). */
.rhs-toggle {
    position: absolute;
    top: 50%;
    right: var(--rhs-width);
    transform: translateY(-50%);
    z-index: 1001;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--ui-panel-bg);
    border: 1px solid var(--ui-line);
    border-radius: 4px;
    cursor: pointer;
    transition: right 0.2s;
}
.rhs-toggle::after { /* CSS triangle, mirrored when collapsed */
    content: "";
    display: block;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 6px solid var(--ui-text);
}
.rhs-toggle:hover { background-color: var(--ui-highlight-bg); }
.rhs-toggle.collapsed { right: 0; transform: translateY(-50%) scaleX(-1); }

.rhs-bar {
    width: var(--rhs-width);
    flex-shrink: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    background-color: var(--ui-panel-bg);
    box-sizing: border-box;
    padding: 20px 20px 0 20px;
    transition: width 0.2s, padding 0.2s;
}
.rhs-bar.collapsed { width: 0; padding: 0; overflow: hidden; }

/* Only the content scrolls; picker/tabs above and the footer below stay put. */
.rhs-form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.rhs-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: 20px;
    scrollbar-width: thin;
    scrollbar-color: var(--ui-scroll) var(--ui-panel-bg);
}
.rhs-scroll::-webkit-scrollbar { width: 8px; }
.rhs-scroll::-webkit-scrollbar-track { background: var(--ui-panel-bg); }
.rhs-scroll::-webkit-scrollbar-thumb { background-color: var(--ui-scroll); border-radius: 4px; }

.rhs-footer {
    flex-shrink: 0;
    background-color: var(--ui-panel-bg);
    padding-top: 16px;
    padding-bottom: 20px;
    margin-top: 8px;
    border-top: 1px solid var(--ui-divider);
    display: flex;
    align-items: center;
    gap: var(--ui-btn-gap);
    flex-wrap: wrap;
}

/* ---- Content page shell: the same 500 px panel, docked left, no map (CONFIG > ONBOARD) ---- */
.panel-page {
    display: flex;
    flex-direction: column;
    width: 500px;
    flex-shrink: 0;
    height: 100vh;
    box-sizing: border-box;
    background-color: var(--ui-panel-bg);
    padding: 20px 20px 0 20px;
}
body:has(> .panel-page) { overflow: hidden; } /* only the panel's .rhs-scroll scrolls */

/* ---- Panel content ---- */
.rhs-picker { display: flex; align-items: center; gap: var(--ui-btn-gap); margin-bottom: 16px; flex-wrap: wrap; }
.rhs-select {
    flex: 1;
    min-width: 140px;
    background-color: var(--ui-input-bg);
    color: var(--ui-text);
    border: 1px solid var(--ui-soft-line);
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 12px;
}
.rhs-picker-meta { color: var(--ui-label); font-size: 11px; width: 100%; }

/* Tabs: same selection logic as the lefthand navbar (solid background swap,
   accent colour for the active label). */
.rhs-tabs { display: flex; border-bottom: 1px solid var(--ui-line); margin-bottom: 16px; }
.rhs-tab {
    flex: 1;
    background: none;
    border: none;
    color: var(--ui-text);
    padding: 10px 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
}
.rhs-tab:hover { background-color: var(--ui-highlight-bg); color: var(--ui-text); }
.rhs-tab.active { background-color: var(--ui-highlight-bg); color: var(--ui-accent); font-weight: bold; }
/* Many tabs (ONBOARD's chapters): auto-sized, wrapping onto more rows. */
.rhs-tabs.wrap { flex-wrap: wrap; }
.rhs-tabs.wrap .rhs-tab { flex: 1 0 auto; padding: 10px 8px; }

.rhs-section-header {
    font-size: 12px;
    text-transform: uppercase;
    font-weight: bold;
    color: var(--ui-text);
    margin: 20px 0 10px 0;
    padding-top: 16px;
    border-top: 1px solid var(--ui-divider);
}
.rhs-card {
    border: 1px solid var(--ui-soft-line);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
    background-color: var(--ui-section-bg);
}

/* Label beside value: the value column is always 65 % of the row; a long
   label wraps instead of squeezing its value. */
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.field-row label { color: var(--ui-label); font-size: 12px; }
.field-row > label { flex: 1 1 auto; min-width: 0; margin: 0; }
.field-row > input,
.field-row > select,
.field-row-pair input[type="text"],
.ui-textarea {
    box-sizing: border-box; /* keeps border+padding inside the 65 % */
    background-color: var(--ui-input-bg);
    color: var(--ui-text);
    border: 1px solid var(--ui-soft-line);
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 12px;
}
.ui-textarea { font-family: inherit; }
.field-row > input,
.field-row > select { flex: 0 0 65%; max-width: 65%; }
.field-row input:disabled,
.field-row input:read-only { color: var(--ui-muted); }
.field-row-pair { display: flex; align-items: center; gap: 8px; flex: 0 0 65%; min-width: 0; max-width: 65%; }
.field-row-pair input[type="text"] { flex: 1; width: 0; min-width: 0; }
.field-row-pair .btn { flex: none; }
.field-row .ui-radio { display: flex; align-items: center; gap: 4px; color: var(--ui-text); font-size: 12px; } /* a choice is content, not a label */

/* Card title; .card-head puts buttons on the title's right (e.g. Undo / Redo). */
.rhs-card > h3 { margin: 0 0 10px 0; font-size: 12px; text-transform: uppercase; color: var(--ui-text); }
.rhs-card > h3.card-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.card-head-btns { display: flex; gap: var(--ui-btn-gap); }

/* Buttons are as wide as their name (owner, 2026-10-12): left-aligned on a page or the panel itself,
   right-aligned inside a section (card, dialog); buttons next to each other share one .ui-btn-row. */
.rhs-card > .btn { display: block; width: fit-content; margin: 0 0 6px auto; }
.rhs-card > .ui-btn-row { display: flex; justify-content: flex-end; gap: var(--ui-btn-gap); margin: 0 0 6px; }

/* Status / result text under a control. */
.ui-status { font-size: 11px; color: var(--ui-label); margin: 0 0 8px; white-space: pre-line; }
.ui-status:empty { display: none; }

/* Slim progress bar. */
.ui-progress {
    display: block; width: 100%; height: 6px; margin: 0 0 6px;
    -webkit-appearance: none; appearance: none;
    border: none; border-radius: 3px; background: var(--ui-line); overflow: hidden;
}
.ui-progress::-webkit-progress-bar { background: var(--ui-line); border-radius: 3px; }
.ui-progress::-webkit-progress-value { background: var(--ui-ok); border-radius: 3px; }
.ui-progress::-moz-progress-bar { background: var(--ui-ok); border-radius: 3px; }

/* ---- Buttons: one shape for the whole GUI, only the colour changes ---- */
.btn {
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--ui-btn-text);
}
.btn-green   { background-color: var(--ui-btn-primary); }
.btn-red     { background-color: var(--ui-btn-danger); }
.btn-neutral { background-color: var(--ui-btn-neutral); }
/* Hover = white outline, so no shades outside the official colours are needed. */
.btn:hover:not(:disabled) { box-shadow: inset 0 0 0 2px var(--ui-text); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-small { padding: 4px 10px; font-size: 11px; }

/* ---- Deploy dialog (TRACK LIBRARY: circuits.sqlite, ONBOARD: config.yaml) ---- */
.deploy-modal-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0, 0, 0, 0.6); /* black 60 % */
    z-index: 2000;
    align-items: center;
    justify-content: center;
}
.deploy-modal-backdrop.open { display: flex; }
.deploy-modal {
    background-color: var(--ui-section-bg);
    border: 1px solid var(--ui-line);
    border-radius: 6px;
    padding: 20px;
    width: 360px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    color: var(--ui-text);
    font-family: var(--ui-font);
}
.deploy-modal h3 { margin: 0 0 12px 0; font-size: 14px; text-transform: uppercase; }
.deploy-modal-hint { margin-bottom: 10px; color: var(--ui-label); }
.deploy-modal textarea {
    width: 100%;
    box-sizing: border-box;
    min-height: 70px;
    background-color: var(--ui-input-bg);
    color: var(--ui-text);
    border: 1px solid var(--ui-soft-line);
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 12px;
    font-family: inherit;
    resize: vertical;
}
.deploy-reboot-label { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 12px; color: var(--ui-label); cursor: pointer; }
.deploy-modal-actions { display: flex; justify-content: flex-end; gap: var(--ui-btn-gap); margin-top: 12px; }
.deploy-status { margin-top: 10px; font-size: 12px; color: var(--ui-label); }
.deploy-results { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.deploy-result-row { display: flex; align-items: flex-start; gap: 8px; font-size: 12px; }
.deploy-result-dot { flex-shrink: 0; width: 8px; height: 8px; border-radius: 50%; margin-top: 4px; }
.deploy-result-dot.success { background-color: var(--ui-ok); }
.deploy-result-dot.failure { background-color: var(--ui-fail); }

/* ---- Leaflet controls in the GUI's colours (map pages) ---- */
.leaflet-bar a,
.leaflet-bar a:hover { background-color: var(--ui-panel-bg); color: var(--ui-text); border-bottom-color: var(--ui-line); }
.leaflet-bar a:hover { box-shadow: inset 0 0 0 2px var(--ui-text); }
.leaflet-bar { border-color: var(--ui-line) !important; }
.leaflet-control-layers { background-color: var(--ui-panel-bg); color: var(--ui-text); border: 1px solid var(--ui-line) !important; }
.leaflet-control-layers-separator { border-top-color: var(--ui-line); }
.leaflet-container .leaflet-control-attribution { background-color: var(--ui-panel-bg); color: var(--ui-text); }
.leaflet-container .leaflet-control-attribution a { color: var(--ui-text); }

/* Layers button: Leaflet's grey picture replaced by the same stack icon drawn in --ui-text. */
.leaflet-control-layers-toggle,
.leaflet-retina .leaflet-control-layers-toggle {
    background-image: none;
    position: relative;
}
.leaflet-control-layers-toggle::after {
    content: "";
    position: absolute;
    inset: 9px;
    background-color: var(--ui-text);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2 1 7l11 5 11-5-11-5zm0 12.5L3.2 10.6 1 11.6l11 5 11-5-2.2-1L12 14.5zm0 4.5-8.8-3.9L1 16.1l11 5 11-5-2.2-1L12 19z'/%3E%3C/svg%3E") center / contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2 1 7l11 5 11-5-11-5zm0 12.5L3.2 10.6 1 11.6l11 5 11-5-2.2-1L12 14.5zm0 4.5-8.8-3.9L1 16.1l11 5 11-5-2.2-1L12 19z'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* Map labels (Start-Finish, T9, ...): GUI colours, fully opaque (Leaflet fades them to 90 %). */
.leaflet-tooltip {
    background-color: var(--ui-panel-bg);
    color: var(--ui-text);
    border: 1px solid var(--ui-line);
    box-shadow: none;
    opacity: 1 !important;
}
.leaflet-tooltip-top::before    { border-top-color: var(--ui-line); }
.leaflet-tooltip-bottom::before { border-bottom-color: var(--ui-line); }
.leaflet-tooltip-left::before   { border-left-color: var(--ui-line); }
.leaflet-tooltip-right::before  { border-right-color: var(--ui-line); }

/* Popups (e.g. a whiteline's file name) in the same colours. */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background-color: var(--ui-panel-bg); color: var(--ui-text); border: 1px solid var(--ui-line); box-shadow: none; }
.leaflet-container a.leaflet-popup-close-button { color: var(--ui-text); }
