:root {
    --bg: #eef3f0;
    --panel: #ffffff;
    --ink: #12211d;
    --muted: #5d716b;
    --line: #d7e2dd;
    --brand: #0f766e;
    --brand-dark: #115e59;
    --brand-soft: #ccfbf1;
    --accent: #d97706;
    --ok: #047857;
    --ok-soft: #d1fae5;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --info: #0369a1;
    --info-soft: #e0f2fe;
    --sidebar: #0b1f1c;
    --sidebar-2: #12302b;
    --shadow: 0 14px 40px rgba(15, 40, 34, 0.08);
    --radius: 16px;
}

* { box-sizing: border-box; }
html {
    margin: 0;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
html, body { padding: 0; }
body {
    margin: 0;
    font-family: "Plus Jakarta Sans", "Segoe UI", sans-serif;
    font-size: 16px;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}
body.nav-open { overflow: hidden; }

a { color: var(--brand); text-decoration: none; }
img { max-width: 100%; height: auto; }

.app {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    grid-template-columns: 260px 1fr;
}

.sidebar {
    background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
    color: #e7f4f0;
    padding: 22px 16px max(22px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    z-index: 30;
}
.sidebar-close { display: none; }
.sidebar-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(11, 31, 28, 0.5);
    z-index: 25;
}

.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.brand > div { min-width: 0; }
.brand-center { justify-content: center; margin-bottom: 18px; }
.brand strong {
    display: block;
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.brand small { color: #9cb8b2; }
.brand-mark {
    width: 42px; height: 42px; border-radius: 12px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #14b8a6, #0f766e);
    color: #fff; font-weight: 800; flex-shrink: 0;
}

.sidebar nav { margin: 28px 0; display: grid; gap: 6px; }
.sidebar nav a {
    color: #c9ddd8;
    padding: 12px 12px;
    border-radius: 10px;
    font-weight: 600;
}
.sidebar nav a:hover, .sidebar nav a.active {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.sidebar-user {
    margin-top: auto;
    display: flex;
    gap: 10px;
    align-items: center;
    padding-top: 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    min-width: 0;
}
.sidebar-user > div:nth-child(2) { min-width: 0; flex: 1; }
.sidebar-user strong, .sidebar-user small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: #134e4a; display: grid; place-items: center; font-weight: 700; flex-shrink: 0;
}
.sidebar-user small { color: #9cb8b2; }
.logout { margin-left: auto; color: #fbbf24; font-size: 13px; font-weight: 700; flex-shrink: 0; }

.main { min-width: 0; overflow: visible; }
.btn, .nav-toggle, .bell, .choice, .sidebar nav a { touch-action: manipulation; }
.topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: max(16px, env(safe-area-inset-top)) 28px 8px;
    position: relative;
    z-index: 20;
    overflow: visible;
}
.topbar h1 {
    margin: 0;
    font-size: clamp(18px, 2.4vw, 26px);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.topbar-meta { color: var(--muted); font-weight: 600; white-space: nowrap; flex-shrink: 0; }
.nav-toggle {
    display: none;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 12px;
    width: 44px;
    height: 44px;
    font-size: 20px;
    cursor: pointer;
    flex-shrink: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    margin-left: auto;
}
.btn-scan {
    white-space: nowrap;
    padding: 8px 14px;
    min-height: 44px;
    height: 44px;
}
.scan-short { display: none; }
.notify-wrap { position: relative; flex-shrink: 0; }
.bell {
    position: relative;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 12px;
    width: 44px; height: 44px;
    cursor: pointer; font-size: 18px;
}
.bell-count {
    position: absolute; top: -6px; right: -6px;
    background: var(--danger); color: #fff;
    border-radius: 999px; font-size: 11px; font-weight: 800;
    min-width: 18px; padding: 1px 5px;
}
.notify-drop {
    position: absolute; right: 0; top: 52px; z-index: 40;
    width: min(360px, calc(100vw - 24px));
    max-height: min(70vh, 420px);
    overflow: auto;
    background: #fff; border: 1px solid var(--line);
    border-radius: 14px; box-shadow: var(--shadow);
    padding: 12px; display: grid; gap: 8px;
}
.notify-item { display: grid; gap: 2px; padding: 8px; border-radius: 10px; color: inherit; }
.notify-item.unread { background: var(--brand-soft); }
.notify-item small { color: var(--muted); }
.row-unread td { background: #ecfdf5; }

.client-pick {
    max-height: 220px; overflow: auto;
    border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px;
}
.check-line { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; font-weight: 600; }
.check-line input { width: auto; margin-top: 3px; flex-shrink: 0; }

.scan-video {
    width: 100%;
    max-width: 100%;
    min-height: 220px;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    border-radius: 16px;
    background: #0b1f1c;
    display: block;
    margin-bottom: 10px;
}
.scan-panel { max-width: 560px; }
.work-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.work-card {
    display: grid; gap: 4px;
    border: 1px solid var(--line); border-radius: 14px;
    padding: 14px; background: #f8fbfa; color: inherit;
}
.work-card.active, .work-card:hover { border-color: var(--brand); background: var(--brand-soft); }
.stats-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.content { padding: 8px 28px max(40px, env(safe-area-inset-bottom)); overflow: visible; }
.inspection-detail { border: 2px solid var(--brand); }
.answers-table th { width: 42%; }

.panel, .stat, .auth-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel { padding: 22px; margin-bottom: 18px; }
.panel h2, .panel h3 { margin: 0 0 14px; }

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}
.stat { padding: 18px; min-width: 0; }
.stat span { color: var(--muted); font-size: 13px; font-weight: 700; }
.stat strong { display: block; font-size: clamp(22px, 3vw, 30px); margin-top: 4px; }
.stat em { font-style: normal; color: var(--brand); font-weight: 700; font-size: 13px; }

.toolbar {
    display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
    margin-bottom: 16px;
}
.toolbar .grow { margin-left: auto; }
.toolbar form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; min-width: 0; }
.search {
    min-width: min(240px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
}

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: #f7fbf9; }

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: #eef2f1; color: #4b5c57; }

.btn, button.btn, label.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: 0; border-radius: 12px; padding: 10px 14px;
    background: #e8efec; color: var(--ink); font-weight: 700; cursor: pointer;
    font-family: inherit; font-size: 16px;
    min-height: 44px;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 10px; font-size: 14px; border-radius: 10px; min-height: 36px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; }
.req { color: var(--danger); }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    font: inherit;
    font-size: 16px;
    background: #fff;
    color: var(--ink);
    max-width: 100%;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus {
    outline: 3px solid var(--brand-soft);
    border-color: var(--brand);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.stack > * + * { margin-top: 8px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.alert {
    padding: 12px 14px;
    border-radius: 12px;
    margin-bottom: 14px;
    font-weight: 600;
    overflow-wrap: anywhere;
}
.alert-success { background: var(--ok-soft); color: var(--ok); }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-info { background: var(--info-soft); color: var(--info); }

.choice-row { display: flex; gap: 10px; flex-wrap: wrap; }
.choice {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    border: 1px solid var(--line); border-radius: 12px;
    padding: 12px 14px; min-width: 92px; min-height: 48px; cursor: pointer; font-weight: 700;
    flex: 1 1 120px;
}
.choice:has(input:checked) {
    border-color: var(--brand);
    background: var(--brand-soft);
}
.choice input { width: auto; }

.auth-body {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at 10% 10%, #99f6e4 0, transparent 28%),
        radial-gradient(circle at 90% 80%, #fde68a 0, transparent 26%),
        var(--bg);
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.auth-card { width: min(460px, 100%); padding: 28px; }
.install-card { width: min(720px, 100%); }
.auth-card h1 { margin: 8px 0 6px; }

.type-dot {
    width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px;
}

.form-builder { display: grid; gap: 12px; }
.builder-row {
    border: 1px dashed var(--line);
    border-radius: 14px;
    padding: 14px;
    background: #f8fbfa;
}
.builder-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }

.qr-sheet {
    width: min(420px, 100%);
    margin: 0 auto;
    background: #fff;
    border: 2px solid #111;
    border-radius: 18px;
    padding: 22px;
    text-align: center;
}
.qr-sheet h2 { margin: 8px 0 4px; overflow-wrap: anywhere; }
.qr-target {
    width: min(260px, 70vw);
    height: min(260px, 70vw);
    margin: 16px auto;
}
.qr-target img, .qr-target canvas, .qr-target table {
    width: 100% !important;
    height: 100% !important;
}

.invoice-box { max-width: 860px; margin: 0 auto; }
.invoice-head { display: flex; justify-content: space-between; gap: 20px; }
.totals { width: min(320px, 100%); margin-left: auto; }
.totals div { display: flex; justify-content: space-between; padding: 6px 0; }
.totals .grand { font-size: 20px; font-weight: 800; border-top: 1px solid var(--line); }

.empty {
    text-align: center;
    padding: 40px 16px;
    color: var(--muted);
}

.split {
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    gap: 18px;
}

@media (max-width: 1200px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 980px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(300px, 86vw);
        transform: translateX(-110%);
        transition: transform .2s ease;
        padding-top: max(18px, env(safe-area-inset-top));
    }
    .sidebar.open { transform: none; }
    .sidebar-close {
        display: inline-flex;
        margin: 12px 0 0;
        background: rgba(255,255,255,0.08);
        color: #fff;
        border: 0;
        border-radius: 10px;
        padding: 10px 12px;
        font-weight: 700;
        cursor: pointer;
    }
    .sidebar-scrim.is-on { display: block; }
    .nav-toggle { display: inline-flex; }
    .topbar-meta { display: none; }
    .stats, .stats-3, .grid-2, .grid-3, .split { grid-template-columns: 1fr; }
    .content { padding: 8px 14px max(28px, env(safe-area-inset-bottom)); }
    .topbar { padding-left: 14px; padding-right: 14px; }
    .search, .toolbar, .toolbar form, .toolbar .grow, .toolbar select, .toolbar .btn {
        width: 100%;
    }
    .topbar-actions .btn,
    .topbar-actions .btn-scan {
        width: auto;
    }
    .toolbar .grow { margin-left: 0; }
    .invoice-head, .builder-head { flex-direction: column; align-items: flex-start; }
    .totals { margin-left: 0; width: 100%; }
    .table-scroll { margin: 0 -8px; }
    .table-scroll table { min-width: 620px; }
    .table-scroll table.stack-table,
    .table-scroll table.answers-table { min-width: 0; }
    .hide-when-detail { display: none; }
}

@media (max-width: 700px) {
    table.stack-table thead { display: none; }
    table.stack-table,
    table.stack-table tbody,
    table.stack-table tr,
    table.stack-table td {
        display: block;
        width: 100%;
    }
    table.stack-table tr {
        border: 1px solid var(--line);
        border-radius: 12px;
        margin-bottom: 10px;
        padding: 10px 12px;
        background: #f8fbfa;
    }
    table.stack-table td {
        border: 0;
        padding: 4px 0;
    }
    table.stack-table td[data-label]:not([data-label=""])::before {
        content: attr(data-label);
        display: block;
        color: var(--muted);
        font-size: 11px;
        font-weight: 800;
        text-transform: uppercase;
        letter-spacing: .04em;
        margin-bottom: 2px;
    }
    table.stack-table td:last-child { padding-top: 8px; }
    table.stack-table td .btn { width: 100%; }
}

@media (max-width: 640px) {
    .btn-scan { font-size: 13px; padding: 8px 10px; }
    .scan-full { display: none; }
    .scan-short { display: inline; }
    .stats, .stats-3 { grid-template-columns: 1fr; }
    .panel, .auth-card, .install-card { padding: 16px; }
    .stat { padding: 14px; }
    .work-grid { grid-template-columns: 1fr; }
    .scan-video { aspect-ratio: 4 / 5; min-height: 240px; }
    .notify-wrap { position: static; }
    .notify-drop {
        left: 12px;
        right: 12px;
        width: auto;
        top: calc(100% + 4px);
    }
}

@media (max-width: 400px) {
    .topbar h1 { font-size: 17px; }
    .qr-sheet { padding: 14px; }
}

@media print {
    .sidebar, .sidebar-scrim, .topbar, .toolbar, .no-print, .alert, .nav-toggle { display: none !important; }
    .app { display: block; }
    .content { padding: 0; }
    .panel, .qr-sheet, .invoice-box { box-shadow: none; border-color: #111; }
}
