:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --bg-gradient: radial-gradient(circle at 15% 10%, #dbeafe, transparent 45%),
                   radial-gradient(circle at 85% 5%, #c7d2fe, transparent 40%),
                   linear-gradient(180deg, #f8fafc, #eef2ff);
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --stroke: #e2e8f0;
    --stroke-strong: #cbd5e1;
    --primary: #2563eb;
    --primary-strong: #1d4ed8;
    --primary-soft: #eef2ff;
    --success: #16a34a;
    --danger: #dc2626;
    --warn: #f59e0b;
    --text: #0f172a;
    --muted: #64748b;
    --header-bg: rgba(255,255,255,0.85);
    --tabs-bg: rgba(245,247,251,0.92);
    --icon-border: #dfe3ff;
    --icon-hover: #e0e7ff;
    --success-bg: #ecfdf5;
    --success-border: #bbf7d0;
    --success-text: #065f46;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --danger-text: #991b1b;
    --ghost-border: #dfe3ff;
    --ghost-hover: #e0e7ff;
    --line-bg: #fbfdff;
    --line-expanded-bg: linear-gradient(180deg, #ffffff, #f8fbff);
    --line-expanded-border: #bfdbfe;
    --chip-soft: #eff6ff;
    --pill-bg: #e0f2fe;
    --pill-text: #075985;
    --pill-gray-bg: #f1f5f9;
    --pill-gray-text: #475569;
    --item-bg: #ffffff;
    --input-focus-bg: #ffffff;
    --mobile-footer-bg: rgba(255, 255, 255, 0.92);
    --mobile-footer-border: rgba(226, 232, 240, 0.9);
    --modal-bg: #ffffff;
    --toast-bg: #0f172a;
    --calc-key-bg: #f1f5f9;
    --calc-key-hover: #e2e8f0;
    --calc-warn-bg: #fef3c7;
    --calc-warn-border: #fde68a;
    --calc-warn-text: #92400e;
    --shadow-sm: 0 4px 12px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 12px 28px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 20px 45px rgba(15, 23, 42, 0.12);
    --radius: 14px;
    --radius-sm: 10px;
    --radius-lg: 20px;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b1220;
    --bg-gradient: radial-gradient(circle at 15% 10%, rgba(37, 99, 235, 0.24), transparent 38%),
                   radial-gradient(circle at 85% 5%, rgba(56, 189, 248, 0.16), transparent 30%),
                   linear-gradient(180deg, #0b1220, #111827);
    --panel: #111827;
    --panel-soft: #0f172a;
    --stroke: #243244;
    --stroke-strong: #334155;
    --primary: #60a5fa;
    --primary-strong: #3b82f6;
    --primary-soft: rgba(59, 130, 246, 0.16);
    --success: #22c55e;
    --danger: #f87171;
    --warn: #fbbf24;
    --text: #e5eefc;
    --muted: #94a3b8;
    --header-bg: rgba(11, 18, 32, 0.84);
    --tabs-bg: rgba(11, 18, 32, 0.9);
    --icon-border: #304256;
    --icon-hover: rgba(59, 130, 246, 0.22);
    --success-bg: rgba(34, 197, 94, 0.14);
    --success-border: rgba(34, 197, 94, 0.26);
    --success-text: #86efac;
    --danger-bg: rgba(248, 113, 113, 0.14);
    --danger-border: rgba(248, 113, 113, 0.3);
    --danger-text: #fca5a5;
    --ghost-border: #304256;
    --ghost-hover: rgba(59, 130, 246, 0.22);
    --line-bg: #101c2f;
    --line-expanded-bg: linear-gradient(180deg, rgba(17, 24, 39, 0.98), rgba(13, 22, 37, 0.98));
    --line-expanded-border: #3b82f6;
    --chip-soft: rgba(59, 130, 246, 0.18);
    --pill-bg: rgba(56, 189, 248, 0.16);
    --pill-text: #7dd3fc;
    --pill-gray-bg: #1e293b;
    --pill-gray-text: #cbd5e1;
    --item-bg: #0f172a;
    --input-focus-bg: #111827;
    --mobile-footer-bg: rgba(17, 24, 39, 0.92);
    --mobile-footer-border: rgba(51, 65, 85, 0.8);
    --modal-bg: #111827;
    --toast-bg: #020617;
    --calc-key-bg: #172233;
    --calc-key-hover: #223044;
    --calc-warn-bg: rgba(251, 191, 36, 0.14);
    --calc-warn-border: rgba(251, 191, 36, 0.28);
    --calc-warn-text: #fcd34d;
    --shadow-sm: 0 12px 24px rgba(2, 6, 23, 0.28);
    --shadow-md: 0 18px 34px rgba(2, 6, 23, 0.34);
    --shadow-lg: 0 24px 48px rgba(2, 6, 23, 0.44);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: "Segoe UI", "Inter", system-ui, -apple-system, Roboto, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    background-image: var(--bg-gradient);
    background-attachment: fixed;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

body.quote-active .mobile-footer-actions {
    display: grid;
}

h1, h2, h3 {
    margin: 0 0 8px;
    letter-spacing: -0.01em;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* HEADER */
.app-header {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    padding-top: calc(14px + env(safe-area-inset-top, 0));
    background: var(--header-bg);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--stroke);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    color: #fff;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(37,99,235,0.35);
    font-size: 20px;
}

.brand-title {
    font-weight: 700;
    font-size: 16px;
    line-height: 1.1;
}

.brand-sub {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.2;
    max-width: 60vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-btn {
    background: var(--primary-soft);
    border: 1px solid var(--icon-border);
    color: var(--primary-strong);
    border-radius: 10px;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform .08s ease, background .12s ease;
}
.icon-btn:hover { background: var(--icon-hover); }
.icon-btn:active { transform: translateY(1px); }

.theme-btn {
    position: relative;
}

.theme-icon {
    position: absolute;
    inset: 0;
    margin: auto;
    display: none;
}

.theme-icon-moon {
    display: block;
}

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

:root[data-theme="dark"] .theme-icon-sun {
    display: block;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.auth-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    color: var(--success-text);
    padding: 6px 10px 6px 8px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    max-width: 220px;
}
.auth-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #16a34a;
    flex: 0 0 auto;
    box-shadow: 0 0 0 3px rgba(22,163,74,0.15);
}
.auth-who {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 140px;
}
.auth-out {
    background: transparent;
    border: none;
    color: var(--success-text);
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 6px;
}
.auth-out:hover { background: var(--success-bg); }

.auth-card { max-width: 400px; }
.auth-error {
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--danger-text);
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 13px;
}
.auth-toggle { text-align: center; margin-top: 2px; }
.auth-toggle a { color: var(--primary-strong); font-weight: 600; text-decoration: none; }
.auth-toggle a:hover { text-decoration: underline; }

.server-state {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--panel-soft);
    border: 1px dashed var(--stroke-strong);
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
}
.server-state.ok { color: #065f46; background: #ecfdf5; border: 1px solid #bbf7d0; border-style: solid; }
.server-state.bad { color: #991b1b; background: #fef2f2; border: 1px solid #fecaca; border-style: solid; }

/* TABS */
.tabs {
    display: flex;
    gap: 6px;
    padding: 10px 12px 0;
    overflow-x: auto;
    scrollbar-width: none;
    position: sticky;
    top: 68px;
    z-index: 40;
    background: var(--tabs-bg);
    backdrop-filter: blur(8px);
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
    flex: 0 0 auto;
    background: transparent;
    border: 1px solid transparent;
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    transition: all .15s ease;
}
.tab:hover { color: var(--text); }
.tab.active {
    background: var(--item-bg);
    color: var(--primary-strong);
    border-color: var(--stroke);
    box-shadow: var(--shadow-sm);
}

/* CONTAINER */
.container {
    max-width: 920px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: 40px;
    display: grid;
    gap: 14px;
}

.tab-panel { display: none; gap: 14px; }
.tab-panel.active { display: grid; }

/* CARDS */
.card {
    background: var(--panel);
    border: 1px solid var(--stroke);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 10px;
}

.card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    gap: 8px;
    flex-wrap: wrap;
}

.stack { display: grid; gap: 12px; }

/* ROWS */
.row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 10px;
    margin-bottom: 10px;
}
.row:last-child { margin-bottom: 0; }

.row-inner {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* INPUTS */
label.helper {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
    font-weight: 500;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="file"],
select,
textarea {
    width: 100%;
    border: 1px solid var(--stroke);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    background: var(--panel-soft);
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
    background: var(--input-focus-bg);
}

input[type="file"] { padding: 8px; background: var(--item-bg); }

/* BUTTONS */
.btn {
    border: none;
    border-radius: var(--radius-sm);
    padding: 11px 16px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: transform .08s ease, box-shadow .12s ease, background .12s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.btn.primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    color: #fff;
    box-shadow: 0 10px 22px rgba(37,99,235,0.30);
}
.btn.primary:hover { box-shadow: 0 14px 26px rgba(37,99,235,0.40); }
.btn.ghost {
    background: var(--primary-soft);
    color: var(--primary-strong);
    border: 1px solid var(--ghost-border);
}
.btn.ghost:hover { background: var(--ghost-hover); }
.btn.danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid var(--danger-border);
}
.btn.danger:hover { background: var(--danger-bg); }
.btn.small { padding: 7px 10px; font-size: 13px; }
.btn:active { transform: translateY(1px); }

.actions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
    justify-content: flex-end;
}

/* ADD INLINE */
.add-inline {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: end;
}

/* LINES (QUOTE) */
.lines {
    display: grid;
    gap: 10px;
    margin-top: 10px;
}

.line {
    border: 1px solid var(--stroke);
    border-radius: 16px;
    padding: 12px;
    background: var(--line-bg);
    display: grid;
    gap: 10px;
    box-shadow: var(--shadow-sm);
}

.line.expanded {
    border-color: var(--line-expanded-border);
    background: var(--line-expanded-bg);
}

.line-top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: start;
}

.line-toggle {
    width: 100%;
    border: none;
    background: transparent;
    padding: 0;
    text-align: left;
    cursor: pointer;
    display: grid;
    gap: 10px;
}

.line-summary-main {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: start;
}

.line-summary-text {
    min-width: 0;
    display: grid;
    gap: 4px;
}

.line-title {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.line-summary-meta {
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
}

.line-summary-side {
    justify-self: end;
    text-align: right;
    display: grid;
    gap: 1px;
}

.line-price-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.line-price {
    font-size: 18px;
    font-weight: 800;
    color: var(--primary-strong);
    line-height: 1.1;
}

.line-summary-subtotal {
    font-size: 12px;
    color: var(--muted);
}

.line-toggle-state {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.line-toggle-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 999px;
    background: var(--chip-soft);
    color: var(--primary-strong);
    font-size: 12px;
    font-weight: 700;
}

.line-toggle-arrow {
    color: var(--muted);
    font-size: 16px;
    transition: transform .16s ease;
}

.line.expanded .line-toggle-arrow {
    transform: rotate(180deg);
}

.line-name-input {
    font-weight: 600;
    font-size: 15px;
    width: 100%;
    background: transparent;
    border: 1px dashed transparent;
    padding: 6px 8px;
    border-radius: 8px;
}
.line-name-input:hover { border-color: var(--stroke); background: var(--item-bg); }
.line-name-input:focus { border-color: var(--primary); background: var(--item-bg); border-style: solid; }

.line-actions {
    display: flex;
    gap: 4px;
}

.line-editor {
    display: grid;
    gap: 10px;
    padding-top: 2px;
}

.line-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    align-items: end;
}

.line-field-span {
    grid-column: 1 / -1;
}

.line-subtotal {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 6px;
    border-top: 1px dashed var(--stroke);
    margin-top: 4px;
    font-weight: 700;
    color: var(--primary-strong);
    font-size: 15px;
}

.pill {
    background: var(--pill-bg);
    color: var(--pill-text);
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.pill.green { background: #dcfce7; color: #166534; }
.pill.gray { background: var(--pill-gray-bg); color: var(--pill-gray-text); }

.empty {
    padding: 18px;
    text-align: center;
    color: var(--muted);
    border: 1px dashed var(--stroke-strong);
    border-radius: 12px;
    background: var(--panel-soft);
    font-size: 14px;
}

/* TOTALS */
.totals-card {
    display: grid;
    gap: 12px;
}

.totals-grid {
    display: grid;
    gap: 6px;
}

.t-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 15px;
    color: var(--muted);
    padding: 4px 0;
}

.t-line.total {
    border-top: 2px solid var(--stroke);
    padding-top: 10px;
    margin-top: 4px;
    font-size: 22px;
    font-weight: 800;
    color: var(--primary-strong);
}

.is-hidden {
    display: none !important;
}

.toggle-card {
    background: linear-gradient(180deg, var(--item-bg), var(--panel-soft));
    border: 1px solid var(--stroke);
    border-radius: 14px;
    padding: 12px 14px;
}

.switch-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
}

.switch-label {
    display: block;
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.switch-help {
    display: block;
    margin-top: 2px;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.35;
}

.switch-control {
    position: relative;
    flex: 0 0 auto;
}

.switch-control input {
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
}

.switch-ui {
    display: inline-flex;
    width: 54px;
    height: 32px;
    border-radius: 999px;
    background: #cbd5e1;
    position: relative;
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
    transition: background .16s ease;
}

.switch-ui::after {
    content: "";
    position: absolute;
    top: 4px;
    left: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.18);
    transition: transform .16s ease;
}

.switch-control input:checked + .switch-ui {
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
}

.switch-control input:checked + .switch-ui::after {
    transform: translateX(22px);
}

.vat-rate-wrap {
    transition: opacity .15s ease, transform .15s ease;
}

.vat-rate-wrap.disabled {
    opacity: 0.55;
}

/* CATALOG */
.cat-list {
    display: grid;
    gap: 8px;
}
.cat-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--stroke);
    border-radius: 12px;
    background: var(--item-bg);
    align-items: center;
}
.cat-item .cat-name { font-weight: 600; }
.cat-item .cat-meta { color: var(--muted); font-size: 12px; }
.cat-item .cat-price { font-weight: 700; color: var(--primary-strong); white-space: nowrap; }
.cat-item .cat-actions { display: flex; gap: 4px; }

/* SAVED */
.saved-list { display: grid; gap: 16px; }
.saved-section { display: grid; gap: 8px; }
.saved-section-head {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.saved-item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--stroke);
    border-radius: 12px;
    background: var(--item-bg);
    align-items: center;
}
.saved-item .s-title { font-weight: 600; }
.saved-item .s-meta { color: var(--muted); font-size: 12px; }
.saved-item .s-total { font-weight: 700; color: var(--primary-strong); }
.saved-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* SETTINGS */
.logo-preview-wrap { display: grid; gap: 8px; }
.logo-preview {
    min-height: 70px;
    border: 1px dashed var(--stroke-strong);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    background: var(--panel-soft);
    padding: 6px;
    overflow: hidden;
}
.logo-preview img { max-height: 80px; max-width: 100%; }

/* MOBILE FOOTER */
.mobile-footer {
    display: none;
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0));
    z-index: 80;
    padding: 10px;
    border-radius: 22px;
    background: var(--mobile-footer-bg);
    border: 1px solid var(--mobile-footer-border);
    box-shadow: 0 18px 38px rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(18px) saturate(170%);
    -webkit-backdrop-filter: blur(18px) saturate(170%);
}

.mobile-footer-actions {
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 8px;
}

.mobile-footer-actions .btn {
    min-width: 0;
}

.mobile-footer-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
}

.mobile-tab {
    border: none;
    background: transparent;
    color: var(--muted);
    border-radius: 16px;
    padding: 10px 6px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.15;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, transform .08s ease;
}

.mobile-tab.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    color: #fff;
    box-shadow: 0 10px 20px rgba(37, 99, 235, 0.28);
}

/* MODAL */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top, 0));
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
}
.modal.open { display: flex; }
.modal-card {
    background: var(--modal-bg);
    border-radius: var(--radius-lg);
    padding: 18px;
    width: 100%;
    max-width: 460px;
    box-shadow: var(--shadow-lg);
    display: grid;
    gap: 12px;
    max-height: 90vh;
    overflow: auto;
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 6px;
}

.pdf-preview-card {
    max-width: min(1100px, calc(100vw - 32px));
    width: 100%;
    height: min(92vh, 920px);
    padding: 16px;
    grid-template-rows: auto minmax(0, 1fr) auto;
}

.pdf-preview-note {
    margin: 0;
}

.pdf-preview-body {
    min-height: 0;
    border: 1px solid var(--stroke);
    border-radius: 16px;
    overflow: hidden;
    background: #ffffff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.pdf-preview-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: #ffffff;
}

/* CALCULATOR */
.calc-card { max-width: 360px; }
.calc-display {
    background: #0f172a;
    color: #fff;
    border-radius: 12px;
    padding: 14px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.calc-expr {
    color: #94a3b8;
    font-size: 14px;
    min-height: 18px;
    word-break: break-all;
}
.calc-result {
    font-size: 32px;
    font-weight: 700;
    word-break: break-all;
}
.calc-keys {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}
.calc-key {
    background: var(--calc-key-bg);
    border: 1px solid var(--stroke);
    border-radius: 12px;
    padding: 16px;
    font-size: 19px;
    font-weight: 600;
    cursor: pointer;
    transition: transform .06s ease, background .1s ease;
    font-family: inherit;
}
.calc-key:hover { background: var(--calc-key-hover); }
.calc-key:active { transform: translateY(1px); }
.calc-key.op {
    background: var(--primary-soft);
    color: var(--primary-strong);
    border-color: #dfe3ff;
}
.calc-key.warn { background: var(--calc-warn-bg); color: var(--calc-warn-text); border-color: var(--calc-warn-border); }
.calc-key.eq {
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    color: #fff;
    border-color: transparent;
}
.calc-key.zero { grid-column: span 1; }

/* TOAST */
.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%) translateY(40px);
    background: var(--toast-bg);
    color: #fff;
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: transform .22s ease, opacity .22s ease;
    z-index: 300;
    pointer-events: none;
    max-width: 90vw;
    text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

:root[data-theme="dark"] .server-state.ok {
    color: var(--success-text);
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    border-style: solid;
}

:root[data-theme="dark"] .server-state.bad {
    color: var(--danger-text);
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    border-style: solid;
}

:root[data-theme="dark"] .pill.green {
    background: rgba(34, 197, 94, 0.14);
    color: #86efac;
}

:root[data-theme="dark"] .logo-preview {
    background: var(--item-bg);
}

:root[data-theme="dark"] .auth-dot {
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
}

:root[data-theme="dark"] .pdf-preview-body,
:root[data-theme="dark"] .pdf-preview-frame {
    background: #ffffff;
}

/* RESPONSIVE TWEAKS */
@media (max-width: 560px) {
    .tabs { display: none; }
    .mobile-footer { display: block; }
    .container {
        padding: 12px;
        padding-bottom: 156px;
    }
    .card { padding: 14px; }
    .actions-row { justify-content: stretch; }
    .actions-row .btn { flex: 1; min-width: 120px; }
    .app-header { padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top, 0)); }
    .brand-title { font-size: 15px; }
    .cat-item { grid-template-columns: 1fr auto; }
    .cat-item .cat-actions { grid-column: 1 / -1; justify-content: flex-end; }
    .saved-item { grid-template-columns: 1fr; }
    .saved-actions { justify-content: stretch; }
    .saved-actions .btn { flex: 1; min-width: 90px; }
    .line-top {
        grid-template-columns: 1fr;
    }
    .line-actions {
        justify-content: flex-end;
    }
    .line-summary-main {
        grid-template-columns: 1fr;
    }
    .line-summary-side {
        justify-self: start;
        text-align: left;
        gap: 3px;
    }
    .line-price {
        font-size: 17px;
    }
    .toggle-card {
        padding: 12px;
    }
    .switch-field {
        align-items: flex-start;
    }
    .pdf-preview-card {
        height: min(90vh, calc(100vh - 24px));
        padding: 14px;
    }
    .toast {
        bottom: 120px;
    }
}

@media (max-width: 400px) {
    .row-inner { grid-template-columns: 1fr; }
    .line-fields { grid-template-columns: repeat(2, 1fr); }
    .mobile-tab {
        font-size: 11px;
        padding: 10px 4px;
    }
}

/* PRINT fallback */
@media print {
    .app-header, .tabs, .actions-row, .mobile-footer, .modal, .icon-btn { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; border: 1px solid #ddd; page-break-inside: avoid; }
}
