:root {
  --bg: #f4f3ee;
  --surface: #ffffff;
  --surface-2: #f1f0ea;
  --ink: #16211e;
  --muted: #65706b;
  --line: #e3e1d8;
  --brand: #0b7a5e;
  --brand-strong: #075e48;
  --brand-ink: #ffffff;
  --brand-soft: #dbeee7;
  --amber: #a8690c;
  --amber-soft: #faeed4;
  --red: #bb3225;
  --red-soft: #fae3df;
  --blue: #27688f;
  --blue-soft: #dfecf3;
  --side: #0f201b;
  --side-ink: #c9d6d1;
  --side-active: #1c3a31;
  --hero: #0f2a23;
  --hero-ink: #eef6f3;
  --hero-muted: #9db8ae;
  --shadow: 0 1px 2px rgba(22, 33, 30, .05), 0 8px 24px -16px rgba(22, 33, 30, .18);
  --radius: 14px;
  --font: "Manrope", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0c1311;
  --surface: #141d1a;
  --surface-2: #1b2622;
  --ink: #e7eeeb;
  --muted: #92a19a;
  --line: #25322d;
  --brand: #35c49d;
  --brand-strong: #5ad6b4;
  --brand-ink: #05251c;
  --brand-soft: #153a30;
  --amber: #e8b04f;
  --amber-soft: #3a2c12;
  --red: #f0796b;
  --red-soft: #3f1d19;
  --blue: #7cb9dd;
  --blue-soft: #18303e;
  --side: #0a100e;
  --side-ink: #a9bab3;
  --side-active: #17302a;
  --hero: #11352b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 500 14.5px/1.5 var(--font);
  font-feature-settings: "tnum";
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
svg.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Karkas ---------- */

.shell { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
  padding: 20px 14px;
  background: var(--side); color: var(--side-ink);
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 20px; color: #fff; font-weight: 800; font-size: 16px; letter-spacing: -.01em; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: #35c49d; color: #05251c; }
.brand small { display: block; font-weight: 500; font-size: 11.5px; color: var(--side-ink); letter-spacing: 0; }

.nav-label { padding: 14px 12px 6px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; opacity: .55; }

.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 10px;
  font-weight: 600; transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.nav-link.active { background: var(--side-active); color: #fff; }
.nav-count { margin-left: auto; min-width: 22px; padding: 0 7px; border-radius: 99px; background: #e0574a; color: #fff; font-size: 11.5px; font-weight: 700; text-align: center; line-height: 20px; }
.nav-count.soft { background: #35c49d; color: #05251c; }

.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .08); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.side-user b { display: block; color: #fff; font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.side-user span { font-size: 12px; opacity: .7; }
.side-actions { display: flex; gap: 6px; padding: 4px 6px 0; }
.side-actions form { flex: 1; display: flex; }
.side-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px; border: 0; border-radius: 9px; background: rgba(255, 255, 255, .06); color: inherit; font: inherit; font-size: 13px; cursor: pointer; }
.side-btn:hover { background: rgba(255, 255, 255, .11); color: #fff; }

.main { min-width: 0; padding: 26px 32px 56px; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.topbar h1 { font-size: 25px; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; }
.topbar p { color: var(--muted); margin-top: 3px; }
.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.menu-toggle { display: none; align-items: center; gap: 8px; margin-bottom: 14px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font: inherit; font-weight: 700; cursor: pointer; }
.backdrop { display: none; }

/* ---------- Tugmalar ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 15px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn.danger { color: var(--red); border-color: var(--red-soft); background: var(--red-soft); }
.btn.danger:hover { border-color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.block { width: 100%; }

/* ---------- Kartalar ---------- */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 0; flex-wrap: wrap; }
.card-head h2 { font-size: 15px; font-weight: 800; letter-spacing: -.01em; }
.card-head a.more { color: var(--brand); font-size: 13px; font-weight: 700; }
.card-sub { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 16px 18px 18px; }

.kpis { display: grid; grid-template-columns: 1.5fr repeat(3, 1fr); gap: 14px; margin-bottom: 14px; }
.kpi { padding: 16px 18px; min-width: 0; }
.kpi-label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; font-weight: 700; }
.kpi-value { margin-top: 8px; font-size: 25px; font-weight: 800; letter-spacing: -.025em; line-height: 1.15; overflow-wrap: anywhere; }
.kpi-value small { font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: 0; }
.kpi-note { margin-top: 6px; color: var(--muted); font-size: 12.5px; }
.kpi.alert .kpi-value { color: var(--red); }

.kpi.hero { background: var(--hero); border-color: var(--hero); color: var(--hero-ink); position: relative; overflow: hidden; }
.kpi.hero .kpi-label, .kpi.hero .kpi-note { color: var(--hero-muted); }
.kpi.hero .kpi-value { font-size: 32px; }
.kpi.hero .kpi-value small { color: var(--hero-muted); }
.kpi.hero::after { content: ""; position: absolute; right: -50px; bottom: -70px; width: 190px; height: 190px; border-radius: 50%; border: 34px solid rgba(53, 196, 157, .13); }

.delta { font-weight: 800; }
.delta.up { color: var(--brand); }
.delta.down { color: var(--red); }

.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.grid.two-one { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid.halves { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.thirds { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.detail { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; min-width: 0; }

.chart-box { position: relative; height: 290px; }
.chart-box.short { height: 230px; }
.chart-empty { display: grid; place-items: center; height: 100%; color: var(--muted); }

/* ---------- Jadval ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 18px; text-align: left; color: var(--muted); font-size: 12px; font-weight: 700; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.link:hover { background: var(--surface-2); cursor: pointer; }
td.num, th.num { text-align: right; white-space: nowrap; }
.cell-main { font-weight: 700; display: block; }
.cell-sub { color: var(--muted); font-size: 12.5px; display: block; }
tr.voided td { opacity: .55; text-decoration: line-through; }
tr.voided td:last-child { text-decoration: none; opacity: 1; }

.row-list { display: grid; }
.row-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--line); }
.row-item:last-child { border-bottom: 0; }
a.row-item:hover { background: var(--surface-2); }
.row-amount { font-weight: 800; text-align: right; white-space: nowrap; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge.paid, .badge.active, .badge.completed { background: var(--brand-soft); color: var(--brand); }
.badge.overdue, .badge.cancelled, .badge.blocked { background: var(--red-soft); color: var(--red); }
.badge.today, .badge.partial { background: var(--amber-soft); color: var(--amber); }
.badge.info { background: var(--blue-soft); color: var(--blue); }

.progress { height: 7px; border-radius: 99px; background: var(--surface-2); overflow: hidden; min-width: 90px; }
.progress span { display: block; height: 100%; border-radius: 99px; background: var(--brand); }

.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }

.empty { padding: 34px 18px; text-align: center; color: var(--muted); }

/* ---------- Filtrlar ---------- */

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 700; font-size: 13px; }
.tab:hover { color: var(--ink); }
.tab.active { background: var(--brand-soft); color: var(--brand); }
.search { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.search input, .search select { width: auto; }
.search input[type="search"] { width: 240px; max-width: 100%; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }

/* ---------- Forma ---------- */

label.field { display: block; margin-bottom: 14px; }
label.field > span, .field-label { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 700; }
input, select, textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 500; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input[type="file"] { padding: 6px; color: var(--muted); font-size: 13px; }
input[type="file"]::file-selector-button { margin-right: 10px; padding: 5px 11px; border: 0; border-radius: 7px; background: var(--brand-soft); color: var(--brand); font: inherit; font-weight: 700; cursor: pointer; }
.field-error { display: block; margin-top: 4px; color: var(--red); font-size: 12.5px; font-weight: 600; }
.field-help { display: block; margin-top: 4px; color: var(--muted); font-size: 12.5px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.form-error { margin-bottom: 14px; padding: 10px 12px; border-radius: 10px; background: var(--red-soft); color: var(--red); font-weight: 600; }

.picker { position: relative; }
.picker-list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); max-height: 270px; overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 16px 34px -14px rgba(0, 0, 0, .3); }
.picker-option { display: block; width: 100%; padding: 9px 12px; border: 0; background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.picker-option:hover { background: var(--surface-2); }
.picker-option small { display: block; color: var(--muted); }
.picker-chosen { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.picker-chosen button { border: 0; background: none; color: inherit; font: inherit; font-size: 12.5px; text-decoration: underline; cursor: pointer; }

.summary { display: grid; gap: 8px; padding: 14px; border-radius: 10px; background: var(--surface-2); margin-bottom: 14px; }
.summary div { display: flex; justify-content: space-between; gap: 12px; }
.summary b { font-weight: 800; }

.facts { display: grid; }
.fact { display: flex; justify-content: space-between; gap: 14px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.fact:last-child { border-bottom: 0; }
.fact span:first-child { color: var(--muted); }
.fact span:last-child { font-weight: 700; text-align: right; overflow-wrap: anywhere; }

.contract-progress { display: flex; align-items: center; gap: 12px; margin-top: 12px; color: var(--muted); font-size: 13px; font-weight: 700; }
.contract-progress .progress { flex: 1; height: 9px; }

details.date-edit { display: inline-block; position: relative; }
details.date-edit summary { list-style: none; color: var(--brand); font-size: 12.5px; font-weight: 700; cursor: pointer; }
details.date-edit summary::-webkit-details-marker { display: none; }
details.date-edit form { display: flex; gap: 6px; margin-top: 6px; }
details.date-edit input { width: 150px; padding: 5px 8px; }

.passport { display: block; width: 100%; max-height: 230px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }

.toast-stack { display: grid; gap: 8px; margin-bottom: 16px; }
.toast { padding: 10px 14px; border-radius: 10px; font-weight: 700; background: var(--blue-soft); color: var(--blue); }
.toast.success { background: var(--brand-soft); color: var(--brand); }
.toast.warning { background: var(--amber-soft); color: var(--amber); }
.toast.error { background: var(--red-soft); color: var(--red); }

/* ---------- Kirish sahifasi ---------- */

.login { display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }
.login-side { display: flex; flex-direction: column; justify-content: space-between; padding: 44px; background: var(--hero); color: var(--hero-ink); position: relative; overflow: hidden; }
.login-side::after { content: ""; position: absolute; right: -130px; bottom: -130px; width: 440px; height: 440px; border-radius: 50%; border: 70px solid rgba(53, 196, 157, .12); }
.login-side h1 { font-size: 36px; font-weight: 800; letter-spacing: -.025em; line-height: 1.15; max-width: 440px; }
.login-side p { margin-top: 12px; color: var(--hero-muted); max-width: 400px; }
.login-side .brand { padding: 0; }
.login-form { display: grid; place-items: center; padding: 28px; }
.login-form form { width: min(360px, 100%); }
.login-form h2 { font-size: 23px; font-weight: 800; letter-spacing: -.02em; margin-bottom: 20px; }

/* ---------- Moslashuvchanlik ---------- */

@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two-one, .grid.thirds, .grid.detail { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .nav-open .sidebar { transform: none; }
  .nav-open .backdrop { display: block; position: fixed; z-index: 30; inset: 0; background: rgba(0, 0, 0, .45); }
  .main { padding: 16px 16px 44px; }
  .menu-toggle { display: inline-flex; }
  .grid.halves { grid-template-columns: minmax(0, 1fr); }
  .login { grid-template-columns: minmax(0, 1fr); }
  .login-side { display: none; }
  .search, .search input[type="search"] { width: 100%; }
}

@media (max-width: 520px) {
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .form-row { grid-template-columns: minmax(0, 1fr); }
  .topbar h1 { font-size: 22px; }
}

@media print {
  .sidebar, .menu-toggle, .topbar-actions, .no-print { display: none !important; }
  .shell, .grid.detail { display: block; }
  .main { padding: 0; }
  .card { box-shadow: none; }
}
