:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --text: #1c2433;
  --muted: #6b7689;
  --line: #e2e7ef;
  --primary: #2457d6;
  --primary-dark: #1b45ad;
  --danger: #c93434;
  --ok: #1d8a4e;
  --warn: #b7791f;
  --sidebar: #172036;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
.muted { color: var(--muted); }

/* --- Tuzilma --- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { font-size: 18px; font-weight: 700; padding: 20px; }

#nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }

#nav button {
  background: none;
  border: 0;
  color: #c6cfe2;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

#nav button:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
#nav button.active { background: var(--primary); color: #fff; }

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-footer .muted { color: #9aa6bf; overflow: hidden; text-overflow: ellipsis; }

.content { flex: 1; padding: 28px 32px; min-width: 0; }

.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.head h1 { margin: 0; }

/* --- Kartalar --- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
}

.card .num { font-size: 28px; font-weight: 700; }
.card .label { color: var(--muted); margin-top: 4px; }

/* --- Jadval --- */
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow-x: auto;
}

table { border-collapse: collapse; width: 100%; }

th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }

th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); background: #fafbfd; white-space: nowrap; }

tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8faff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td.empty { text-align: center; color: var(--muted); padding: 28px; }
tr.clickable { cursor: pointer; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.wrap-any { overflow-wrap: anywhere; }

/* --- Tugma va maydonlar --- */
.btn {
  display: inline-block;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
}

.btn:hover { border-color: #c4cddc; background: #f7f9fc; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 9px; font-size: 13px; }
.btn.wide { width: 100%; padding: 11px; }

input, select, textarea {
  font: inherit;
  color: inherit;
  border: 1px solid #cfd6e2;
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  max-width: 100%;
}

input:focus, select:focus, textarea:focus { outline: 2px solid rgba(36, 87, 214, 0.25); border-color: var(--primary); }
textarea { width: 100%; min-height: 150px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
input.tiny { width: 70px; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.filters input[type="search"], .filters input[name="chat"], .filters input[name="invite_link"] { flex: 1; min-width: 220px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label, .login-card label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
.form-grid label.check { flex-direction: row; align-items: center; font-weight: 400; font-size: 14px; }
.form-grid input:not([type="checkbox"]), .form-grid select { width: 100%; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }
.hint { color: var(--muted); font-weight: 400; font-size: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.form-error { color: var(--danger); margin: 10px 0 0; }
.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-weight: 400; }
.file-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; }

.note { background: #fff8e6; border: 1px solid #f1dfae; border-radius: 10px; padding: 10px 14px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #e8edf7; color: #3b4a66; }
.badge.active { background: #dff3e7; color: var(--ok); }
.badge.paused { background: #fde4e4; color: var(--danger); }
.badge.scheduled { background: #fff1d6; color: var(--warn); }
.badge.ended { background: #e8eaee; color: #5c6575; }

.pager { display: flex; align-items: center; gap: 10px; margin-top: 12px; }

dl.info { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 8px; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; font-weight: 600; }

/* --- Modal va xabar --- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 40, 0.5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 10;
}

.modal[hidden], .toast[hidden], [hidden] { display: none !important; }

.modal-box { background: var(--panel); border-radius: 14px; width: 100%; max-width: 820px; padding: 22px 24px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 18px; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #1c2433;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  max-width: 420px;
  z-index: 20;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}

.toast.error { background: var(--danger); }

/* --- Kirish sahifasi --- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 30px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 { margin: 0; }
.login-card p { margin: 0; }

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  #nav { flex-direction: row; flex-wrap: wrap; }
  .content { padding: 18px 14px; }
  .form-grid { grid-template-columns: 1fr; }
}
