/* ============================================================
   RepairTool — Design System
   Flat, dark, single-tone. Borders separate, not shadows/glows.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    /* layout */
    --nav-h: 56px;
    --tabbar-h: 60px;
    --timebar-h: 44px;
    --gap: 14px;
    --radius: 8px;
    --radius-sm: 6px;

    /* base — single tone dark, components separated by border only */
    --bg: #0c0d10;
    --surface: #0c0d10;
    --surface-raised: #14161b;
    --surface-sunken: #11131a;
    --border: #232630;
    --border-soft: #1a1c23;

    --text: #e8e9ec;
    --text-muted: #8a8d98;
    --text-dim: #5a5d68;

    /* accent — used only on icons / status / interactive states */
    --accent: #5b8cff;
    --accent-soft: #5b8cff22;

    --c-blue: #5b8cff;
    --c-green: #3ecf8e;
    --c-amber: #e0a93a;
    --c-red: #e0585b;
    --c-purple: #a374e0;
    --c-grey: #6b6e78;

    --mono: 'JetBrains Mono', monospace;
    --sans: 'Inter', system-ui, sans-serif;
}

[data-theme="light"] {
    --bg: #f7f7f8;
    --surface: #f7f7f8;
    --surface-raised: #ffffff;
    --surface-sunken: #ececee;
    --border: #e1e2e6;
    --border-soft: #ececee;
    --text: #15161a;
    --text-muted: #62646d;
    --text-dim: #97989f;
    --accent-soft: #5b8cff18;
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
ul { margin: 0; padding: 0; list-style: none; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

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

/* ── App Shell ───────────────────────────────────────────── */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Main content area ───────────────────────────────────── */
.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.main.main-flush { padding-bottom: 0; }

.topbar {
    height: var(--nav-h);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--gap);
    padding-top: env(safe-area-inset-top);
    height: calc(var(--nav-h) + env(safe-area-inset-top));
    gap: var(--gap);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 30;
}
.topbar-brand-text { font-weight: 600; font-size: 14.5px; white-space: nowrap; }
.logo-mark {
    width: 28px; height: 28px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    color: var(--accent);
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}
.logo-mark-img {
    object-fit: contain;
    border-color: var(--border); /* a real logo doesn't need the accent-colored placeholder border */
    padding: 2px;
}

/* ── Bottom Tab Bar (everywhere — desktop + mobile) ─────── */
.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: var(--tabbar-h);
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    z-index: 100;
    touch-action: none;
}
.tabbar-swipe-handle {
    position: absolute;
    top: 7px; left: 50%;
    transform: translateX(-50%);
    width: 40px; height: 4px;
    border-radius: 999px;
    background: var(--border);
    pointer-events: none;
}
.tab-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 100%;
    min-width: 44px;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}
.tab-link i { font-size: 22px; }
.tab-link span { font-size: 10.5px; font-weight: 500; }
.tab-link.active { color: var(--accent); }
.tab-link:hover { color: var(--text); }
.tab-link.active:hover { color: var(--accent); }
.tab-link:active { opacity: .6; }

/* the centered scan+add pill */
.tab-pill-slot {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    height: 100%;
}
.tab-pill {
    display: flex;
    align-items: center;
    height: 52px;
    margin-top: -22px;
    border-radius: 999px;
    background: var(--accent);
    border: 4px solid var(--bg);
    overflow: hidden;
}
.tab-pill-half {
    width: 52px; height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #0c0d10;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}
.tab-pill-half:active { opacity: .7; }
.tab-pill-half:hover { opacity: .85; }
.tab-pill-half.active { background: var(--c-green); }

@media (min-width: 640px) {
    .tabbar { max-width: 480px; left: 50%; transform: translateX(-50%); border-left: 1px solid var(--border); border-right: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; bottom: 0; }
}

/* ── "Mehr" sheet ────────────────────────────────────────── */
.sheet-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 199;
}
.sheet-overlay.open { display: block; }
.sheet {
    display: none;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    max-height: 75vh;
    max-height: 75dvh; /* dvh accounts for the on-screen keyboard shrinking the viewport; vh is the fallback for older browsers */
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    z-index: 200;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    overflow-y: auto;
}
.sheet.open { display: block; }
@media (min-width: 640px) {
    .sheet { max-width: 480px; left: 50%; transform: translateX(-50%); }
}
.sheet-handle {
    width: 36px; height: 4px;
    background: var(--border);
    border-radius: 999px;
    margin: 10px auto 4px;
}
.sheet-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 16px 14px;
}
.sheet-head strong { font-size: 15px; }
.sheet-body { padding: 0 16px 8px; }
.sheet-group-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-dim);
    padding: 14px 2px 8px;
}
.sheet-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}
.sheet-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 4px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-align: center;
}
.sheet-item:hover { background: var(--border-soft); color: var(--text); }
.sheet-item.active { color: var(--accent); }
.sheet-item i { font-size: 22px; }
.sheet-item span { font-size: 11.5px; font-weight: 500; }

.sheet-account-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 2px 4px;
}
.sheet-account-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 15px;
    flex-shrink: 0;
}

.timer-sheet-active {
    text-align: center;
    padding: 8px 4px;
}
.timer-sheet-clock {
    font-family: var(--mono);
    font-size: 32px;
    font-weight: 600;
    color: var(--c-amber);
    letter-spacing: .02em;
}
.topbar-search {
    flex: 1;
    max-width: 420px;
    display: flex;
    align-items: center;
    gap: 8px;
    height: 42px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
}
.topbar-search input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-size: 16px;
    outline: none;
    min-height: 0;
    padding: 0;
}
@media (max-width: 480px) {
    .topbar-brand-text { display: none; }
    .topbar-search { max-width: none; }
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
    width: 40px; height: 40px;
    border: 1px solid var(--border);
    background: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    font-size: 17px;
    flex-shrink: 0;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-btn.primary { color: var(--accent); border-color: var(--accent); }

.theme-icon-light { display: none; }
[data-theme="light"] .theme-icon-dark { display: none; }
[data-theme="light"] .theme-icon-light { display: inline; }

.page-body {
    padding: var(--gap);
    flex: 1;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--gap);
    flex-wrap: wrap;
    gap: 10px;
}
.page-title { font-size: 19px; font-weight: 600; margin: 0; }
.page-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ── Pull-to-search indicator (drag down at the top of the page) ───── */
.pull-search-indicator {
    height: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 12.5px;
    font-weight: 500;
    background: var(--border-soft);
    transition: height .15s ease;
}
.pull-search-indicator.ready { color: var(--accent); }
.pull-search-indicator i { font-size: 15px; }

/* ── Time Bar (task timer strip) ─────────────────────────── */
.timebar {
    height: var(--timebar-h);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 var(--gap);
    background: var(--surface-sunken);
    font-family: var(--mono);
    font-size: 13px;
}
.timebar .tb-label { color: var(--text-muted); }
.timebar .tb-task { color: var(--text); font-weight: 600; }
.timebar .tb-clock {
    margin-left: auto;
    color: var(--c-amber);
    font-weight: 600;
    letter-spacing: .02em;
}
.timebar .tb-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--c-amber);
    box-shadow: none;
    flex-shrink: 0;
}
.timebar.running .tb-dot { background: var(--c-green); }
.timebar.paused .tb-dot { background: var(--c-amber); animation: none; }
.timebar.paused .tb-clock { color: var(--text-dim); }
.timebar button.tb-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    height: 26px;
    padding: 0 10px;
    cursor: pointer;
    font-family: var(--sans);
    font-size: 12px;
}
.timebar button.tb-btn:hover { color: var(--text); border-color: var(--accent); }

/* ── Todos: fullscreen step-by-step focus mode ──────────── */
.focus-mode {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 800;
    background: var(--bg);
    flex-direction: column;
}
.focus-mode.open { display: flex; }

.focus-mode-top {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
}
.focus-mode-progress {
    flex: 1;
    height: 6px;
    border-radius: 999px;
    background: var(--border-soft);
    overflow: hidden;
}
.focus-mode-progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 999px;
    transition: width .25s ease;
    width: 0%;
}
.focus-mode-counter {
    font-family: var(--mono);
    font-size: 12.5px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.focus-mode-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.focus-mode-card {
    width: 100%;
    max-width: 480px;
    text-align: center;
    transition: transform .2s ease, opacity .2s ease;
}
.focus-mode-ticket {
    display: inline-block;
    font-family: var(--mono);
    font-size: 12.5px;
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px 12px;
    margin-bottom: 18px;
}
.focus-mode-title {
    font-size: 24px;
    font-weight: 600;
    line-height: 1.4;
}

.focus-mode-actions {
    display: flex;
    gap: 10px;
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.focus-skip-btn { flex: 1; justify-content: center; height: 50px; }
.focus-done-btn { flex: 2; justify-content: center; height: 50px; font-size: 15px; }

/* ── Scanner: full-bleed camera stage ───────────────────── */
.scanner-stage {
    position: relative;
    flex: 1;
    background: #000;
    overflow: hidden;
}
.scanner-stage video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}
.scanner-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-align: center;
    padding: 24px;
}
.scanner-placeholder i { font-size: 38px; margin-bottom: 12px; color: var(--text-dim); }
.scanner-placeholder div { font-size: 13.5px; line-height: 1.5; }

.scanner-reticle {
    position: absolute;
    inset: 16% 12%;
    max-height: 320px;
    border: 2px solid var(--accent);
    border-radius: 14px;
    display: none;
    pointer-events: none;
}

.scanner-overlay-top {
    position: absolute;
    top: calc(12px + env(safe-area-inset-top));
    left: 12px; right: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 10;
}
.scanner-overlay-btn {
    background: rgba(12,13,16,.55);
    border-color: rgba(255,255,255,.2);
    color: #fff;
    backdrop-filter: blur(6px);
}
.scanner-overlay-btn:hover { border-color: #fff; color: #fff; }

.scanner-manual {
    position: absolute;
    top: calc(60px + env(safe-area-inset-top));
    left: 12px; right: 12px;
    z-index: 10;
    display: none;
}
.scanner-manual.open { display: block; }
.scanner-manual input {
    background: rgba(12,13,16,.75);
    backdrop-filter: blur(6px);
    border-color: rgba(255,255,255,.2);
    color: #fff;
}

.scanner-history-handle {
    position: absolute;
    left: 0; right: 0;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    z-index: 10;
    background: rgba(12,13,16,.7);
    backdrop-filter: blur(6px);
    border: none;
    border-top: 1px solid rgba(255,255,255,.12);
    color: #fff;
    padding: 10px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
}
.scanner-history-bar {
    width: 36px; height: 4px;
    border-radius: 999px;
    background: rgba(255,255,255,.35);
}
.scanner-history-sheet {
    position: absolute;
    left: 0; right: 0;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    max-height: 55%;
    background: var(--surface-raised);
    border-top: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform .2s ease;
    z-index: 9;
}
.scanner-history-sheet.open { transform: translateY(0); }
.scanner-history-handle.open { display: none; }

/* ── Cards / Tables / generic components ─────────────────── */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.card-pad { padding: 16px; }

.grid {
    display: grid;
    gap: var(--gap);
}
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1024px) {
    /* tablet: keep 2 columns where it still makes sense, instead of collapsing straight to 1 */
    .grid-cols-3, .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .grid-cols-2, .grid-cols-3, .grid-cols-4 { grid-template-columns: 1fr; }
}

.stat-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}
.stat-card .stat-label { color: var(--text-muted); font-size: 12px; }
.stat-card .stat-value { font-size: 22px; font-weight: 600; margin-top: 4px; font-family: var(--mono); }
.stat-card .stat-icon { color: var(--accent); font-size: 18px; margin-bottom: 8px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
    text-align: left;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}
tbody td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border-soft);
}
tbody tr:hover { background: var(--border-soft); }
tbody tr { cursor: pointer; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 40px;
    padding: 0 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: none;
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0c0d10; }
.btn-primary:hover { opacity: .9; color: #0c0d10; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-danger:hover { border-color: var(--c-red); color: var(--c-red); }

input, select, textarea {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 12px 14px;
    font-size: 16px; /* 16px+ prevents iOS Safari from auto-zooming the page on focus */
    font-family: inherit;
    width: 100%;
    min-height: 46px;
}
textarea { min-height: 0; } /* let rows= control textarea height instead of the input min-height */
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { font-size: 13px; color: var(--text-muted); display: block; margin-bottom: 6px; }
.field { margin-bottom: 16px; }

.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--text-muted);
}
.empty-state i { font-size: 30px; color: var(--text-dim); margin-bottom: 10px; display: block; }

/* low stock highlight */
.qty-low { color: var(--c-red); font-weight: 600; }

/* modal */
.modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 600;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    max-height: 90dvh; /* dvh accounts for the on-screen keyboard shrinking the viewport; vh is the fallback for older browsers */
    overflow-y: auto;
    margin: auto; /* keeps the modal scrollable into view when the keyboard shrinks available height */
}
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-body { padding: 16px; }
.modal-foot {
    display: flex; justify-content: flex-end; gap: 8px;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
}

/* toast */
#toast-stack {
    position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); right: 16px;
    display: flex; flex-direction: column; gap: 8px;
    z-index: 700;
}
.toast {
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 13px;
    min-width: 220px;
}
.toast.error { border-left-color: var(--c-red); }
.toast.success { border-left-color: var(--c-green); }
