:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e4e7ec;
  --text: #101828;
  --muted: #667085;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --red: #b42318;    --red-soft: #fef3f2;
  --amber: #b54708;  --amber-soft: #fffaeb;
  --blue: #175cd3;   --blue-soft: #eff8ff;
  --green: #067647;  --green-soft: #ecfdf3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f19;
    --surface: #141a26;
    --surface-2: #1a2130;
    --border: #273042;
    --text: #eef1f6;
    --muted: #93a0b5;
    --accent: #8b8cf8;
    --accent-soft: rgba(129, 140, 248, .14);
    --red: #f97066;    --red-soft: rgba(240, 68, 56, .14);
    --amber: #fdb022;  --amber-soft: rgba(247, 144, 9, .14);
    --blue: #53b1fd;   --blue-soft: rgba(46, 144, 250, .14);
    --green: #47cd89;  --green-soft: rgba(23, 178, 106, .14);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; letter-spacing: -.01em; }
.logo {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff; font-size: 14px; font-weight: 700;
}
.top-meta { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 13px; }
.top-meta form { margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 7px 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { width: 100%; padding: 10px 14px; border: 0; background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-accent { border: 0; background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent); color: #fff; filter: brightness(1.08); }

/* ---------- Layout ---------- */

main { max-width: 1240px; margin: 0 auto; padding: 24px; display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }

.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; letter-spacing: -.02em; }
.sub { color: var(--muted); font-size: 13px; }
.crumb { color: var(--muted); font-size: 13px; }
.crumb a { color: var(--accent); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 15px; font-weight: 650; }
.card-body { padding: 16px 20px; }

/* ---------- Stat cards ---------- */

.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat { padding: 16px 18px; position: relative; overflow: hidden; }
.stat::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--tone, var(--accent)); }
.stat-label { color: var(--muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.stat-value { margin-top: 6px; font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--tone-text, var(--text)); }
.stat-sub { margin-top: 2px; color: var(--muted); font-size: 12.5px; }
.tone-red   { --tone: var(--red);   --tone-text: var(--red); }
.tone-amber { --tone: var(--amber); --tone-text: var(--amber); }
.tone-blue  { --tone: var(--blue);  --tone-text: var(--blue); }
.tone-green { --tone: var(--green); }
.tone-violet { --tone: #8b5cf6; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 16px; text-align: left; white-space: nowrap; }
th {
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
td { border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
th.num, td.num { text-align: center; }
.w-name { font-weight: 600; }
.w-name a { color: var(--text); }
.w-name a:hover { color: var(--accent); }
th.idx, td.idx { width: 1%; padding-right: 4px; color: var(--muted); font-weight: 500; }
/* Butun qator bosiladi: worker havolasi qatorning hamma yuzasini qoplaydi */
.workers tbody tr { position: relative; cursor: pointer; }
.workers tbody tr:hover .row-link { color: var(--accent); }
.row-link::after { content: ""; position: absolute; inset: 0; }
.note { display: block; margin-top: 2px; color: var(--amber); font-size: 12px; font-weight: 500; white-space: normal; }
.muted { color: var(--muted); }

.load { display: flex; align-items: center; gap: 10px; min-width: 150px; }
.bar { flex: 1; min-width: 60px; height: 6px; border: 0; border-radius: 99px; background: var(--border); overflow: hidden; appearance: none; -webkit-appearance: none; }
.bar::-webkit-progress-bar { background: var(--border); }
.bar::-webkit-progress-value { background: var(--green); border-radius: 99px; }
.bar::-moz-progress-bar { background: var(--green); border-radius: 99px; }

.pill {
  display: inline-block; min-width: 30px; padding: 2px 9px; border-radius: 99px;
  font-weight: 650; font-size: 13px; text-align: center;
}
.pill-red   { background: var(--red-soft);   color: var(--red); }
.pill-amber { background: var(--amber-soft); color: var(--amber); }
.pill-blue  { background: var(--blue-soft);  color: var(--blue); }
.pill-green { background: var(--green-soft); color: var(--green); }
.zero { color: var(--muted); opacity: .6; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; background: var(--muted); }
.dot-online { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.dot-bad { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }

/* ---------- Group lists ---------- */

.search {
  width: min(320px, 100%); padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-2); color: var(--text); font: inherit;
}
.search::placeholder { color: var(--muted); }

.tabs { display: flex; gap: 4px; padding: 10px 14px 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  padding: 9px 14px; border: 0; background: none; cursor: pointer;
  color: var(--muted); font: inherit; font-weight: 600; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .count { margin-left: 6px; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; }

.panel-title { padding: 14px 20px 0; font-size: 13px; color: var(--muted); font-weight: 600; }
.js .panel-title { display: none; }
.js .tab-panel:not(.is-active) { display: none; }
html:not(.js) .tabs, html:not(.js) .search { display: none; }

.rows { list-style: none; margin: 0; padding: 6px 0; }
.row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 11px 20px; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }
.row-main { min-width: 0; overflow-wrap: anywhere; }
.row-title { font-weight: 600; }
.row-reason { margin-top: 2px; color: var(--muted); font-size: 13px; }
.arrow { margin: 0 8px; color: var(--muted); }
.tg { color: var(--accent); font-weight: 600; }
a.tg:hover { text-decoration: underline; }
.new { color: var(--green); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; flex-shrink: 0; max-width: 55%; }
.chip {
  padding: 2px 9px; border-radius: 7px; font-size: 12.5px; font-weight: 550;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
a.chip:hover { color: var(--accent); border-color: var(--accent); }
.chip b { font-weight: 650; }
.chip-green { background: var(--green-soft); color: var(--green); border-color: transparent; }
.chip-red   { background: var(--red-soft);   color: var(--red);   border-color: transparent; }
.chip-amber { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.chip-blue  { background: var(--blue-soft);  color: var(--blue);  border-color: transparent; }
.chip-muted b { font-weight: 550; }
.pill-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.row-title .pill { margin-right: 8px; font-size: 12px; }
.row-others { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.row-side { flex-shrink: 0; }
.empty { padding: 28px 20px; text-align: center; color: var(--muted); }
.panel-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.panel-actions .btn { flex-shrink: 0; }
.confirm { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 18px 20px; border-color: var(--accent); }
.confirm-buttons { display: flex; gap: 10px; }
.strike { text-decoration: line-through; opacity: .7; }
.alert-green { background: var(--green-soft); color: var(--green); border-color: color-mix(in srgb, var(--green) 25%, transparent); }
.card-head h2 a:hover { color: var(--accent); }

.grid-2 { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; }
.alert {
  padding: 12px 16px; border-radius: 11px; font-weight: 500;
  background: var(--amber-soft); color: var(--amber); border: 1px solid color-mix(in srgb, var(--amber) 25%, transparent);
}
.alert-red { background: var(--red-soft); color: var(--red); border-color: color-mix(in srgb, var(--red) 25%, transparent); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }

/* ---------- Login ---------- */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: min(380px, 100%); padding: 30px 28px; }
.login .brand { justify-content: center; font-size: 18px; margin-bottom: 6px; }
.login p.sub { text-align: center; margin: 0 0 22px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 13px; }
.field input {
  width: 100%; padding: 10px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.login .alert { margin-bottom: 16px; font-size: 13px; }

@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .top-meta .when { display: none; }
  .row { flex-direction: column; gap: 8px; }
  .chips { justify-content: flex-start; max-width: 100%; }
}
