:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #16191d;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2563eb;
  --accent-soft: #eaf0ff;
  --ok: #0f7b4f;
  --warn: #9a6700;
  --danger: #b42318;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --surface: #1c1f25;
    --text: #e9ecf1;
    --muted: #9aa3b2;
    --line: #2b2f37;
    --accent: #6b9bff;
    --accent-soft: #1e2636;
    --ok: #5ad19b;
    --warn: #e3b341;
    --danger: #ff8a7a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Kirish ekrani */
.screen { min-height: 100vh; }
.login-card {
  max-width: 420px;
  margin: 12vh auto;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
}
h1 { font-size: 22px; margin: 0 0 8px; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.chip {
  display: inline-block; margin-left: 8px; padding: 2px 8px;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; font-size: 12px; font-weight: 600;
}

/* Tablar */
.tabs {
  display: flex; gap: 4px; padding: 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 49px; z-index: 4;
}
.tab {
  flex: 1; padding: 9px 10px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); font-weight: 600; cursor: pointer;
}
.tab.active { background: var(--accent-soft); color: var(--accent); }

main { max-width: 760px; margin: 0 auto; padding: 14px 12px 90px; }

/* Chat */
.messages { display: flex; flex-direction: column; gap: 12px; }
.bubble {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.bubble.user {
  background: var(--accent-soft); border-color: transparent;
  align-self: flex-end; max-width: 85%;
}
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul { margin: 4px 0 10px; padding-left: 20px; }
.bubble h4 { margin: 12px 0 6px; font-size: 14px; text-transform: none; }

.sources { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.sources h5 {
  margin: 0 0 6px; font-size: 12px; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted);
}
.source {
  border-left: 3px solid var(--accent); padding: 4px 0 4px 10px;
  margin-bottom: 8px; font-size: 14px;
}
.source.external { border-left-color: var(--warn); }
.source .passage { color: var(--muted); font-size: 13px; }
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 700; border: 1px solid var(--line);
  color: var(--muted); margin-left: 6px;
}
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.meta-line { margin-top: 8px; font-size: 12px; color: var(--muted); }

/* Composer */
.composer {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; gap: 8px; padding: 10px 12px;
  background: var(--surface); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: vertical; min-height: 44px; padding: 10px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit;
}

button, select, input, textarea { font: inherit; }
button { cursor: pointer; border-radius: 10px; }
.primary {
  background: var(--accent); color: #fff; border: 0; padding: 10px 16px; font-weight: 600;
}
.primary[disabled] { opacity: .55; cursor: progress; }
.ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--line); padding: 7px 12px;
}
.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); padding: 6px 10px; }
.link { color: var(--accent); text-decoration: none; font-weight: 600; }

input[type="text"], input[type="search"], input[type="number"], select, textarea {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text); width: 100%;
}

/* Ro'yxatlar */
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.item h3 { margin: 0 0 4px; font-size: 15px; }
.item .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.search-row input { flex: 1; }

.notice { margin: 10px 0; font-size: 14px; color: var(--muted); }
.notice.error { color: var(--danger); }
.notice.ok { color: var(--ok); }

pre.material-text {
  white-space: pre-wrap; word-break: break-word; font: inherit;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin: 0;
}

/* Admin */
.admin-grid { display: grid; gap: 14px; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }

@media (max-width: 560px) {
  .row-2 { grid-template-columns: 1fr; }
  table { font-size: 13px; }
}
