:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f2f0eb;
  --border: #e4e0d9;
  --text: #1c1d1f;
  --muted: #6b6d70;
  --brand: #0f6e80;
  --brand-strong: #0b5866;
  --brand-soft: #e2f0f2;
  --on-brand: #ffffff;
  --danger: #c8321f;
  --danger-soft: #fbe9e6;
  --success: #12805c;
  --success-soft: #e1f3eb;
  --warn: #a35a00;
  --warn-soft: #fdf0d8;
  --violet: #6440b8;
  --violet-soft: #eee9fa;
  --live: #e5322d;
  --log-bg: #15181b;
  --log-text: #d7dade;
  --shadow: 0 1px 2px rgba(20, 20, 20, 0.04), 0 2px 8px rgba(20, 20, 20, 0.04);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111315;
    --surface: #1a1d20;
    --surface-2: #22262a;
    --border: #2d3237;
    --text: #e7e8e6;
    --muted: #9ba1a6;
    --brand: #4fb0c2;
    --brand-strong: #74c4d3;
    --brand-soft: #16353b;
    --on-brand: #06262c;
    --danger: #f0786a;
    --danger-soft: #3a1d19;
    --success: #4cc79a;
    --success-soft: #15332a;
    --warn: #f0b45a;
    --warn-soft: #3a2a12;
    --violet: #ad94f0;
    --violet-soft: #2a2140;
    --live: #ff5a52;
    --log-bg: #0b0d0f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, "Noto Sans", "Noto Sans Arabic", sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
bdi, .bidi { unicode-bidi: plaintext; }

.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- layout ---------- */

.shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 14px;
  color: var(--text);
  font-weight: 650;
  font-size: 15px;
}
.brand:hover { text-decoration: none; }
.brand img { width: 30px; height: 30px; }
.brand small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 550;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-strong); }
.nav .count {
  margin-left: auto;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--live);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
}
.nav .count:empty { display: none; }

.sidebar-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 8px 0;
  border-top: 1px solid var(--border);
}
.me { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 550; }

.main { padding: 28px 32px 48px; min-width: 0; }
.page { max-width: 1320px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head .sub { margin-top: 4px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 550; margin-bottom: 8px; }
.back .icon { width: 16px; height: 16px; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* ---------- cards & stats ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
}
.card-head .muted { font-weight: 500; }
.card-body { padding: 0 18px 18px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat { padding: 16px 18px; }
.stat-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 550; font-size: 13px; }
.stat-label .icon { width: 16px; height: 16px; }
.stat-value { margin-top: 6px; font-size: 28px; font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-foot { color: var(--muted); font-size: 12.5px; }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  padding: 8px 18px;
  text-align: left;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 11px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 6px; }
tr.clickable { cursor: pointer; }

.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.person-id { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }

.avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 12px;
  font-weight: 700;
}
.avatar.sm { width: 26px; height: 26px; font-size: 11px; }
.avatar.recorder { background: var(--surface-2); color: var(--muted); }

.media { display: inline-flex; gap: 6px; }
.media .icon { width: 17px; height: 17px; }
.media .on { color: var(--success); }
.media .off { color: var(--muted); opacity: 0.55; }
.media .muted-state { color: var(--danger); }

.empty {
  padding: 36px 18px;
  text-align: center;
  color: var(--muted);
}
.empty .icon { width: 30px; height: 30px; margin-bottom: 8px; opacity: 0.6; }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 2px; }

/* ---------- badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
}
.badge .icon { width: 13px; height: 13px; }
.badge.live, .badge.rec { background: var(--danger-soft); color: var(--live); }
.badge.live::before, .badge.rec::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.6s ease-in-out infinite;
}
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.brand { background: var(--brand-soft); color: var(--brand-strong); }
.badge.violet { background: var(--violet-soft); color: var(--violet); }
@keyframes pulse { 50% { opacity: 0.35; } }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.dot.ok { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.dot.bad { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

/* ---------- buttons & inputs ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn:focus-visible, input:focus-visible, select:focus-visible, .nav a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.btn .icon { width: 16px; height: 16px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-strong); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(0.93); }
.btn.danger-ghost { color: var(--danger); }
.btn.danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.icon-only { width: 32px; padding: 0; }
.btn.icon-only.small { width: 28px; }
.btn.block { width: 100%; }

input, select {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input::placeholder { color: var(--muted); }

.search { position: relative; display: inline-flex; align-items: center; }
.search .icon { position: absolute; left: 10px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 32px; width: 260px; max-width: 100%; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar .spacer { flex: 1; }

.segmented { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--surface-2); gap: 2px; flex-wrap: wrap; }
.segmented button {
  height: 28px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 550; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }

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

.timeline { list-style: none; margin: 0; padding: 0 18px 14px; }
.timeline li { display: grid; grid-template-columns: 14px minmax(0, 1fr); gap: 10px; padding: 7px 0; }
.timeline .tl-dot { width: 8px; height: 8px; margin-top: 7px; border-radius: 50%; background: var(--muted); }
.timeline .tl-text { overflow-wrap: anywhere; }
.timeline .tl-meta { color: var(--muted); font-size: 12px; }
.cat-meeting { --cat: var(--brand); }
.cat-people { --cat: var(--success); }
.cat-media { --cat: var(--muted); }
.cat-recording { --cat: var(--live); }
.cat-admin { --cat: var(--violet); }
.cat-warn { --cat: var(--warn); }
.cat-danger { --cat: var(--danger); }
.timeline [class*="cat-"] .tl-dot, .tl-dot[class*="cat-"] { background: var(--cat); }

.services { list-style: none; margin: 0; padding: 0 18px 14px; }
.services li { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.services .name { font-weight: 600; }
.services .since { margin-left: auto; color: var(--muted); font-size: 12.5px; }

.meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 6px 0 4px; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--brand); }
.meter.high > span { background: var(--danger); }

.alert {
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 550;
}

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); }

/* ---------- logs ---------- */

.logbox {
  height: calc(100vh - 290px);
  min-height: 320px;
  overflow: auto;
  padding: 12px 0;
  border-radius: var(--radius);
  background: var(--log-bg);
  color: var(--log-text);
  font: 12.5px/1.55 ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.logline { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 12px; padding: 0 16px; }
.logline:hover { background: rgba(255, 255, 255, 0.04); }
.logline time { color: #7d858d; }
.logline span { white-space: pre-wrap; overflow-wrap: anywhere; }
.logline.error span { color: #ff8b80; }
.logline.warn span { color: #f3c26b; }
.logline.debug span { color: #8d969e; }
.logbox .empty { color: #8d969e; }

/* ---------- login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 20px; }
.login-card p { margin: -8px 0 4px; }
.login-logo { width: 40px; height: 40px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; }
.field input { height: 40px; font-weight: 400; font-size: 14px; }
.form-error { margin: 0; color: var(--danger); font-weight: 550; }

/* ---------- dialog & toasts ---------- */

.dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.dialog.wide { width: min(960px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(10, 12, 14, 0.5); }
.dialog form { margin: 0; }
.dialog-body { padding: 22px 22px 8px; }
.dialog-body h2 { font-size: 17px; margin-bottom: 8px; }
.dialog-body p { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 22px 20px; }
.dialog video { display: block; width: 100%; max-height: 70vh; background: #000; border-radius: 10px; margin-top: 10px; }

.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 10; }
.toast {
  max-width: 380px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-weight: 550;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  animation: toast-in 0.2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.skeleton { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- small screens ---------- */

@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: sticky;
    z-index: 5;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 8px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .brand { padding: 0 6px 0 0; }
  .brand span { display: none; }
  .nav { flex-direction: row; }
  .nav a { padding: 7px 9px; white-space: nowrap; }
  .nav a .label { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; border: 0; }
  .sidebar-foot .me { display: none; }
  .main { padding: 18px 16px 40px; }
  .stats { gap: 10px; }
  .stat-value { font-size: 24px; }
  th, td { padding-left: 12px; padding-right: 12px; }
  .search input { width: 100%; }
  .logline { grid-template-columns: minmax(0, 1fr); gap: 0; }
}
.person-text { min-width: 0; }
.dialog-option { margin-top: 14px; color: var(--text); }
.logline span { tab-size: 4; }
