:root {
    color-scheme: light;
    --bg: #f7f7f2;
    --surface: #ffffff;
    --text: #17201d;
    --muted: #68736f;
    --primary: #0f766e;
    --primary-strong: #115e59;
    --line: #dce3df;
    --shadow: 0 18px 45px rgba(20, 31, 28, .12);
}

.dark {
    color-scheme: dark;
    --bg: #101413;
    --surface: #1a211f;
    --text: #eef5f2;
    --muted: #a9b7b2;
    --primary: #2dd4bf;
    --primary-strong: #5eead4;
    --line: #2d3a36;
    --shadow: 0 18px 45px rgba(0, 0, 0, .36);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
.app-shell {
    width: min(100%, 760px);
    margin: 0 auto;
    padding: 18px 16px 96px;
}
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    line-height: 1;
}
.icon-form {
    display: contents;
    margin: 0;
}
.brand {
    margin: 0 0 3px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: 30px; line-height: 1.08; }
h2 { margin: 0 0 6px; font-size: 24px; }
h3 { margin: 0 0 10px; font-size: 17px; }
.pill, .icon-btn {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--muted);
    border-radius: 999px;
    padding: 8px 12px;
    box-shadow: none;
}
.icon-btn {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    padding: 0;
    color: var(--text);
    display: inline-grid;
    place-items: center;
    line-height: 1;
    font-size: 20px;
    cursor: pointer;
}
.network-icon {
    color: #15803d;
    font-size: 18px;
}
.network-icon.offline {
    color: #b91c1c;
}
.hero-copy { margin: 18px 0; }
.hero-copy p { margin: 0; color: var(--muted); }
.text-search-box { margin: 0 0 16px; }
.camera-card {
    position: relative;
    min-height: 310px;
    border: 2px dashed color-mix(in srgb, var(--primary) 55%, var(--line));
    border-radius: 28px;
    background: var(--surface);
    display: grid;
    place-items: center;
    overflow: hidden;
    box-shadow: var(--shadow);
}
.camera-card input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.camera-card label {
    display: grid;
    gap: 8px;
    place-items: center;
    text-align: center;
    padding: 28px;
}
.camera-icon {
    width: 96px;
    height: 96px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--primary);
    color: #ffffff;
    font-size: 56px;
}
.camera-card small { color: var(--muted); }
.preview {
    display: none;
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    inset: 0;
}
.loading {
    position: absolute;
    inset: auto 18px 18px;
    padding: 14px 16px;
    border-radius: 18px;
    background: rgba(15, 118, 110, .95);
    color: #fff;
    text-align: center;
    font-weight: 800;
}
.panel, .product-card, .quote-card, .empty-state {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 16px;
    box-shadow: var(--shadow);
}
.recovery-panel {
    display: grid;
    gap: 14px;
    margin-top: 18px;
}
.recovery-panel p {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}
.auth-panel { margin-top: 34px; }
.form-stack { display: grid; gap: 14px; }
label { display: grid; gap: 7px; color: var(--muted); font-weight: 700; }
input, textarea, select {
    width: 100%;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 94%, var(--bg));
    color: var(--text);
    border-radius: 16px;
    padding: 13px 14px;
    outline: none;
}
textarea { min-height: 96px; resize: vertical; }
.share-text {
    min-height: 156px;
    white-space: pre-wrap;
}
.check-row { grid-template-columns: 22px 1fr; align-items: center; }
.primary-btn, .secondary-btn {
    display: inline-flex;
    min-height: 46px;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 16px;
    padding: 12px 16px;
    font-weight: 800;
}
.primary-btn { background: var(--primary); color: #fff; }
.secondary-btn { background: color-mix(in srgb, var(--primary) 12%, var(--surface)); color: var(--primary-strong); }
.small { min-height: 38px; border-radius: 13px; padding: 8px 12px; }
.full { width: 100%; margin-top: 14px; }
.alert, .error {
    border-radius: 16px;
    padding: 12px 14px;
    margin: 12px 0;
}
.alert { background: color-mix(in srgb, var(--primary) 16%, var(--surface)); }
.error { background: #fee2e2; color: #991b1b; }
.results-grid, .section-block, .list { display: grid; gap: 14px; }
.section-note {
    margin: -4px 0 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}
.metric-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}
.metric-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric-card {
    display: grid;
    gap: 6px;
    min-height: 108px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--surface);
    box-shadow: var(--shadow);
}
.metric-card span, .metric-card small { color: var(--muted); font-weight: 700; }
.metric-card strong { font-size: 24px; line-height: 1.1; }
.metric-link.active {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 10%, var(--surface));
}
.pager {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    color: var(--muted);
    font-weight: 800;
}
.pager a:last-child { justify-self: end; }
.action-panel { margin-bottom: 14px; }
.back-btn {
    margin: 0 0 12px;
    min-height: 40px;
    padding-inline: 14px;
}
.report-filter {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 14px;
}
.report-filter.ledger-filter {
    grid-template-columns: repeat(2, minmax(0, 1fr)) auto auto auto;
}
.compact-list { margin-top: 12px; }
.task-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}
.task-card {
    display: grid;
    gap: 6px;
    min-height: 126px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}
.task-card span, .task-card small { color: var(--muted); font-weight: 800; }
.task-card strong { font-size: 28px; line-height: 1; }
.task-card.danger { border-color: #fecaca; }
.task-card.danger strong { color: #b91c1c; }
.task-card.warn { border-color: #fde68a; }
.task-card.warn strong { color: #a16207; }
.task-card.ok strong { color: #15803d; }
.stock-compare {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.stock-compare > div {
    display: grid;
    gap: 7px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: color-mix(in srgb, var(--surface) 94%, var(--bg));
}
.stock-compare span {
    color: var(--muted);
    font-weight: 800;
    font-size: 13px;
}
.stock-compare strong {
    font-size: 24px;
    line-height: 1.1;
}
.product-card {
    display: grid;
    grid-template-columns: 116px 1fr;
    gap: 14px;
    padding: 12px;
}
.product-media {
    position: relative;
    aspect-ratio: 1;
    border-radius: 18px;
    overflow: hidden;
    background: color-mix(in srgb, var(--primary) 10%, var(--surface));
}
.product-media img { width: 100%; height: 100%; object-fit: cover; }
.image-placeholder { height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 42px; }
.score {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 5px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .68);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
}
.product-info h3 { margin-bottom: 4px; }
.product-info p { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.meta-row { display: grid; gap: 3px; color: var(--muted); font-size: 13px; }
.meta-row strong { color: var(--text); font-size: 16px; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.list-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 16px;
    border-radius: 18px;
    background: var(--surface);
    border: 1px solid var(--line);
}
.ledger-list {
    display: grid;
    gap: 10px;
}
.ledger-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
}
.ledger-row small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}
.ledger-row strong {
    white-space: nowrap;
}
.legal-ledger-paper {
    display: grid;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
}
.legal-ledger-head {
    display: grid;
    gap: 4px;
}
.legal-ledger-head p {
    margin: 0;
    color: var(--muted);
    font-weight: 700;
}
.legal-ledger-head h2 {
    margin: 8px 0 2px;
    text-align: center;
    text-transform: uppercase;
    font-size: 18px;
}
.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
}
.legal-table {
    width: 100%;
    min-width: 640px;
    border-collapse: collapse;
    background: var(--surface);
}
.legal-table th,
.legal-table td {
    border: 1px solid var(--line);
    padding: 10px;
    text-align: left;
    vertical-align: top;
}
.legal-table th {
    background: color-mix(in srgb, var(--primary) 10%, var(--surface));
    color: var(--text);
    font-weight: 800;
}
.legal-table .table-code th {
    text-align: center;
    color: var(--muted);
    background: color-mix(in srgb, var(--surface) 94%, var(--bg));
}
.legal-table .number {
    text-align: right;
    white-space: nowrap;
    font-weight: 800;
}
.legal-table .group-row td,
.legal-table .total-row td {
    font-weight: 800;
    background: color-mix(in srgb, var(--surface) 92%, var(--bg));
}
.list-row small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}
.sale-row-actions {
    display: grid;
    justify-items: end;
    gap: 4px;
    min-width: 112px;
}
.cart-list {
    display: grid;
    gap: 12px;
}
.cart-row {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(90px, .55fr) minmax(110px, .75fr) auto auto;
    gap: 10px;
    align-items: end;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: color-mix(in srgb, var(--surface) 94%, var(--bg));
}
.cart-row small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-weight: 700;
}
.cart-row > strong {
    white-space: nowrap;
    padding-bottom: 13px;
}
.danger-link {
    color: #b91c1c;
    padding-bottom: 14px;
    cursor: pointer;
}
.sync-status {
    display: inline-block;
    margin-top: 0;
    padding: 3px 8px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--primary) 12%, var(--surface));
    color: var(--primary-strong);
}
.sync-status.sync_failed { background: #fee2e2; color: #991b1b; }
.sync-status.synced { background: #dcfce7; color: #166534; }
.link-btn {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--primary-strong);
    font-weight: 800;
    padding: 0;
}
.quote-card { display: grid; gap: 16px; }
.qr-wrap { display: grid; place-items: center; }
.qr-wrap img { width: 180px; height: 180px; border-radius: 16px; }
.split-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.empty-state { display: grid; gap: 12px; text-align: center; margin-top: 20px; }
.bottom-nav {
    position: fixed;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    width: min(calc(100% - 24px), 720px);
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 6px;
    padding: 8px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    border: 1px solid var(--line);
    border-radius: 22px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}
.bottom-nav a {
    display: grid;
    place-items: center;
    gap: 2px;
    min-height: 52px;
    border-radius: 16px;
    color: var(--muted);
    font-weight: 800;
}
.bottom-nav a span { font-size: 11px; }
.bottom-nav a { text-align: center; }
.bottom-nav a.active { background: var(--primary); color: #fff; }
.hidden { display: none !important; }

@media (max-width: 420px) {
    .app-shell { padding-inline: 12px; }
    h1 { font-size: 27px; }
    .product-card { grid-template-columns: 96px 1fr; }
    .split-actions { grid-template-columns: 1fr; }
    .report-filter, .report-filter.ledger-filter { grid-template-columns: 1fr; }
    .task-grid { grid-template-columns: 1fr; }
    .stock-compare { grid-template-columns: 1fr; }
    .ledger-row { grid-template-columns: 1fr; }
    .cart-row { grid-template-columns: 1fr; }
    .cart-row > strong, .danger-link { padding-bottom: 0; }
    .metric-grid, .metric-grid.three { grid-template-columns: 1fr; }
}
