/* Mavzuni theme.js tanlaydi: <html data-theme="light | dark"> */
:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #e1e4ea;
  --fg: #171a21;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #e6eefe;
  --accent-fg: #ffffff;
  --danger: #d92d20;
  --danger-soft: #fdeceb;
  --success: #17803d;
  --warning-soft: #fff4d6;
  --warning-fg: #8a5a00;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.04);
  --radius: 12px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #111317;
  --surface: #1b1e24;
  --surface-2: #262a32;
  --border: #2e333d;
  --fg: #e9ebf0;
  --muted: #9aa1ad;
  --accent: #5b9cf5;
  --accent-soft: #1d2a40;
  --accent-fg: #0b1220;
  --danger: #f0655a;
  --danger-soft: #3a1f1d;
  --success: #4ac27a;
  --warning-soft: #3a3016;
  --warning-fg: #f2c661;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 24px; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
p { margin: 4px 0 0; }
section { margin-top: 28px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer, .grow { flex: 1; min-width: 0; }
.icon { display: block; width: 18px; height: 18px; flex: none; }
[hidden] { display: none !important; }

/* ---------- tugma va maydonlar ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; white-space: nowrap;
  padding: 9px 14px; border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  background: var(--accent); color: var(--accent-fg);
  transition: filter 0.15s, background 0.15s, transform 0.05s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: var(--surface); color: var(--fg); border-color: var(--border); }
.btn.secondary:hover, .btn.ghost:hover { background: var(--surface-2); filter: none; }
.btn.ghost { background: transparent; color: var(--fg); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger-text { color: var(--danger); }
.btn.danger-text:hover { background: var(--danger-soft); }
.btn.icon-only { padding: 9px; }
.btn:disabled { opacity: 0.5; cursor: default; }
[aria-busy="true"] { opacity: 0.6; pointer-events: none; }

input, select {
  font: inherit; color: var(--fg); background: var(--surface);
  padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); min-width: 0;
}
input.narrow { width: 84px; }
:is(input, select, button):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- yuqori panel ---------- */

.topbar {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px max(16px, calc((100% - 1040px) / 2));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; margin-right: 8px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-fg);
}
.brand-mark.large { width: 56px; height: 56px; border-radius: 16px; }
.brand-mark.large .icon { width: 28px; height: 28px; }
nav { display: flex; gap: 4px; }
.nav-item {
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-weight: 600; color: var(--muted); background: none; border: 0; cursor: pointer;
  padding: 8px 12px; border-radius: 10px;
}
.nav-item:hover { background: var(--surface-2); color: var(--fg); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.user-chip { display: flex; align-items: center; gap: 10px; line-height: 1.2; }
.user-name { font-weight: 600; }

main { max-width: 1040px; margin: 0 auto; padding: 24px 16px 64px; }
.page-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-title.with-action > div:first-of-type, .page-title.with-back > div { flex: 1; min-width: 200px; }

/* ---------- umumiy bo'laklar ---------- */

.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--muted); color: #fff; font-weight: 700; font-size: 14px;
}
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.list { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 14px; }
.row.blocked .avatar, .row.blocked .row-title { opacity: 0.55; }
.row-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.row-actions { display: flex; gap: 2px; }
.row-icon { display: inline-flex; padding: 9px; border-radius: 10px; background: var(--surface-2); color: var(--muted); }
.list.compact { gap: 0; margin-top: 12px; }
.list.compact .row { padding: 10px 0; border-top: 1px solid var(--border); }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--accent); color: #fff; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted);
}
.chip .icon { width: 13px; height: 13px; }
.chip.live, .chip.rec { background: var(--danger-soft); color: var(--danger); }
.chip.soon { background: var(--warning-soft); color: var(--warning-fg); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: pulse 1.4s ease-in-out infinite; }
.count { font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
@keyframes pulse { 50% { opacity: 0.35; } }

.empty {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  padding: 28px 16px; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius);
}
.empty .icon { width: 28px; height: 28px; opacity: 0.7; }
.panel .empty { border: 0; padding: 20px 8px 8px; }

/* ---------- kirish ---------- */

.login { max-width: 1040px; margin: 0 auto; padding: 16px 16px 64px; }
.login-top { display: flex; justify-content: flex-end; }
.login-hero { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 16px 0 8px; }
.account-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.account {
  display: flex; align-items: center; gap: 12px; text-align: left;
  font: inherit; color: var(--fg); cursor: pointer;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.1s;
}
.account:hover { border-color: var(--accent); transform: translateY(-1px); }
.account-text { flex: 1; min-width: 0; }
.account-name { font-weight: 600; }

/* ---------- darslar ---------- */

.lesson { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 14px 16px; }
.lesson.live { border-color: var(--danger); }
.lesson-time { min-width: 92px; padding-right: 16px; border-right: 1px solid var(--border); }
.lesson-clock { font-size: 22px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.lesson-body { flex: 1; min-width: 160px; }
.lesson-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; font-size: 16px; }
.progress { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.progress progress { width: 170px; accent-color: var(--accent); }
video.player { display: block; width: 100%; max-height: 72vh; margin-top: 20px; border-radius: var(--radius); background: #000; }

/* ---------- admin ---------- */

.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin: 20px 0 14px; }
.search { position: relative; flex: 1; min-width: 220px; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { width: 100%; padding-left: 38px; }
.segmented { display: flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--surface-2); }
.segmented button {
  font: inherit; font-weight: 600; color: var(--muted); background: none; border: 0; cursor: pointer;
  padding: 6px 10px; border-radius: 9px; white-space: nowrap;
}
.segmented button.active { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
.segmented .count { background: none; padding: 0; }

.group-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); margin-top: 20px; }
.group-card {
  position: relative; display: flex; align-items: center; gap: 12px; text-align: left; overflow: hidden;
  font: inherit; color: var(--fg); cursor: pointer; padding: 16px 14px 16px 22px;
  transition: border-color 0.15s, transform 0.1s;
}
.group-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.group-card > .icon { color: var(--muted); }
.group-stripe { position: absolute; left: 0; top: 0; bottom: 0; width: 6px; }
.group-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 10px; }

.panels { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); margin-top: 20px; align-items: start; }
.panel { margin: 0; padding: 16px; }
.panel h2 { display: flex; align-items: center; gap: 8px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.inline-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.inline-form select { flex: 1; min-width: 140px; }

/* ---------- dialog va xabarlar ---------- */

.modal {
  width: min(420px, calc(100vw - 32px)); padding: 20px; border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); color: var(--fg); box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.modal::backdrop { background: rgba(8, 10, 14, 0.55); }
.modal h2 { font-size: 18px; margin-bottom: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; font-weight: 600; font-size: 13px; }
.field input, .field select { font-weight: 400; font-size: 15px; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 12px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  max-width: min(520px, 92vw); padding: 11px 16px; border-radius: 12px;
  background: #1f2937; color: #fff; font-weight: 500; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
#toast.error { background: #b42318; }
#toast.success { background: #166534; }

#loading {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 30; opacity: 0;
  background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 50% 100%; background-repeat: no-repeat;
}
/* 0.25s kechikish: tez javob keladigan so'rovlarda chiziq miltillamaydi */
.busy #loading { opacity: 1; transition: opacity 0.1s 0.25s; animation: loading 1s linear infinite; }
@keyframes loading { from { background-position: -50% 0; } to { background-position: 150% 0; } }

/* ---------- jonli dars (har doim to'q rangda) ---------- */

.room-page {
  position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column;
  background: #0d0f13; color: #f1f3f7;
}
.room-top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; min-height: 52px; }
.room-title { font-weight: 700; font-size: 16px; margin-right: 4px; }
.room-page .chip { background: #23262e; color: #cfd4dc; }
.room-page .chip.live, .room-page .chip.rec { background: #3a1f1d; color: #ff7a6e; font-variant-numeric: tabular-nums; }

.room { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 0 12px; }
/* flex: oxirgi to'lmagan qator o'rtada turadi (masalan, 3 kishi: 2 + 1) */
.grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; width: 100%; }
.tile {
  width: calc((100% - (var(--columns, 1) - 1) * 8px) / var(--columns, 1));
  position: relative; aspect-ratio: 16 / 9; overflow: hidden; border-radius: 14px;
  background: #1c1f26; outline: 2px solid transparent; outline-offset: -2px; transition: outline-color 0.15s;
}
.tile.speaking { outline-color: #4ade80; }
.tile video { display: block; width: 100%; height: 100%; object-fit: cover; }
.tile > .avatar { display: none; position: absolute; inset: 0; margin: auto; width: 22%; height: auto; aspect-ratio: 1; min-width: 40px; font-size: clamp(15px, 2.6vw, 34px); }
.tile.no-video > .avatar { display: inline-flex; }
.tile .name {
  position: absolute; left: 8px; bottom: 8px; z-index: 1; display: flex; align-items: center; gap: 6px;
  max-width: calc(100% - 16px); padding: 3px 9px; border-radius: 8px;
  background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 13px; font-weight: 500;
}
.name-text { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mic-off { display: none; color: #ff7a6e; }
.mic-off .icon { width: 14px; height: 14px; }
.tile.muted-mic .mic-off { display: inline-flex; }

/* Kimdir ekran ulashganda: ekran katta, ishtirokchilar pastda kichik qator bo'lib turadi */
.stage { display: none; flex: 1; min-height: 0; width: 100%; gap: 8px; }
.room.sharing .stage { display: flex; }
.tile.screen { flex: 1; min-width: 0; aspect-ratio: auto; background: #000; }
.tile.screen video { object-fit: contain; }
.room.sharing .grid { flex-wrap: nowrap; width: auto; max-width: 100%; overflow-x: auto; flex: none; }
.room.sharing .grid .tile { width: 168px; flex: none; border-radius: 10px; }
/* kichik katakda bosh harflar ism yozuvidan yuqoriroqda turadi */
.room.sharing .grid .tile > .avatar { inset: 0 0 26px; width: auto; height: 46%; min-width: 0; font-size: 14px; }
.room.sharing .grid .name { left: 5px; bottom: 5px; max-width: calc(100% - 10px); padding: 2px 7px; font-size: 12px; }

.controls { display: flex; align-items: flex-start; justify-content: center; gap: 6px; flex-wrap: wrap; padding: 12px 12px max(12px, env(safe-area-inset-bottom)); }
.ctl {
  display: flex; flex-direction: column; align-items: center; gap: 5px; width: 92px;
  font: inherit; font-size: 12px; color: #cfd4dc; background: none; border: 0; cursor: pointer; padding: 0;
}
.ctl-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: 50%; background: #2a2e37; color: #fff; transition: background 0.15s;
}
.ctl-icon .icon { width: 21px; height: 21px; }
.ctl:hover .ctl-icon { background: #363b46; }
.ctl-label { line-height: 1.2; text-align: center; }
.ctl[data-state="off"] .ctl-icon { background: #f1f3f7; color: #c2261b; }
.ctl[data-state="active"] .ctl-icon { background: #2563eb; }
.ctl[data-state="recording"] .ctl-icon { background: #d92d20; animation: pulse 1.4s ease-in-out infinite; }
.ctl[data-state="done"] { opacity: 0.6; cursor: default; }
.ctl.danger .ctl-icon { background: #d92d20; }
.ctl.danger:hover .ctl-icon { background: #b42318; }
.ctl-divider { width: 1px; height: 48px; background: #2a2e37; margin: 0 6px; }

.audio-blocked {
  align-self: center; display: inline-flex; align-items: center; gap: 8px; margin-top: 8px;
  font: inherit; font-weight: 600; color: #0b1220; background: #fbbf24; border: 0; border-radius: 99px; padding: 8px 14px; cursor: pointer;
}
.room-connecting {
  position: absolute; inset: 52px 0 96px; display: flex; align-items: center; justify-content: center; gap: 12px;
  color: #cfd4dc; font-weight: 500;
}
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid #2a2e37; border-top-color: #fff; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- telefon ---------- */

@media (max-width: 640px) {
  h1 { font-size: 21px; }
  .user-chip > div { display: none; }
  .nav-item span { display: none; }
  .lesson-time { min-width: 0; }
  .lesson-action, .lesson-action .btn { width: 100%; }
  .progress { align-items: stretch; }
  .progress progress { width: 100%; }
  .ctl { width: 64px; }
  .ctl-label { display: none; }
  .ctl-divider { margin: 0 2px; }
  .room.sharing .grid .tile { width: 112px; }
}

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