/* =========================================================================
   simpleCAD — 2D CAD / drafting tool
   Dark theme, mobile-first. Full-height shell below the shared navbar v2.
   The navbar paints its own (.tt-scope) palette; everything here is the tool.
   ========================================================================= */

:root {
    /* Seed the shared navbar height (published live by tt-navbar.js) */
    --tt-topnav-h: 64px;

    --bg:        #0a0a0f;
    --bg-2:      #0e0e15;
    --panel:     #14141d;
    --panel-2:   #1a1a26;
    --inset:     #101019;
    --border:    rgba(255, 255, 255, 0.10);
    --border-2:  rgba(255, 255, 255, 0.16);

    --text:      #f2f3f8;
    --text-2:    rgba(242, 243, 248, 0.72);
    --text-3:    rgba(242, 243, 248, 0.46);

    --indigo:    #6366f1;
    --violet:    #8b5cf6;
    --cyan:      #06b6d4;
    --green:     #22c55e;
    --amber:     #f59e0b;
    --red:       #f87171;

    --accent:    var(--indigo);
    --accent-2:  var(--cyan);
    --grad:      linear-gradient(135deg, var(--indigo), var(--cyan));

    /* Drawing surface (painted on the canvas in JS; mirrored here for chrome) */
    --paper:     #0c0c12;
    --grid-minor: rgba(255, 255, 255, 0.045);
    --grid-major: rgba(255, 255, 255, 0.10);
    --axis:      rgba(120, 140, 255, 0.55);

    --r-sm: 7px;
    --r-md: 11px;
    --r-lg: 16px;

    --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    --shadow: 0 18px 50px -22px rgba(0, 0, 0, 0.75);
    --ease: cubic-bezier(0.22, 1, 0.36, 1);

    --tap: 40px;   /* base control size; padding lifts touch targets past 44px */
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
    overflow-x: clip;          /* never break position:sticky (navbar-v2 lesson) */
    overscroll-behavior: none;
}

button { font-family: inherit; }

/* ===================== APP SHELL ===================== */
.app {
    height: calc(100dvh - var(--tt-topnav-h));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===================== TOOLBAR ===================== */
.toolbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
}
.toolbar::-webkit-scrollbar { height: 6px; }
.toolbar::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; }

.tgroup { display: flex; align-items: center; gap: 3px; flex: 0 0 auto; }
.tsep { width: 1px; align-self: stretch; margin: 4px 4px; background: var(--border); flex: 0 0 auto; }
.tspacer { flex: 1 1 auto; min-width: 6px; }

.tbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: var(--tap);
    height: var(--tap);
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text-2);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
    flex: 0 0 auto;
}
.tbtn i { font-size: 1rem; }
.tbtn:hover { background: var(--panel-2); color: var(--text); }
.tbtn:active { transform: translateY(1px); }
.tbtn:disabled { opacity: .35; cursor: default; pointer-events: none; }
.tbtn-label { font-size: 0.86rem; font-weight: 600; }

.tool-btn.is-active {
    background: rgba(99, 102, 241, 0.18);
    color: #c7caff;
    border-color: rgba(99, 102, 241, 0.55);
}
.tbtn.is-on { color: var(--cyan); }

.tmenu { position: relative; flex: 0 0 auto; }
.tmenu-pop {
    position: fixed;            /* fixed + JS-anchored: the toolbar's overflow-x:auto/-y:hidden would clip an absolute dropdown */
    min-width: 210px;
    background: var(--panel-2);
    border: 1px solid var(--border-2);
    border-radius: var(--r-md);
    box-shadow: var(--shadow);
    padding: 6px;
    z-index: calc(var(--tt-z-modal, 1000) + 5);
}
.tmenu-pop[hidden] { display: none; }
.tmenu-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 10px 12px;
    background: transparent; border: 0; border-radius: var(--r-sm);
    color: var(--text); font-size: 0.9rem; text-align: left; cursor: pointer;
}
.tmenu-item i { width: 18px; text-align: center; color: var(--text-3); }
.tmenu-item:hover { background: rgba(99,102,241,0.16); }
.tmenu-item:hover i { color: var(--accent-2); }
.tmenu-div { height: 1px; margin: 5px 4px; background: var(--border); }

/* ===================== WORKSPACE ===================== */
.workspace { flex: 1 1 auto; display: flex; position: relative; overflow: hidden; min-height: 0; }

/* Sidebar (layers + properties) */
.sidebar {
    width: 272px;
    flex: 0 0 auto;
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.side-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; font-weight: 700; font-size: 0.82rem;
    letter-spacing: .04em; text-transform: uppercase; color: var(--text-3);
    border-bottom: 1px solid var(--border);
}
.side-close { display: none; }
.side-scroll { overflow-y: auto; padding: 8px 0 24px; flex: 1 1 auto; min-height: 0; }
.side-sec { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.sec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sec-head h3 { margin: 0; font-size: 0.78rem; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); }

.side-row { display: flex; align-items: center; gap: 8px; margin: 7px 0; }
.side-row label { flex: 0 0 56px; font-size: 0.84rem; color: var(--text-2); }
.unit-suffix { color: var(--text-3); font-size: 0.82rem; }

.ctrl {
    flex: 1 1 auto; min-width: 0;
    height: 34px; padding: 0 10px;
    background: var(--inset); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--r-sm);
    font-size: 0.88rem; font-family: var(--mono);
}
.ctrl:focus { outline: none; border-color: var(--accent); }
select.ctrl { font-family: inherit; cursor: pointer; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border-radius: var(--r-sm);
    background: transparent; border: 1px solid var(--border); color: var(--text-2);
    cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* Layers list */
.layer-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.layer-item {
    display: flex; align-items: center; gap: 7px;
    padding: 6px 7px; border-radius: var(--r-sm);
    background: var(--inset); border: 1px solid transparent; cursor: pointer;
}
.layer-item.is-active { border-color: rgba(99,102,241,0.55); background: rgba(99,102,241,0.12); }
.layer-swatch { width: 15px; height: 15px; border-radius: 4px; flex: 0 0 auto; border: 1px solid rgba(255,255,255,.25); cursor: pointer; }
.layer-name { flex: 1 1 auto; min-width: 0; font-size: 0.86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: transparent; border: 0; color: var(--text); padding: 2px 0; }
.layer-name:focus { outline: none; border-bottom: 1px solid var(--accent); }
.layer-tog { background: transparent; border: 0; color: var(--text-3); cursor: pointer; width: 24px; height: 24px; border-radius: 5px; }
.layer-tog:hover { color: var(--text); background: var(--panel-2); }
.layer-tog.off { color: var(--text-3); opacity: .5; }
.layer-tog.locked { color: var(--amber); }

/* Properties */
.props { display: flex; flex-direction: column; gap: 8px; }
.props-empty { margin: 4px 0; font-size: 0.84rem; color: var(--text-3); line-height: 1.5; }
.prop-row { display: flex; align-items: center; gap: 8px; }
.prop-row label { flex: 0 0 44px; font-size: 0.8rem; color: var(--text-3); font-family: var(--mono); }
.prop-row .ctrl { height: 30px; }
.prop-type { font-size: 0.82rem; color: var(--accent-2); font-weight: 600; text-transform: capitalize; margin-bottom: 2px; }

/* ===================== CANVAS ===================== */
.canvas-wrap { flex: 1 1 auto; position: relative; overflow: hidden; background: var(--paper); min-width: 0; }
#cad { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.canvas-wrap.tool-select #cad { cursor: default; }
.canvas-wrap.panning #cad { cursor: grabbing; }

.hud {
    position: absolute; z-index: 6; pointer-events: none;
    padding: 4px 8px; border-radius: 6px;
    background: rgba(10,10,18,0.92); border: 1px solid var(--border-2);
    color: var(--text); font-family: var(--mono); font-size: 0.76rem; white-space: nowrap;
    box-shadow: 0 6px 18px -8px rgba(0,0,0,.8);
}
.hud[hidden] { display: none; }

.entry {
    position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
    z-index: 7; display: flex; align-items: center; gap: 8px;
    padding: 8px 12px; border-radius: var(--r-md);
    background: var(--panel-2); border: 1px solid var(--accent); box-shadow: var(--shadow);
}
.entry[hidden] { display: none; }
.entry-lbl { font-size: 0.78rem; color: var(--text-2); }
.entry input { width: 92px; height: 30px; padding: 0 8px; background: var(--inset); border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-family: var(--mono); font-size: 0.9rem; }
.entry input:focus { outline: none; border-color: var(--accent); }
.entry-unit { font-size: 0.78rem; color: var(--text-3); }

.zoom-pad { position: absolute; right: 12px; bottom: 12px; z-index: 6; display: flex; flex-direction: column; gap: 6px; }
.zbtn {
    width: 38px; height: 38px; border-radius: 9px;
    background: rgba(20,20,30,0.86); border: 1px solid var(--border-2);
    color: var(--text-2); cursor: pointer; backdrop-filter: blur(6px);
    display: inline-flex; align-items: center; justify-content: center;
}
.zbtn:hover { color: var(--text); border-color: var(--accent); }

/* ===================== STATUS BAR ===================== */
.statusbar {
    flex: 0 0 auto;
    display: flex; align-items: center; gap: 14px;
    padding: 5px 12px; min-height: 30px;
    background: var(--panel); border-top: 1px solid var(--border);
    font-size: 0.76rem; color: var(--text-2); font-family: var(--mono);
    overflow: hidden; white-space: nowrap;
}
.statusbar i { color: var(--text-3); }
.st-item { display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto; }
.st-spacer { flex: 1 1 auto; }
.st-hint { color: var(--text-3); font-family: 'Inter', sans-serif; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1 1 auto; }
.st-snap { color: var(--cyan); }
.st-snap:empty { display: none; }

/* ===================== OVERLAYS ===================== */
.overlay {
    position: fixed; inset: 0;
    z-index: calc(var(--tt-z-modal, 1000) + 10);   /* clear the shared navbar */
    display: flex; align-items: center; justify-content: center;
    padding: 18px;
    background: rgba(5, 5, 9, 0.72); backdrop-filter: blur(4px);
}
.overlay[hidden] { display: none; }
.overlay-card {
    width: min(960px, 100%); max-height: calc(100dvh - 36px);
    background: var(--panel); border: 1px solid var(--border-2);
    border-radius: var(--r-lg); box-shadow: var(--shadow);
    display: flex; flex-direction: column; overflow: hidden;
}
.overlay-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.overlay-head h2 { margin: 0; font-size: 1.05rem; display: flex; align-items: center; gap: 9px; }
.overlay-head h2 i { color: var(--accent-2); }
.overlay-actions { display: flex; gap: 10px; flex-wrap: wrap; padding: 16px 20px 4px; }
.overlay-sec { padding: 14px 20px; overflow-y: auto; }
.overlay-sec h3 { margin: 0 0 12px; font-size: 0.82rem; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); }
.overlay-card > .overlay-sec:last-child { padding-bottom: 22px; }

.btn {
    display: inline-flex; align-items: center; gap: 8px;
    height: 40px; padding: 0 16px; border-radius: var(--r-sm);
    background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text);
    font-size: 0.9rem; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--grad); border: 0; color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--red); border-color: rgba(248,113,113,.4); }

/* Template + project cards */
.template-grid, .project-grid {
    display: grid; gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.tcard, .pcard {
    border: 1px solid var(--border); border-radius: var(--r-md);
    background: var(--inset); overflow: hidden; cursor: pointer; text-align: left;
    display: flex; flex-direction: column; transition: border-color .15s var(--ease), transform .12s var(--ease);
}
.tcard:hover, .pcard:hover { border-color: var(--accent); transform: translateY(-2px); }
.tcard-thumb, .pcard-thumb { height: 92px; background: var(--paper); display: block; width: 100%; }
.tcard-body, .pcard-body { padding: 9px 11px; }
.tcard-name, .pcard-name { font-size: 0.88rem; font-weight: 600; margin: 0 0 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tcard-desc { font-size: 0.74rem; color: var(--text-3); margin: 0; line-height: 1.4; }
.pcard-meta { font-size: 0.72rem; color: var(--text-3); margin: 0; font-family: var(--mono); }
.pcard { position: relative; }
.pcard-kebab {
    position: absolute; top: 6px; right: 6px; z-index: 2;
    width: 28px; height: 28px; border-radius: 6px;
    background: rgba(10,10,18,0.7); border: 1px solid var(--border); color: var(--text-2); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.pcard-kebab:hover { color: var(--text); }
.pcard-menu {
    position: fixed; z-index: calc(var(--tt-z-modal, 1000) + 15);   /* fixed so the overlay's overflow:auto can't clip it */
    background: var(--panel-2); border: 1px solid var(--border-2); border-radius: var(--r-sm);
    box-shadow: var(--shadow); padding: 5px; min-width: 150px;
}
.pcard-menu[hidden] { display: none; }
.pcard-menu button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px; background: transparent; border: 0; border-radius: 5px; color: var(--text); font-size: 0.84rem; text-align: left; cursor: pointer; }
.pcard-menu button i { width: 15px; text-align: center; color: var(--text-3); }
.pcard-menu button:hover { background: rgba(99,102,241,.16); }
.proj-empty { color: var(--text-3); font-size: 0.88rem; line-height: 1.5; }

/* Generic dialog */
.overlay-sm .overlay-card { width: min(420px, 100%); }
.dialog-card { padding: 20px; }
.dialog-card h3 { margin: 0 0 8px; font-size: 1rem; }
.dialog-card p { margin: 0 0 14px; color: var(--text-2); font-size: 0.9rem; line-height: 1.5; }
.dialog-card .ctrl { width: 100%; height: 38px; margin-bottom: 16px; }
.dialog-card .ctrl[hidden] { display: none; }
.dialog-btns { display: flex; justify-content: flex-end; gap: 10px; }

/* Toasts */
.toasts { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: calc(var(--tt-z-modal, 1000) + 20); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
    padding: 10px 16px; border-radius: var(--r-md);
    background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text);
    font-size: 0.86rem; box-shadow: var(--shadow); pointer-events: auto;
    display: flex; align-items: center; gap: 9px; animation: toastIn .25s var(--ease);
}
.toast i { color: var(--accent-2); }
.toast.ok i { color: var(--green); }
.toast.err i { color: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===================== MOBILE ===================== */
@media (max-width: 820px) {
    .sidebar {
        position: absolute; top: 0; bottom: 0; left: 0; z-index: 12;
        width: min(300px, 86vw);
        transform: translateX(-101%);
        transition: transform .22s var(--ease);
        box-shadow: var(--shadow);
    }
    .sidebar.is-open { transform: none; }
    .side-close { display: inline-flex; }
}

@media (max-width: 600px) {
    .tbtn-label { display: none; }       /* icon-only on phones */
    .tbtn-wide { padding: 0 10px; }
    .st-hint { display: none; }           /* status bar gets tight — drop the hint */
    .statusbar { gap: 10px; }
    .overlay { padding: 0; align-items: stretch; }
    .overlay-card { max-height: 100dvh; border-radius: 0; border: 0; width: 100%; }
    .template-grid, .project-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

/* Coarse pointers: lift every tap target comfortably past 44px */
@media (pointer: coarse) {
    :root { --tap: 44px; }
    .icon-btn { width: 40px; height: 40px; }
    .zbtn { width: 44px; height: 44px; }
    .layer-item { padding: 8px 7px; }
    .layer-tog { width: 40px; height: 40px; }
    .layer-swatch { width: 22px; height: 22px; }
    .pcard-kebab { width: 40px; height: 40px; }
    .side-close { width: 40px; height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

/* Dark-theme dropdown fix (fleet sweep 2026-06-30): native <option>s do NOT inherit
   the dark theme — the OS paints the open list white, so without explicit colours the
   options are white-on-white (invisible). Literal hex per .claude/rules/coding-standards.md. */
select option { background-color: #101019; color: #f2f3f8; }
