:root {
  --bg: #f4f6fb; --surface: #ffffff; --surface-2: #eef1f7; --text: #1b2230; --muted: #667085;
  --border: #e2e6ef; --primary: #1f6feb; --primary-text: #fff; --danger: #d92d20; --ok: #16a34a; --warn: #d97706;
  --radius: 14px; --shadow: 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c; --surface: #171d27; --surface-2: #1f2733; --text: #e6e9ef; --muted: #98a2b3;
    --border: #2a3342; --primary: #4c8dff; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.icon { width: 17px; height: 17px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round; }
.icon.lg { width: 30px; height: 30px; stroke-width: 2.6; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 22px; } h3 { font-size: 16px; }
a { color: var(--primary); text-decoration: none; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.error { color: var(--danger); min-height: 1em; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 10px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--surface-2); color: var(--text); white-space: nowrap; }
.btn:hover { filter: brightness(.96); } .btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.icon { padding: 6px 9px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 11px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
label.check input { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 0; }
legend { padding: 0 6px; font-weight: 500; }

/* Kirish */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; padding: 32px 28px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login-card label { text-align: left; }
.logo { width: 56px; height: 56px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center;
  font-size: 28px; font-weight: 700; margin: 0 auto; }
.logo.sm { width: 30px; height: 30px; font-size: 16px; margin: 0; }

/* Joylashuv */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 14px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 0 6px; }
nav { display: flex; flex-direction: column; gap: 4px; }
nav a { color: var(--text); padding: 9px 12px; border-radius: 10px; font-weight: 500; display: flex; align-items: center; gap: 10px; }
nav a .icon { width: 19px; height: 19px; }
nav a.active, nav a:hover { background: var(--surface-2); }
nav a.active { color: var(--primary); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 6px; }
main { padding: 24px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.search { position: relative; display: flex; align-items: center; }
.search .icon { position: absolute; left: 11px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 36px; width: 280px; }
.link-icon { display: inline-flex; align-items: center; gap: 6px; }
.logo .icon { stroke: #fff; }
.btn.small .icon { width: 14px; height: 14px; }
.actions select { width: auto; }
.badge { background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 1px 10px; font-size: 13px; font-weight: 600; vertical-align: middle; }

/* Jadval */
.table-wrap { overflow-x: auto; margin-bottom: 16px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  padding: 12px 14px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table td.right { text-align: right; white-space: nowrap; }
.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--surface-2); display: grid; place-items: center;
  font-weight: 700; color: var(--muted); font-size: 14px; }
.name { font-weight: 600; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill.no { background: color-mix(in srgb, var(--danger) 13%, transparent); color: var(--danger); }
.pill.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.pill.gray { background: var(--surface-2); color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 32px; margin: 0; }

/* Forma */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 20px; }
.form-grid .span2 { grid-column: 1 / -1; }
#rel-form { margin-bottom: 16px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { flex-direction: row; align-items: center; gap: 6px; background: var(--surface-2); padding: 6px 10px; border-radius: 999px; font-weight: 500; cursor: pointer; }
.chips input { width: auto; }
.previews { display: flex; gap: 8px; flex-wrap: wrap; }
.previews img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
progress { width: 220px; height: 10px; }

dialog { border: 1px solid var(--border); border-radius: 18px; padding: 0; background: var(--surface); color: var(--text);
  width: min(640px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(10, 14, 22, .5); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1b2230; color: #fff; padding: 11px 18px;
  border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); z-index: 100; max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 14px; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  main { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .search, .search input { width: 100%; }
}
