:root {
    --bg: #f4f6fa;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --line: #e2e8f0;
    --primary: #0f4c8a;
    --primary-dark: #0b3a6a;
    --primary-soft: #e8f0fa;
    --ok: #15803d;
    --ok-soft: #dcfce7;
    --bad: #b91c1c;
    --bad-soft: #fee2e2;
    --warn: #a16207;
    --warn-soft: #fef3c7;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font: 15px/1.5 "Noto Sans Georgian", "Sylfaen", "DejaVu Sans", system-ui, sans-serif;
}
a { color: var(--primary); }
h1 { font-size: 1.45rem; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.nowrap { white-space: nowrap; }
code { background: var(--primary-soft); padding: 1px 6px; border-radius: 4px; font-size: .85em; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.content { padding-top: 20px; padding-bottom: 32px; min-height: calc(100vh - 120px); }
.footer { color: var(--muted); font-size: .8rem; padding-bottom: 20px; text-align: center; }

/* top bar */
.topbar { background: var(--primary); color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: 16px; min-height: 58px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.brand img { height: 34px; background: #fff; border-radius: 6px; padding: 2px; }
.nav { display: flex; align-items: center; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a { color: #dbe7f5; text-decoration: none; padding: 8px 12px; border-radius: 8px; font-size: .92rem; }
.nav a:hover, .nav a.active { background: rgba(255,255,255,.14); color: #fff; }
.nav-user { color: #b6cbe3; font-size: .85rem; padding: 0 8px 0 12px; border-left: 1px solid rgba(255,255,255,.2); margin-left: 6px; }
.nav-toggle { display: none; margin-left: auto; background: none; border: 0; color: #fff; font-size: 1.5rem; cursor: pointer; }

/* cards & layout */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card.narrow { max-width: 440px; width: 100%; }
.center-block { margin: 40px auto; }
.center-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0; }
.section-title { margin-top: 32px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.meta { display: grid; gap: 6px; font-size: .92rem; }
.meta a { word-break: break-all; }

/* forms */
.form label, .form .label { display: block; font-weight: 500; font-size: .92rem; }
.form > label, .form > .grid-2, .form > .upload-row { margin-bottom: 14px; }
input, select, textarea {
    width: 100%; margin-top: 5px; padding: 10px 12px; font: inherit; color: inherit;
    border: 1px solid #cbd5e1; border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 76, 138, .25); border-color: var(--primary); }
input[type=checkbox] { width: auto; margin: 0; }
input[type=file] { padding: 7px; background: #f8fafc; }
textarea { resize: vertical; }
textarea.mono { font-family: "Noto Sans Georgian", Consolas, monospace; font-size: .9rem; line-height: 1.55; }
.check { display: flex !important; align-items: center; gap: 10px; font-weight: 400 !important; margin: 8px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; flex: none; }
.check.disabled { color: var(--muted); cursor: default; }
.has-error input, .has-error select { border-color: var(--bad); background: #fffafa; }
.field-error { display: block; color: var(--bad); font-size: .82rem; font-weight: 400; margin-top: 4px; }
.hint { font-size: .85rem; color: var(--muted); margin: -6px 0 12px; }
.w-sm { max-width: 110px; }
.label-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.file-import { font-weight: 400; font-size: .82rem; color: var(--muted); }
.file-import input { width: auto; margin: 0 0 0 4px; padding: 3px; font-size: .8rem; }

fieldset { border: 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px 6px; margin: 0 0 16px; }
legend { float: left; width: 100%; padding: 0; margin-bottom: 12px; font-weight: 700; color: var(--primary); font-size: 1rem; }
fieldset > *:not(legend) { clear: both; }
fieldset > label, fieldset > .grid-2, fieldset > .chips { margin-bottom: 14px; }

.inline-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.inline-form label { font-size: .88rem; font-weight: 500; }
.inline-form .grow { flex: 1 1 220px; }
.inline-form .btn { margin-bottom: 1px; }
.test-sms { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--line); }

.upload-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; }
.upload-row label:not(.check) { flex: 1 1 240px; }
.preview-img { max-height: 70px; max-width: 200px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: #fff; }
.preview-img.stamp { max-height: 110px; }

/* buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: 8px; border: 1px solid #cbd5e1; background: #fff; color: var(--text);
    font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: .82rem; }
.btn.big { padding: 13px 20px; font-size: 1.02rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .35; cursor: default; pointer-events: none; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    padding: 9px 14px; border-radius: 999px; border: 1px solid #c7d6ea; background: var(--primary-soft);
    color: var(--primary); font: inherit; font-size: .92rem; cursor: pointer;
}
.chip:hover { border-color: var(--primary); }
.chip.selected { background: var(--primary); color: #fff; border-color: var(--primary); }
.placeholders { margin-bottom: 14px; }
.placeholders .chip { font-size: .82rem; padding: 6px 11px; }
.years-row { display: flex; gap: 8px; align-items: center; margin-top: 5px; }
.years-row .chip { min-width: 46px; }
.years-row .years-input { width: 90px; margin: 0; }

/* alerts & badges */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; font-size: .93rem; }
.alert.success { background: var(--ok-soft); border-color: #86efac; color: #14532d; }
.alert.error { background: var(--bad-soft); border-color: #fca5a5; color: #7f1d1d; }
.alert.warning { background: var(--warn-soft); border-color: #fcd34d; color: #713f12; }
.alert.info { background: var(--primary-soft); border-color: #bfd3ea; color: var(--primary-dark); }
.alert a { font-weight: 600; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.expired { background: var(--bad-soft); color: var(--bad); }
.badge.muted { background: #eef2f7; color: var(--muted); }

/* tables */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; background: #f8fafc; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafcff; }
.table td input, .table td select { margin: 0; padding: 7px 9px; }
.table .empty { text-align: center; color: var(--muted); padding: 30px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row-actions form { margin: 0; }
.toolbar { margin: 0 0 10px; display: flex; justify-content: flex-end; }
.order-cell { width: 1%; }
.order-cell form { display: flex; gap: 4px; margin: 0; }
.order-btn { padding: 4px 9px; font-size: .75rem; line-height: 1.2; }
.table tr.inactive td { opacity: .55; }

/* admin list */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; color: var(--muted); font-size: .85rem; text-decoration: none; }
.stat span { display: block; font-size: 1.6rem; font-weight: 700; color: var(--text); }
.stat.warn span { color: var(--bad); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.filters input { flex: 1 1 280px; margin: 0; }
.filters select { flex: 0 1 200px; margin: 0; }
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.pager a, .pager span { padding: 6px 12px; border-radius: 6px; background: var(--card); text-decoration: none; box-shadow: var(--shadow); }
.pager .current { background: var(--primary); color: #fff; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs a { padding: 7px 14px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); text-decoration: none; font-size: .9rem; }
section.card { scroll-margin-top: 80px; }

/* customer pages */
.customer { background: linear-gradient(160deg, #0f4c8a 0%, #1d6fb8 45%, #f4f6fa 45.1%); background-attachment: fixed; }
.customer-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--primary); margin-bottom: 18px; }
.customer-brand img { max-height: 44px; }
.login-link { text-align: center; margin: 18px 0 0; font-size: .82rem; }
.login-link a { color: var(--muted); }
.customer-list { max-width: 900px; }
.customer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; color: #fff; margin: 8px 0 22px; }
.customer-head .muted { color: #cfe0f3; }
.customer-head h1 { color: #fff; }
.cards { display: flex; flex-direction: column; gap: 14px; }
.warranty-card { margin: 0; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 16px 28px; }
.warranty-card h2 { margin: 8px 0 12px; font-size: 1.2rem; overflow-wrap: anywhere; }
.wc-top { display: flex; align-items: center; gap: 12px; font-size: .85rem; }
.wc-facts { display: flex; flex-wrap: wrap; gap: 10px 32px; }
.wc-facts span { display: block; font-size: .8rem; color: var(--muted); }
.wc-facts b { font-weight: 600; white-space: nowrap; }
.warranty-card .actions { display: flex; flex-direction: column; gap: 8px; min-width: 200px; }
.warranty-card .actions .btn { white-space: normal; text-align: center; line-height: 1.3; min-height: 44px; padding: 10px 16px; }

/* mobile */
@media (max-width: 860px) {
    .nav-toggle { display: block; }
    .nav { display: none; width: 100%; flex-direction: column; align-items: stretch; padding-bottom: 10px; }
    .nav-open .nav { display: flex; }
    .nav-user { border: 0; margin: 6px 0 0; padding: 6px 12px; }
    .grid-2 { grid-template-columns: 1fr; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    h1 { font-size: 1.25rem; }
    fieldset { padding: 16px 14px 4px; }
    .card { padding: 16px; }
}
@media (max-width: 640px) {
    .warranty-card { grid-template-columns: 1fr; }
    .warranty-card .actions { min-width: 0; }
    .wc-facts { gap: 10px 20px; }
}

[hidden] { display: none !important; }
.issuer { display: flex; flex-direction: column; gap: 2px; padding: 4px 0 14px; }
.issuer b { font-size: 1.05rem; }
.product-field { display: grid; gap: 12px; }
.seg { display: inline-flex; background: #eef2f7; border-radius: 10px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.seg label { position: relative; display: block; padding: 8px 16px; border-radius: 8px; cursor: pointer; font-weight: 500; font-size: .92rem; color: var(--muted); }
.seg input { position: absolute; left: 0; top: 0; width: 1px; height: 1px; min-height: 0 !important; margin: 0; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }
.seg label:has(input:focus-visible) { outline: 2px solid rgba(15, 76, 138, .35); }

/* ================================================================ mobile UX */
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 62vw; }
a[href^="tel:"] { text-decoration: none; }

@media (max-width: 860px) {
    /* iOS-ზე ველზე დაჭერისას გადიდება რომ არ მოხდეს — მინ. 16px */
    input, select, textarea { font-size: 16px; }
    input:not([type=checkbox]):not([type=file]), select { min-height: 46px; }

    .topbar-inner { min-height: 54px; }
    .nav { gap: 2px; border-top: 1px solid rgba(255,255,255,.15); padding-top: 6px; }
    .nav a { padding: 12px 14px; font-size: 1rem; }
    .nav .logout { color: #fecaca; }
    .nav-toggle { width: 44px; height: 44px; }

    .content { padding-top: 14px; }
    .page-head > .btn, .page-head > .row-actions { width: 100%; }
    .page-head > .row-actions .btn { flex: 1 1 0; }
    .btn { min-height: 44px; white-space: normal; text-align: center; line-height: 1.3; }
    .btn.sm { min-height: 38px; padding: 7px 12px; font-size: .88rem; }

    /* სტატისტიკა */
    .stats { gap: 8px; }
    .stat { padding: 10px 12px; font-size: .8rem; }
    .stat span { font-size: 1.3rem; }

    /* ფილტრები */
    .filters input { flex: 1 1 100%; }
    .filters select { flex: 1 1 calc(50% - 5px); min-width: 0; }
    .filters .btn { flex: 1 1 0; }

    /* ჰორიზონტალური ფორმები (დამატება) */
    .inline-form { gap: 10px; }
    .inline-form > label { flex: 1 1 calc(50% - 5px); min-width: 0; }
    .inline-form > label.grow { flex-basis: 100%; }
    .inline-form > .btn { flex: 1 1 100%; }

    /* პარამეტრების ჩანართები — ჰორიზონტალური სქროლი, ეკრანზე მიმაგრებული */
    .tabs { flex-wrap: nowrap; overflow-x: auto; position: sticky; top: 54px; z-index: 5;
            background: var(--bg); margin: 0 0 14px; padding: 8px 0; scrollbar-width: none; }
    .tabs::-webkit-scrollbar { display: none; }
    .tabs a { flex: none; padding: 9px 14px; }
    section.card { scroll-margin-top: 120px; }
    .label-row { flex-direction: column; align-items: flex-start; }
    .upload-row { flex-direction: column; align-items: stretch; gap: 12px; }
    .upload-row label:not(.check) { flex: none; }
    .upload-row .preview-img { align-self: flex-start; }
    .upload-row .w-sm { max-width: none; }
    .settings-actions .btn, .card .row-actions > .btn { flex: 1 1 100%; }

    /* ინსტალატორის ფორმა — შენახვის ღილაკი ყოველთვის ხილვადია */
    .warranty-form > button[type=submit] {
        position: sticky; bottom: 10px; z-index: 6;
        box-shadow: 0 6px 20px rgba(15, 76, 138, .35);
    }
    .chip { padding: 10px 14px; }
    .seg { display: flex; }
    .seg label { flex: 1 1 0; text-align: center; padding: 11px 8px; }
    .years-row .chip { flex: 1 1 0; min-width: 0; min-height: 46px; }
    .years-row .years-input { width: 76px; flex: none; }
    .check input { width: 22px; height: 22px; }

    .footer { padding-bottom: 28px; }
}

/* ცხრილები → ბარათები მობილურზე */
@media (max-width: 760px) {
    .table-wrap.stack { background: transparent; box-shadow: none; overflow: visible; }
    .table.stack, .table.stack tbody, .table.stack tr, .table.stack td { display: block; width: 100%; }
    .table.stack thead { display: none; }
    .table.stack tr {
        background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
        padding: 12px 14px; margin-bottom: 12px;
    }
    .table.stack tbody tr:hover { background: var(--card); }
    .table.stack tr.inactive { opacity: .6; }
    .table.stack tr.inactive td { opacity: 1; }
    .table.stack td { border: 0; padding: 6px 0; }
    .table.stack td[data-label] { position: relative; padding-left: 40%; min-height: 30px; }
    .table.stack td[data-label]::before {
        content: attr(data-label); position: absolute; left: 0; top: 7px; width: 37%;
        color: var(--muted); font-size: .8rem; line-height: 1.3;
    }
    .table.stack td[data-label]:has(input:not([type=checkbox]), select)::before { top: 18px; }
    .table.stack td.card-no { padding-bottom: 0; color: var(--muted); font-size: .85rem; }
    .table.stack td.card-title { font-size: 1.05rem; font-weight: 600; padding-bottom: 8px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
    .table.stack td.card-title .muted { font-weight: 400; }
    .table.stack td.empty { text-align: center; }
    .table.stack td.row-actions {
        display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line);
    }
    .table.stack td.row-actions > .btn, .table.stack td.row-actions > form { flex: 1 1 calc(50% - 4px); }
    .table.stack td.row-actions form .btn { width: 100%; }
    .table.stack .btn.sm { min-height: 42px; font-size: .92rem; }
    .table.stack td.order-cell { width: 100%; }
    .table.stack .order-btn { min-width: 46px; }
    .table.stack input[type=checkbox] { width: 24px; height: 24px; margin-top: 3px; }
    .table.stack td .w-sm { max-width: 120px; }
}
