/* ------------------------------------------------------------------ tokenlar */
:root {
  --ink: #23264a;          /* siyoh: chap ustun, sarlavhalar */
  --ink-hover: #2f3462;
  --rail-text: #c6c9e4;
  --rail-muted: #8d92b8;
  --paper: #f1f2f5;        /* qog'oz: umumiy fon */
  --surface: #ffffff;
  --rule: #dadde5;
  --text: #1d2033;
  --muted: #636981;
  --accent: #3d4fd6;
  --accent-text: #ffffff;
  --selected: #e9ebfb;
  --danger: #b23a3a;

  --st-new: #3d4fd6;
  --st-in_review: #a3650d;
  --st-answered: #2e7650;
  --st-closed: #767c90;

  --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --radius-s: 6px;
  --radius-m: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #0f1124;
    --ink-hover: #1b1e3a;
    --rail-text: #c6c9e4;
    --rail-muted: #7f84a8;
    --paper: #15172a;
    --surface: #1c1f36;
    --rule: #2e3250;
    --text: #e6e7f2;
    --muted: #9a9fba;
    --accent: #8c99ff;
    --accent-text: #12142a;
    --selected: #272b4f;
    --danger: #ff8a8a;
    --st-new: #8c99ff;
    --st-in_review: #e3a54c;
    --st-answered: #62c08c;
    --st-closed: #959bb0;
    color-scheme: dark;
  }
}

/* ------------------------------------------------------------------ asos */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
a { color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--rule); background: var(--surface);
  border-radius: var(--radius-s); padding: 9px 16px; font-weight: 500;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-primary:disabled { opacity: .55; cursor: progress; }
.btn-ghost { background: transparent; }
.btn-wide { width: 100%; }

/* ------------------------------------------------------------------ kirish */
.login {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 1fr);
}
.login-side {
  background: var(--ink);
  color: var(--rail-text);
  padding: clamp(32px, 7vw, 96px);
  display: flex; flex-direction: column; justify-content: flex-end;
}
.login-univ { margin: 0 0 20px; font-weight: 600; color: #fff; font-size: 17px; }
.login-title {
  margin: 0; color: #fff;
  font-size: clamp(40px, 6vw, 72px); line-height: 1.02; font-weight: 700;
  letter-spacing: -0.03em; max-width: 9ch;
}
.login-lead { margin: 24px 0 0; max-width: 42ch; font-size: 17px; line-height: 1.55; }
.login-form {
  align-self: center; justify-self: center;
  width: min(360px, 100% - 32px);
  display: flex; flex-direction: column; gap: 16px;
  padding: 32px 0;
}
.login-form h2 { margin: 0 0 8px; font-size: 22px; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.field input {
  border: 1px solid var(--rule); background: var(--surface); color: var(--text);
  border-radius: var(--radius-s); padding: 11px 12px; font-size: 16px;
}
.form-error { margin: 0; min-height: 1.4em; color: var(--danger); font-size: 14px; }

/* ------------------------------------------------------------------ panel tuzilishi */
.shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: 236px minmax(320px, 420px) minmax(0, 1fr);
}

/* chap ustun */
.rail {
  background: var(--ink); color: var(--rail-text);
  display: flex; flex-direction: column; gap: 18px;
  padding: 20px 12px 14px; overflow-y: auto;
}
.rail-head { padding: 4px 10px 6px; display: flex; flex-direction: column; }
.rail-univ { color: var(--rail-muted); font-size: 13px; }
.rail-title { color: #fff; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.rail-group { display: flex; flex-direction: column; gap: 2px; }
.rail-h { margin: 0 10px 6px; font-size: 13px; font-weight: 500; color: var(--rail-muted); }

.filter {
  position: relative;
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  width: 100%; border: 0; background: transparent; color: inherit; text-align: left;
  padding: 6px 10px; border-radius: var(--radius-s); font-size: 14px;
}
.filter:hover { background: var(--ink-hover); }
.filter[aria-pressed="true"] { background: rgba(255, 255, 255, .1); color: #fff; font-weight: 600; }
.filter-count { font-variant-numeric: tabular-nums; color: var(--rail-muted); font-weight: 400; }
.filter[aria-pressed="true"] .filter-count { color: #fff; }
.filter-dot { width: 7px; height: 7px; border-radius: 50%; margin-right: 8px; flex: none; align-self: center; }
.dot-new { background: var(--st-new); }
.dot-in_review { background: var(--st-in_review); }
.dot-answered { background: var(--st-answered); }
.dot-closed { background: var(--st-closed); }
.filter-label { display: flex; align-items: center; min-width: 0; }
.filter-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter.is-new .filter-count { color: #fff; background: var(--st-new); border-radius: 99px; padding: 0 7px; }
.filter.is-urgent .filter-count { color: #fff; background: #c4423f; border-radius: 99px; padding: 0 7px; }
.rail-note { margin: 6px 10px 0; font-size: 12px; color: var(--rail-muted); }

.rail-foot {
  margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255, 255, 255, .1);
  display: flex; justify-content: space-between; align-items: center; font-size: 14px;
}
.rail-user { color: #fff; }
.rail-logout { border: 0; background: none; color: var(--rail-muted); padding: 4px 0; }
.rail-logout:hover { color: #fff; }

/* mobil filtr paneli ochiqligida orqa fonni yopuvchi qatlam */
.scrim { display: none; position: fixed; inset: 0; z-index: 15; background: rgba(10, 12, 30, .45); }

/* ro'yxat */
.list-pane {
  border-right: 1px solid var(--rule);
  display: flex; flex-direction: column; min-height: 0; background: var(--paper);
}
.list-head { display: flex; gap: 8px; padding: 16px 16px 8px; }
.filters-toggle { display: none; }
.search {
  flex: 1; min-width: 0;
  border: 1px solid var(--rule); background: var(--surface);
  border-radius: var(--radius-s); padding: 9px 12px; font-size: 15px;
}
.list-count { margin: 0; padding: 0 16px 8px; font-size: 13px; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0 8px 16px; overflow-y: auto; flex: 1; }
.list-empty { padding: 32px 16px; color: var(--muted); }

.row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "num cat time" "preview preview preview" "meta meta meta";
  column-gap: 10px; row-gap: 4px;
  width: 100%; text-align: left;
  border: 0; border-left: 3px solid transparent;
  background: transparent; border-radius: 0 var(--radius-s) var(--radius-s) 0;
  padding: 12px 12px 12px 13px; margin-bottom: 2px;
}
.row:hover { background: var(--surface); }
.row[aria-current="true"] { background: var(--selected); }
.row.s-new { border-left-color: var(--st-new); }
.row.s-in_review { border-left-color: var(--st-in_review); }
.row.s-answered { border-left-color: var(--st-answered); }
.row.s-closed { border-left-color: var(--rule); }
.row-num { grid-area: num; font-weight: 700; font-variant-numeric: tabular-nums; }
.row-cat { grid-area: cat; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.row-time { grid-area: time; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.row-preview {
  grid-area: preview; color: var(--muted); font-size: 14px; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.row.s-new .row-preview { color: var(--text); }
.row-meta { grid-area: meta; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.row-status { font-weight: 600; }
.row-urgent { font-weight: 600; color: var(--danger); }
.s-new .row-status { color: var(--st-new); }
.s-in_review .row-status { color: var(--st-in_review); }
.s-answered .row-status { color: var(--st-answered); }
.s-closed .row-status { color: var(--st-closed); }

.pager { display: flex; gap: 8px; justify-content: center; padding: 0 16px 16px; }
.pager:empty { display: none; }
.pager-info { align-self: center; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* o'qish oynasi */
.read-pane { overflow-y: auto; background: var(--surface); min-height: 0; }
.read-empty { max-width: 46ch; margin: 18vh auto 0; padding: 0 24px; font-size: 16px; }
.read-empty .muted { font-size: 14px; }

.doc { max-width: 760px; padding: 28px clamp(20px, 4vw, 48px) 0; }
.doc-back { display: none; margin-bottom: 16px; }
.doc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.doc-num {
  margin: 0; font-size: 44px; line-height: 1; font-weight: 700;
  letter-spacing: -0.03em; font-variant-numeric: tabular-nums; color: var(--text);
}
/* Holat — rektorat muhri kabi */
.stamp {
  display: inline-block; margin-top: 4px;
  border: 2px solid currentColor; border-radius: 4px;
  padding: 3px 10px; font-weight: 700; font-size: 14px;
  transform: rotate(-2deg);
}
.stamp.s-new { color: var(--st-new); }
.stamp.s-in_review { color: var(--st-in_review); }
.stamp.s-answered { color: var(--st-answered); }
.stamp.s-closed { color: var(--st-closed); }

.doc-cat { margin: 12px 0 4px; font-size: 20px; font-weight: 600; }
.doc-cat-hint { margin-left: 10px; font-size: 13px; font-weight: 400; color: var(--muted); }
.doc-meta { margin: 0; color: var(--muted); font-size: 14px; display: flex; flex-wrap: wrap; gap: 4px 18px; }

/* AI tahlili */
.ai-card {
  margin: 20px 0 0; padding: 14px 16px 16px;
  border: 1px solid var(--rule); border-radius: var(--radius-m); background: var(--paper);
}
.ai-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.ai-title { margin: 0; font-size: 15px; font-weight: 600; }
.ai-urgency { font-size: 13px; font-weight: 600; }
.u-high { color: var(--danger); }
.u-medium { color: var(--st-in_review); }
.u-low { color: var(--muted); }
.ai-summary { margin: 8px 0 0; font-size: 15px; line-height: 1.5; }
.ai-wait { margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.ai-error { margin: 8px 0 0; font-size: 14px; color: var(--danger); }
.ai-controls { margin-top: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ai-field { font-size: 14px; color: var(--muted); }
.ai-controls select {
  max-width: 100%; border: 1px solid var(--rule); background: var(--surface);
  border-radius: var(--radius-s); padding: 6px 10px; font-size: 14px;
}
.ai-note { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.btn-small { padding: 6px 12px; font-size: 14px; }

.author {
  margin: 20px 0 0; padding: 14px 16px; border: 1px solid var(--rule); border-radius: var(--radius-m);
  display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px;
}
.author dt { color: var(--muted); }
.author dd { margin: 0; overflow-wrap: anywhere; }
.author-anon { grid-template-columns: 1fr; color: var(--muted); border-style: dashed; }

.status-bar { margin: 22px 0 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.status-bar-label { font-size: 14px; color: var(--muted); margin-right: 4px; }
.status-btn {
  border: 1px solid var(--rule); background: transparent; border-radius: 99px;
  padding: 5px 12px; font-size: 13px; font-weight: 500;
}
.status-btn:hover { border-color: var(--muted); }
.status-btn[aria-pressed="true"] { color: var(--surface); border-color: transparent; }
.status-btn.s-new[aria-pressed="true"] { background: var(--st-new); }
.status-btn.s-in_review[aria-pressed="true"] { background: var(--st-in_review); }
.status-btn.s-answered[aria-pressed="true"] { background: var(--st-answered); }
.status-btn.s-closed[aria-pressed="true"] { background: var(--st-closed); }

.letter {
  margin: 28px 0 0; padding: 0 0 28px; border-bottom: 1px solid var(--rule);
  font-family: var(--serif); font-size: 18px; line-height: 1.7;
  white-space: pre-wrap; overflow-wrap: anywhere; max-width: 66ch;
}

.files { margin: 24px 0 0; }
.files h3, .log h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.files-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.thumb {
  display: block; width: 132px; height: 100px; border-radius: var(--radius-s);
  overflow: hidden; border: 1px solid var(--rule); background: var(--paper);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-link {
  display: inline-flex; flex-direction: column; justify-content: center;
  min-width: 180px; max-width: 260px; height: 100px; padding: 10px 14px;
  border: 1px solid var(--rule); border-radius: var(--radius-s); text-decoration: none; color: var(--text);
}
.file-link span:first-child { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-link span:last-child { color: var(--muted); font-size: 13px; }

/* yozishmalar jurnali */
.log { margin: 28px 0 0; }
.log ol { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--rule); }
.entry { position: relative; padding: 0 0 18px 14px; }
.entry::before {
  content: ""; position: absolute; left: -25px; top: 6px;
  width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--rule);
}
.entry-head { display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: baseline; font-size: 14px; }
.entry-who { font-weight: 600; }
.entry-time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.entry-text {
  margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere;
  font-family: var(--serif); font-size: 16px; line-height: 1.6; max-width: 64ch;
}
.entry-admin::before { border-color: var(--accent); background: var(--accent); }
.entry-student::before { border-color: var(--text); }
.entry-system .entry-who { font-weight: 500; color: var(--muted); }

/* javob */
.reply {
  margin-top: 8px;
  border-top: 1px solid var(--rule);
  padding: 20px 0 32px; display: flex; flex-direction: column; gap: 10px;
}
.reply textarea {
  width: 100%; min-height: 96px; max-height: 40vh; resize: vertical;
  border: 1px solid var(--rule); border-radius: var(--radius-m); background: var(--paper);
  padding: 12px 14px; font-size: 15px; line-height: 1.5;
}
.reply-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.reply-check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.reply-hint { margin: 0; font-size: 13px; color: var(--muted); }
.reply-closed { padding: 18px 0 24px; color: var(--muted); font-size: 14px; }

/* xabar */
.toast {
  position: fixed; right: 24px; bottom: 24px; transform: translateY(16px);
  background: var(--text); color: var(--surface);
  padding: 10px 16px; border-radius: var(--radius-s); font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: min(520px, calc(100% - 32px));
}
.toast.show { opacity: 1; transform: none; }
.toast.warn { background: var(--danger); color: #fff; }

/* ------------------------------------------------------------------ moslashuvchanlik */
@media (max-width: 1180px) {
  .shell { grid-template-columns: 204px minmax(300px, 360px) minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .login { grid-template-columns: 1fr; }
  .login-side { padding: 40px 24px 32px; }
  .login-title { font-size: 40px; }

  .shell { grid-template-columns: 1fr; }
  .filters-toggle { display: inline-flex; }
  .rail {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 20;
    transform: translateX(-100%); transition: transform .2s;
  }
  .shell.rail-open .rail { transform: none; }
  .shell.rail-open .scrim { display: block; }
  .list-pane { border-right: 0; min-height: 100dvh; }
  .read-pane { position: fixed; inset: 0; z-index: 10; display: none; }
  .shell.reading .read-pane { display: block; }
  .doc-back { display: inline-flex; }
  .doc-num { font-size: 36px; }
  .letter { font-size: 17px; }
}

@media (max-width: 600px) {
  .toast { left: 16px; right: 16px; bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .stamp { transform: none; }
}
