/* ==========================================================================
   أ/ السيد الغريب — design system
   Monochrome shadcn-style. No gradients, no decorative color.
   ========================================================================== */

:root {
  --canvas: #f5f5f5;
  --paper: #ffffff;
  --surface-alt: #fafafa;
  --ink: #0a0a0a;
  --soft-ink: #171717;
  --muted: #737373;
  --hairline: #e5e5e5;
  --destructive: #e7000b;

  --radius-card: 24px;
  --radius-control: 18px;
  --radius-nested: 10px;

  --shadow-card: 0 0 0 1px rgba(23, 23, 23, 0.05), 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
  --font: 'Geist', 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --media-bg: #0a0a0a;
  --media-surface: #171717;
  --media-hairline: #262626;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.6;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.02em; color: var(--ink); }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

.app-body { min-height: 100vh; background: var(--canvas); }

.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------- primitives */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 18px;
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, opacity 120ms ease, transform 60ms ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--ink); color: var(--surface-alt); }
.btn--primary:hover { background: var(--soft-ink); }
.btn--outline { background: transparent; border-color: var(--hairline); color: var(--ink); }
.btn--outline:hover { background: var(--canvas); }
.btn--ghost { background: transparent; color: var(--ink); }
.btn--ghost:hover { background: var(--canvas); }
.btn--danger { background: var(--destructive); color: #fff; }
.btn--danger:hover { background: #c50009; }
.btn--block { width: 100%; }
.btn--sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 12px; }

.input, select.input, textarea.input {
  width: 100%;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  background: var(--canvas);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: box-shadow 120ms ease, background 120ms ease;
}
.input:focus { box-shadow: 0 0 0 3px var(--hairline); background: var(--paper); }
textarea.input { min-height: 72px; resize: vertical; line-height: 1.5; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field__label { font-size: 13px; font-weight: 500; color: var(--muted); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 2px 12px;
  border-radius: var(--radius-control);
  background: var(--canvas);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
}
.badge--outline { background: transparent; border: 1px solid var(--hairline); color: var(--muted); }
.badge[data-status='live'] { background: var(--ink); color: var(--surface-alt); }

.alert { padding: 12px 16px; border-radius: var(--radius-nested); font-size: 13px; margin-bottom: 14px; }
.alert--danger { background: #fef2f2; border: 1px solid #fecaca; color: var(--destructive); }

.card {
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; background: var(--canvas); }
.pill--ready { background: #ecfdf5; color: #067647; }
.pill--recording { background: #fff7ed; color: #b45309; }
.pill--failed { background: #fef2f2; color: var(--destructive); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 12px; border: none;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 15px;
}
.icon-btn:hover { background: var(--canvas); color: var(--ink); }
.icon-btn--danger:hover { color: var(--destructive); background: #fef2f2; }

.empty-line { color: var(--muted); font-size: 13px; padding: 10px 0; list-style: none; }

/* ------------------------------------------------------------------ auth */

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--canvas);
}
.auth-shell { width: 100%; max-width: 420px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth-brand__mark {
  display: grid; place-items: center; width: 44px; height: 44px;
  border-radius: 14px; background: var(--ink); color: var(--surface-alt); font-size: 22px;
}
.auth-brand__text { display: flex; flex-direction: column; }
.auth-brand__text strong { font-size: 16px; }
.auth-brand__text small { color: var(--muted); font-size: 12px; }
.auth-card__header { margin-bottom: 18px; }
.auth-card__title { font-size: 24px; }
.auth-card__subtitle { color: var(--muted); margin: 6px 0 0; }
.form { display: flex; flex-direction: column; }

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

.admin-body { min-height: 100vh; background: var(--canvas); }
.admin-topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 14px 24px; background: var(--paper); border-bottom: 1px solid var(--hairline);
  position: sticky; top: 0; z-index: 20;
}
.admin-nav { display: flex; gap: 6px; }
.admin-nav__link { padding: 8px 14px; border-radius: 12px; color: var(--muted); font-weight: 500; }
.admin-nav__link:hover { background: var(--canvas); color: var(--ink); }
.admin-nav__link.is-active { background: var(--canvas); color: var(--ink); }
.admin-topbar__spacer { flex: 1; }
.admin-user { color: var(--muted); font-size: 13px; }
.admin-logout { display: inline; }
.admin-main { max-width: 1200px; margin: 0 auto; padding: 24px; }
.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.admin-card--wide { grid-column: 1 / -1; }
.admin-card__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.admin-card__title { font-size: 18px; }
.admin-card__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.stat-list { display: grid; gap: 8px; margin: 0; }
.stat-list > div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--hairline); }
.stat-list dt { color: var(--muted); font-size: 13px; }
.stat-list dd { margin: 0; font-weight: 500; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: start; color: var(--muted); font-weight: 500; padding: 10px 12px; border-bottom: 1px solid var(--hairline); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ------------------------------------------------------------------- meet */

.meet-body { min-height: 100vh; }
.screen { min-height: 100vh; }
.screen--center { display: grid; place-items: center; padding: 24px; }
.is-hidden { display: none !important; }

.empty-state { text-align: center; max-width: 440px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty-state__mark {
  display: grid; place-items: center; width: 64px; height: 64px;
  border-radius: 20px; background: var(--ink); color: var(--surface-alt); font-size: 28px;
}
.empty-state__title { font-size: 30px; }
.empty-state__text { color: var(--muted); }
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid var(--hairline); border-top-color: var(--ink);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* pre-join */
.screen--prejoin { display: grid; place-items: center; padding: 24px; }
.prejoin { display: grid; grid-template-columns: minmax(0, 1.3fr) 380px; gap: 24px; width: 100%; max-width: 1040px; }
.prejoin__preview { position: relative; background: var(--media-bg); border-radius: var(--radius-card); overflow: hidden; aspect-ratio: 16 / 9; }
.prejoin__video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.prejoin__avatar { position: absolute; inset: 0; display: grid; place-items: center; background: var(--media-surface); color: var(--surface-alt); font-size: 48px; }
.prejoin__preview-bar { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; gap: 12px; }
.prejoin__error { position: absolute; inset-inline: 16px; bottom: 16px; background: var(--destructive); color: #fff; padding: 10px 14px; border-radius: var(--radius-nested); font-size: 13px; }
.prejoin__title { font-size: 24px; margin-bottom: 6px; }
.prejoin__subtitle { color: var(--muted); margin: 0 0 18px; }
.prejoin__hint { color: var(--muted); font-size: 12px; margin-top: 10px; text-align: center; }

/* room */
.room { display: flex; flex-direction: column; height: 100vh; background: var(--media-bg); color: var(--surface-alt); }
.room-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--media-surface); border-bottom: 1px solid var(--media-hairline);
}
.room-topbar__left, .room-topbar__right { display: flex; align-items: center; gap: 8px; }
.room-topbar__center { display: flex; align-items: center; gap: 14px; }
.room .badge { background: var(--media-hairline); color: var(--surface-alt); }
.room .badge--outline { background: transparent; border-color: var(--media-hairline); color: #d4d4d4; }
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--destructive); animation: pulse 1.4s ease infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }
.conn-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #d4d4d4; }
.conn-status__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn-status[data-state='connected'] .conn-status__dot { background: #4ade80; }
.conn-status[data-state='reconnecting'] .conn-status__dot { background: #facc15; }
.conn-status[data-state='failed'] .conn-status__dot { background: var(--destructive); }
.net-quality { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #d4d4d4; }
.net-quality__bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.net-quality__bars i { width: 3px; background: #525252; border-radius: 1px; }
.net-quality__bars i:nth-child(1) { height: 5px; }
.net-quality__bars i:nth-child(2) { height: 8px; }
.net-quality__bars i:nth-child(3) { height: 12px; }
.net-quality[data-level='excellent'] .net-quality__bars i { background: #4ade80; }
.net-quality[data-level='good'] .net-quality__bars i { background: #facc15; }
.net-quality[data-level='poor'] .net-quality__bars i { background: var(--destructive); }

.room-body { flex: 1; display: flex; min-height: 0; position: relative; }
.stage { flex: 1; position: relative; min-width: 0; }
.stage__grid {
  display: grid; gap: 10px; padding: 14px; height: 100%;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  grid-auto-rows: minmax(150px, 1fr);
  align-content: center;
}
.tile {
  position: relative; background: var(--media-surface); border-radius: 16px; overflow: hidden;
  border: 2px solid transparent; cursor: pointer; min-height: 140px;
}
.tile.is-speaking { border-color: #4ade80; }
.tile__video { width: 100%; height: 100%; object-fit: cover; }
.tile--avatar .tile__video { visibility: hidden; }
.tile__avatar { position: absolute; inset: 0; display: grid; place-items: center; font-size: 40px; color: var(--surface-alt); background: var(--media-surface); }
.tile__overlay { position: absolute; inset-inline: 0; bottom: 0; display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; background: linear-gradient(to top, rgba(0,0,0,0.6), transparent); }
.tile__name { font-size: 12px; color: #fafafa; }
.tile__badges { display: flex; gap: 4px; font-size: 12px; }
.tile__badge { background: rgba(0,0,0,0.5); border-radius: 8px; padding: 1px 6px; }
.tile__badge--hand { background: #facc15; color: #422006; }

.stage__focus { position: absolute; inset: 0; background: #000; z-index: 5; }
.stage__focus-video { width: 100%; height: 100%; object-fit: contain; }
.stage__focus-label { position: absolute; top: 14px; inset-inline-start: 16px; background: rgba(0,0,0,0.6); padding: 6px 12px; border-radius: 10px; font-size: 13px; }
.stage__focus-close { position: absolute; top: 12px; inset-inline-end: 12px; width: 38px; height: 38px; border-radius: 12px; border: none; background: rgba(255,255,255,0.12); color: #fafafa; cursor: pointer; display: grid; place-items: center; }

/* board */
.stage__board { position: absolute; inset: 0; background: var(--paper); display: flex; flex-direction: column; z-index: 8; }
.board-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--hairline); background: var(--surface-alt); flex-wrap: wrap; }
.board-tools, .board-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tool {
  width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--hairline);
  background: var(--paper); color: var(--ink); cursor: pointer; display: grid; place-items: center; font-size: 16px;
}
.tool:hover { background: var(--canvas); }
.tool.is-active { background: var(--ink); color: var(--surface-alt); border-color: var(--ink); }
.tool__glyph { font-size: 16px; line-height: 1; }
.board-canvas-wrap { flex: 1; position: relative; overflow: hidden; background: var(--paper); }
.board-svg { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.wb-obj { pointer-events: none; }
.wb-obj.is-selected { filter: drop-shadow(0 0 0 var(--ink)); outline: none; }
.wb-obj.is-selected > * { stroke-dasharray: none; }
.board-ai-panel { position: absolute; top: 16px; inset-inline-end: 16px; width: 300px; background: var(--paper); border: 1px solid var(--hairline); border-radius: var(--radius-card); padding: 16px; box-shadow: var(--shadow-card); z-index: 10; }
.board-ai-panel__hint { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* waiting strip */
.waiting-strip { width: 280px; background: var(--media-surface); border-inline-start: 1px solid var(--media-hairline); padding: 14px; overflow-y: auto; }
.waiting-strip__title { font-size: 14px; color: #fafafa; display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.waiting-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.waiting-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; background: var(--paper); border: 1px solid var(--hairline); border-radius: 14px; }
.waiting-item__name { font-size: 13px; font-weight: 500; color: var(--ink); }
.waiting-item__actions { display: flex; gap: 6px; }

/* controls */
.room-controls {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; background: var(--media-surface); border-top: 1px solid var(--media-hairline);
  flex-wrap: wrap;
}
.ctrl-btn {
  display: inline-flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 62px; padding: 6px 8px; border-radius: 14px; border: none;
  background: transparent; color: #e5e5e5; cursor: pointer; font-size: 11px;
}
.ctrl-btn:hover { background: var(--media-hairline); }
.ctrl-btn.is-off { color: var(--destructive); }
.ctrl-btn.is-active { background: var(--ink); color: var(--surface-alt); }
.ctrl-btn--danger { color: #fca5a5; }
.ctrl-btn--danger:hover { background: var(--destructive); color: #fff; }
.ctrl-btn__label { font-size: 11px; }

/* drawers */
.drawer {
  position: absolute; top: 0; bottom: 0; inset-inline-end: 0; width: 340px; max-width: 90vw;
  background: var(--paper); border-inline-start: 1px solid var(--hairline);
  display: flex; flex-direction: column; z-index: 15; box-shadow: var(--shadow-card);
}
.drawer__header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--hairline); }
.drawer__title { font-size: 15px; }
.drawer__body { flex: 1; overflow-y: auto; padding: 14px 16px; }
.drawer__footer { padding: 12px 16px; border-top: 1px solid var(--hairline); }
.drawer__actions { display: flex; flex-direction: column; gap: 10px; }

.participant-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.participant-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 14px; }
.participant-item:hover { background: var(--canvas); }
.participant-item__avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--ink); color: var(--surface-alt); font-size: 14px; }
.participant-item__meta { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.participant-item__name { font-size: 13px; font-weight: 500; }
.participant-item__status { font-size: 11px; color: var(--muted); }
.participant-item__actions { display: flex; gap: 2px; }

.chat-body { display: flex; flex-direction: column; gap: 10px; }
.chat-form { display: flex; gap: 8px; }
.chat-message { display: flex; flex-direction: column; gap: 3px; max-width: 92%; }
.chat-message--self { align-self: flex-end; align-items: flex-end; }
.chat-message__header { display: flex; gap: 8px; align-items: baseline; }
.chat-message__name { font-size: 12px; font-weight: 600; }
.chat-message__time { font-size: 11px; color: var(--muted); }
.chat-message__text { background: var(--canvas); padding: 8px 12px; border-radius: 14px; font-size: 13px; word-break: break-word; }
.chat-message--self .chat-message__text { background: var(--ink); color: var(--surface-alt); }

.modal { position: fixed; inset: 0; background: rgba(10,10,10,0.5); display: grid; place-items: center; z-index: 40; padding: 24px; }
.modal__card { width: 100%; max-width: 400px; }
.modal__title { font-size: 18px; margin-bottom: 8px; }
.modal__text { color: var(--muted); margin: 0 0 18px; }
.modal__actions { display: flex; justify-content: flex-end; gap: 10px; }

/* toasts */
.toast-root { position: fixed; bottom: 20px; inset-inline-start: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 60; }
.toast {
  display: flex; align-items: center; gap: 12px; min-width: 240px; max-width: 360px;
  padding: 12px 14px; border-radius: 14px; background: var(--ink); color: var(--surface-alt);
  box-shadow: var(--shadow-card); opacity: 0; transform: translateY(10px); transition: all 160ms ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast--error { background: var(--destructive); }
.toast--warn { background: #b45309; }
.toast--success { background: #065f46; }
.toast__text { flex: 1; font-size: 13px; }
.toast__close { background: none; border: none; color: inherit; font-size: 18px; cursor: pointer; }

/* recording page */
.recording-card { max-width: 900px; margin: 0 auto; }
.recording-card__header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.recording-card__title { font-size: 22px; }
.recording-card__meta { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.recording-player { background: #000; border-radius: var(--radius-card); overflow: hidden; }
.recording-video { width: 100%; display: block; max-height: 70vh; }
.recording-card__actions { display: flex; gap: 10px; margin-top: 16px; }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .admin-grid { grid-template-columns: 1fr; }
  .prejoin { grid-template-columns: 1fr; }
  .waiting-strip { position: absolute; inset-inline: 0; top: 0; bottom: 0; width: auto; z-index: 12; }
  .drawer { width: 100%; }
}

@media (max-width: 640px) {
  .room-controls { gap: 2px; padding: 8px; }
  .ctrl-btn { min-width: 52px; }
  .stage__grid { grid-template-columns: 1fr; }
  .board-ai-panel { inset-inline: 12px; width: auto; }
  .admin-main { padding: 14px; }
}
