/* Müştəri portalı — dizayn tokenləri (designs/1.png sağ-alt, mobil): CRM ilə eyni palitra, mobil-öncə, kitabxanasız.
   Dark rejim: <html data-theme="dark"> (cookie) və ya brauzer seçimi. */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-soft: #e8eefc;
  --primary-ink: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --info: #0ea5e9;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-md: 0 6px 18px rgba(16, 24, 40, .08);
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111b2e;
  --surface-2: #172236;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --line: #1f2a44;
  --primary: #3b82f6;
  --primary-soft: rgba(59, 130, 246, .16);
  --danger: #f87171;
  --ok: #22c55e;
  --warn: #fbbf24;
  --info: #38bdf8;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .4);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #0b1220; --surface: #111b2e; --surface-2: #172236; --text: #e2e8f0; --muted: #94a3b8; --line: #1f2a44;
    --primary: #3b82f6; --primary-soft: rgba(59, 130, 246, .16); --danger: #f87171; --ok: #22c55e; --warn: #fbbf24; --info: #38bdf8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35); --shadow-md: 0 8px 24px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0 0 .25rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .6rem; font-weight: 700; }
p { margin: .25rem 0 .75rem; }
small, .muted { color: var(--muted); }

.container { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* Üst panel */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; min-height: 60px; padding-top: .4rem; padding-bottom: .4rem; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-mark { flex: none; }
.brand span { color: var(--primary); font-weight: 500; }
.nav { display: none; gap: .25rem; }
.nav a { padding: .45rem .8rem; border-radius: 999px; color: var(--muted); white-space: nowrap; font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.who { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.who-name { display: flex; flex-direction: column; line-height: 1.15; font-size: .9rem; text-align: right; }
.who-name small { font-size: .75rem; }
.avatar { width: 36px; height: 36px; border-radius: 999px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; flex: none; }
.theme-btn { width: 36px; height: 36px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.theme-btn svg { width: 18px; height: 18px; }
@media (min-width: 720px) {
  .nav { display: flex; margin-left: 1rem; }
}

/* Mobil alt naviqasiya (dizayn 1: telefon görünüşü) */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .68rem; color: var(--muted); padding: 4px 0; border-radius: 10px; }
.bottom-nav a svg { width: 22px; height: 22px; }
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a:hover { text-decoration: none; }
@media (min-width: 720px) { .bottom-nav { display: none; } }

main { padding: 1.25rem 16px 5.5rem; }
@media (min-width: 720px) { main { padding-bottom: 2rem; } }
.footer { padding: 1rem 16px 2rem; color: var(--muted); font-size: .8rem; }

/* Kartlar və siyahılar */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card-title { font-weight: 700; margin: 0 0 .6rem; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; box-shadow: var(--shadow); color: inherit; display: flex; flex-direction: column; gap: .35rem; --kpi: var(--primary); }
a.kpi:hover { text-decoration: none; border-color: var(--primary); }
.kpi-icon { width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--kpi) 14%, transparent); color: var(--kpi); }
.kpi-icon svg { width: 18px; height: 18px; }
.kpi .kpi-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .kpi-label { color: var(--muted); font-size: .8rem; font-weight: 500; }

.list { display: flex; flex-direction: column; gap: .5rem; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .75rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; color: inherit; box-shadow: var(--shadow); }
a.row:hover { text-decoration: none; border-color: var(--primary); }
.row .num { font-weight: 700; min-width: 9rem; }
.row .grow { flex: 1 1 12rem; }
.row .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.row.dim { opacity: .6; }
.row.dim .num { text-decoration: line-through; }

/* Cədvəl */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .6rem .7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.dim td { color: var(--muted); text-decoration: line-through; }

/* Status çipi — rəng DB-dən (qayda 7), tonlu */
.chip { display: inline-block; padding: .15rem .65rem; border-radius: 999px; font-size: .78rem; font-weight: 600; color: var(--chip, #6b7280); background: color-mix(in srgb, var(--chip, #6b7280) 14%, transparent); border: 1px solid color-mix(in srgb, var(--chip, #6b7280) 30%, transparent); white-space: nowrap; }
html[data-theme="dark"] .chip { color: color-mix(in srgb, var(--chip, #94a3b8) 70%, #fff); background: color-mix(in srgb, var(--chip, #94a3b8) 22%, transparent); }

/* Proqres */
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; min-width: 6rem; }
.bar > span { display: block; height: 100%; background: var(--ok); }

/* Formalar */
label { display: block; font-size: .85rem; font-weight: 600; margin: .75rem 0 .3rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 9px; font: inherit; background: var(--surface); color: var(--text);
}
textarea { min-height: 5rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 30%, transparent); border-color: var(--primary); }
.field-row { display: grid; grid-template-columns: 1fr; gap: .5rem; }
.field-row.line + .field-row.line { border-top: 1px dashed var(--line); padding-top: .75rem; margin-top: .25rem; }
@media (min-width: 720px) { .field-row { grid-template-columns: 2fr 2fr 1fr 1fr; align-items: end; } .field-row.line + .field-row.line { border-top: 0; padding-top: 0; margin-top: 0; } }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .6rem 1rem; border-radius: 9px; border: 1px solid var(--primary); background: var(--primary); color: var(--primary-ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { filter: brightness(.95); text-decoration: none; }
.btn-outline { background: transparent; color: var(--primary); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-sm { padding: .35rem .75rem; font-size: .85rem; }
.btn-block { display: flex; width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Mesajlar */
.alert { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid; }
.alert-ok { background: color-mix(in srgb, var(--ok) 12%, transparent); border-color: color-mix(in srgb, var(--ok) 35%, transparent); color: var(--ok); }
.alert-err { background: color-mix(in srgb, var(--danger) 12%, transparent); border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); }
.alert-warn { background: color-mix(in srgb, var(--warn) 12%, transparent); border-color: color-mix(in srgb, var(--warn) 35%, transparent); color: var(--warn); }
.alert-info { background: color-mix(in srgb, var(--info) 12%, transparent); border-color: color-mix(in srgb, var(--info) 35%, transparent); color: var(--info); }
.validation-summary-errors ul { margin: 0; padding-left: 1.2rem; }

/* Boş hal (§9.8) */
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty .btn { margin-top: .75rem; }

/* Giriş */
.auth { max-width: 420px; margin: 2rem auto; padding: 2rem 1.5rem; }
.auth .brand { justify-content: center; margin-bottom: 1rem; }
.auth h1 { text-align: center; }
.auth .muted { text-align: center; display: block; margin-bottom: 1rem; }

/* Açar-dəyər */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; font-size: .95rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-bottom: 1rem; }
.page-head .spacer { flex: 1; }
.totals { margin-left: auto; max-width: 24rem; }
.totals dd.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Yazışma */
.msg-list { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }
.msg { border: 1px solid var(--line); border-radius: 12px; padding: .6rem .9rem; max-width: 88%; background: var(--surface-2); }
.msg-mine { align-self: flex-end; background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 30%, transparent); }
.msg-staff { align-self: flex-start; }
.msg-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; font-size: .8rem; margin-bottom: .2rem; }
.msg-tag { font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 1px 7px; border-radius: 999px; background: var(--surface); color: var(--muted); border: 1px solid var(--line); }
.msg-doc { color: var(--muted); font-variant-numeric: tabular-nums; }
.msg-time { margin-left: auto; color: var(--muted); font-size: .75rem; white-space: nowrap; }
.msg-body { white-space: pre-wrap; word-break: break-word; }
.msg-compose textarea { min-height: 4rem; }
