/* ===========================================================================
   Reseller portal
   ---------------------------------------------------------------------------
   Every rule is scoped to a class. The first version of this file styled
   `main` directly for the app shell, and that rule also matched the sign-in
   page's <main class="sign-in-card"> — `flex: 1` sets flex-basis: 0, which
   beats a width of 380px, so the sign-in card rendered the full width of the
   screen. A bare element selector is a rule with no idea which page it is on.

   Right-to-left comes from logical properties (inline-start/end, margin-inline)
   rather than left/right, so the same stylesheet lays out Arabic and English.
   =========================================================================== */

:root {
  /* Brand ----------------------------------------------------------------- */
  --brand-50:  #eff6ff;
  --brand-100: #dbeafe;
  --brand-200: #bfdbfe;
  --brand-500: #3b82f6;
  --brand-600: #2563eb;
  --brand-700: #1d4ed8;
  --brand-900: #1e3a8a;

  /* Neutrals -------------------------------------------------------------- */
  --canvas:    #f6f8fb;
  --surface:   #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f3f4f6;
  --border:    #e5e7eb;
  --border-2:  #d1d5db;
  --text:      #111827;
  --text-2:    #4b5563;
  --text-3:    #9ca3af;

  /* Status ---------------------------------------------------------------- */
  --ok-bg:   #ecfdf5;  --ok-fg:   #047857;  --ok-dot:   #10b981;
  --warn-bg: #fffbeb;  --warn-fg: #b45309;
  --info-bg: #eef2ff;  --info-fg: #4338ca;
  --danger:  #dc2626;  --danger-bg: #fef2f2;

  /* Shape and depth -------------------------------------------------------- */
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --ring: 0 0 0 3px var(--brand-100);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 1px 3px rgba(16, 24, 40, .08), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-lg: 0 10px 20px rgba(16, 24, 40, .08), 0 24px 48px rgba(16, 24, 40, .10);

  /* Type ------------------------------------------------------------------- */
  --font: 'Alexandria', 'Segoe UI', Tahoma, system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'JetBrains Mono', Menlo, monospace;

  --sidebar-w: 264px;
  --inbox-w: 340px;
  --header-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas:    #0b1220;
    --surface:   #111827;
    --surface-2: #161f2e;
    --surface-3: #1f2937;
    --border:    #263244;
    --border-2:  #334155;
    --text:      #e5e7eb;
    --text-2:    #9aa6b8;
    --text-3:    #6b7a90;
    --brand-50:  #15233c;
    --brand-100: #1b2d4d;
    --ok-bg:   #0d2b22;  --ok-fg:   #34d399;
    --warn-bg: #2b2210;  --warn-fg: #fbbf24;
    --info-bg: #1b2142;  --info-fg: #a5b4fc;
    --danger-bg: #2c1416;
    --ring: 0 0 0 3px var(--brand-100);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, .5);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; }
p { margin: 0; }

.is-hidden { display: none !important; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.spacer { flex: 1 1 auto; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

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

:where(button, input, select, textarea):focus-visible {
  outline: 2px solid var(--brand-600);
  outline-offset: 2px;
}

/* Scrollbars ---------------------------------------------------------------- */
.scroll { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; overflow-y: auto; }
.scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll::-webkit-scrollbar-thumb {
  background: var(--border-2); border-radius: 999px;
  border: 2px solid transparent; background-clip: padding-box;
}
.scroll::-webkit-scrollbar-track { background: transparent; }

/* ===========================================================  controls  === */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; min-height: 38px;
  font-family: inherit; font-size: 13.5px; font-weight: 500; line-height: 1;
  border-radius: var(--r-md); border: 1px solid transparent;
  cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }

.btn-primary { background: var(--brand-600); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--brand-700); }

.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-2); }

.btn-quiet { background: transparent; color: var(--text-2); }
.btn-quiet:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); border-color: var(--danger); }

.btn-icon { padding: 0; width: 38px; min-height: 38px; }
.btn-block { width: 100%; }
.btn-lg { min-height: 46px; font-size: 15px; border-radius: var(--r-md); }

.field { display: block; margin-block-end: 16px; }
.field-label {
  display: block; margin-block-end: 6px;
  font-size: 13px; font-weight: 500; color: var(--text-2);
}
.field-hint { margin-block-start: 6px; font-size: 12.5px; color: var(--text-3); }

.input {
  display: block; width: 100%;
  /* 16px on touch screens: anything smaller makes iOS Safari zoom the page
     the moment the field is focused, and it never zooms back out. */
  padding: 10px 13px; font-family: inherit; font-size: 16px; line-height: 1.5;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-2); border-radius: var(--r-md);
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; border-color: var(--brand-500); box-shadow: var(--ring); }
.input:disabled { background: var(--surface-3); color: var(--text-3); }
textarea.input { resize: vertical; min-height: 44px; }
select.input { cursor: pointer; }

@media (min-width: 768px) { .input { font-size: 14px; } }

.form-error {
  display: flex; gap: 8px; align-items: flex-start;
  margin-block-start: 14px; padding: 10px 12px;
  font-size: 13px; color: var(--danger);
  background: var(--danger-bg); border: 1px solid currentColor; border-radius: var(--r-md);
}

/* =============================================================  badges  === */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 500; line-height: 1.7;
  background: var(--surface-3); color: var(--text-2);
}
.badge-ok      { background: var(--ok-bg);   color: var(--ok-fg); }
.badge-info    { background: var(--info-bg); color: var(--info-fg); }
.badge-warn    { background: var(--warn-bg); color: var(--warn-fg); }
.badge-count   { background: var(--brand-600); color: #fff; font-variant-numeric: tabular-nums; }
.badge-dot::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex: none;
}

.avatar {
  display: grid; place-items: center; flex: none;
  width: 38px; height: 38px; border-radius: 50%;
  font-size: 14px; font-weight: 600; line-height: 1;
  color: var(--brand-700); background: var(--brand-50);
  user-select: none;
}
.avatar-sm { width: 30px; height: 30px; font-size: 12px; }

/* ============================================================  sign in  === */

.signin-page {
  display: grid; place-items: center; padding: 24px;
  min-height: 100dvh;
  background:
    radial-gradient(1100px 520px at 85% -10%, var(--brand-100), transparent 60%),
    radial-gradient(900px 480px at 0% 110%, var(--brand-50), transparent 55%),
    var(--canvas);
}
.signin-card {
  width: 100%; max-width: 408px;
  padding: 36px 32px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
}
.signin-mark {
  display: grid; place-items: center;
  width: 52px; height: 52px; margin-block-end: 20px;
  border-radius: var(--r-lg);
  color: #fff; background: linear-gradient(140deg, var(--brand-500), var(--brand-700));
  box-shadow: var(--shadow-md);
}
.signin-mark svg { width: 26px; height: 26px; }
.signin-title { font-size: 21px; font-weight: 600; }
.signin-sub { margin-block: 6px 26px; font-size: 14px; color: var(--text-2); }
.signin-foot {
  margin-block-start: 22px; padding-block-start: 18px;
  border-block-start: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-3); text-align: center;
}

/* ==========================================================  app shell  === */

.app-page {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  padding: 18px 14px;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 11px;
  padding: 4px 8px 20px;
}
.sidebar-mark {
  display: grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: var(--r-md);
  color: #fff; background: linear-gradient(140deg, var(--brand-500), var(--brand-700));
}
.sidebar-mark svg { width: 19px; height: 19px; }
.sidebar-name { font-size: 14.5px; font-weight: 600; line-height: 1.25; }
.sidebar-role { font-size: 11.5px; color: var(--text-3); }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; width: 100%;
  font-family: inherit; font-size: 14px; font-weight: 500; text-align: start;
  color: var(--text-2); background: transparent;
  border: 0; border-radius: var(--r-md); cursor: pointer;
  transition: background-color .15s, color .15s;
}
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }
.nav-label { flex: 1 1 auto; }

.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  margin-block-start: auto; padding: 12px 8px 4px;
  border-block-start: 1px solid var(--border);
}
.sidebar-user-text { min-width: 0; }
.sidebar-user-name {
  font-size: 13.5px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-user-role { font-size: 11.5px; color: var(--text-3); }

.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.workspace-head {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--header-h); padding: 12px 22px;
  background: var(--surface); border-block-end: 1px solid var(--border);
}
.workspace-title { font-size: 16px; font-weight: 600; }
.workspace-sub { font-size: 12.5px; color: var(--text-3); }
.workspace-body { flex: 1 1 auto; min-height: 0; }
.workspace-head .avatar { display: none; }

.bottom-nav { display: none; }

/* ==============================================================  chats  === */

.chats { display: grid; grid-template-columns: var(--inbox-w) 1fr; height: 100%; min-height: 0; }

.inbox {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-inline-end: 1px solid var(--border);
}
.inbox-filters { display: flex; flex-direction: column; gap: 9px; padding: 14px; }
.inbox-list { flex: 1 1 auto; min-height: 0; margin: 0; padding: 0 8px 12px; list-style: none; }

.conv {
  display: flex; gap: 11px; align-items: flex-start;
  width: 100%; padding: 11px 12px; margin-block-end: 2px;
  text-align: start; background: transparent;
  border: 0; border-radius: var(--r-md); cursor: pointer;
  transition: background-color .12s;
}
.conv:hover { background: var(--surface-3); }
.conv[aria-selected="true"] { background: var(--brand-50); }
.conv-body { min-width: 0; flex: 1 1 auto; }
.conv-top { display: flex; align-items: center; gap: 8px; }
.conv-name {
  font-size: 13.5px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-time { margin-inline-start: auto; font-size: 11px; color: var(--text-3); flex: none; }
.conv-last {
  margin-block-start: 2px; font-size: 12.5px; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-meta { display: flex; align-items: center; gap: 6px; margin-block-start: 5px; }

.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--canvas); }
.thread-head {
  display: flex; align-items: center; gap: 11px; flex-wrap: wrap;
  padding: 12px 20px; min-height: var(--header-h);
  background: var(--surface); border-block-end: 1px solid var(--border);
}
.thread-who { min-width: 0; }
.thread-name { font-size: 14.5px; font-weight: 600; }
.thread-sub { font-size: 12px; color: var(--text-3); }
.thread-back { display: none; }

.messages {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; gap: 14px;
  padding: 22px 20px;
}
.msg { max-width: min(640px, 76%); align-self: flex-start; }
.msg-out { align-self: flex-end; }
.msg-who { margin-block-end: 4px; font-size: 11.5px; font-weight: 500; color: var(--text-2); }
.msg-bubble {
  padding: 10px 14px; border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-out .msg-bubble { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.msg-out .msg-bubble a { color: #fff; text-decoration: underline; }
.msg-cont { margin-block-start: -8px; }
.msg-time { margin-block-start: 4px; font-size: 11px; color: var(--text-3); }
.msg-out .msg-time { text-align: end; }

.composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 14px 20px;
  background: var(--surface); border-block-start: 1px solid var(--border);
}
.composer .input { flex: 1 1 auto; }

.empty {
  display: grid; place-items: center; gap: 10px;
  height: 100%; padding: 40px 24px; text-align: center; color: var(--text-3);
}
.empty svg { width: 36px; height: 36px; opacity: .55; }
.empty-title { font-size: 14.5px; font-weight: 500; color: var(--text-2); }
.empty-note { font-size: 13px; }

/* ======================================================  cards (pages)  === */

.page { height: 100%; padding: 22px; }
.page-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-block-end: 18px;
}
.page-title { font-size: 17px; font-weight: 600; }

.card {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  margin-block-end: 14px;
}
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card-title { font-size: 15px; font-weight: 600; }
.card-rows { display: grid; gap: 8px; margin-block-start: 14px; }
.row { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; font-size: 13px; }
.row-key { flex: none; min-width: 92px; color: var(--text-3); }
.row-val { color: var(--text-2); overflow-wrap: anywhere; }
.card-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-block-start: 16px; padding-block-start: 14px;
  border-block-start: 1px solid var(--border);
}

.snippet {
  position: relative;
  margin-block-start: 14px; padding: 13px 15px;
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.7;
  color: #e2e8f0; background: #0f172a;
  border-radius: var(--r-md);
  direction: ltr; text-align: start;
  overflow-x: auto; white-space: pre;
}

/* ===========================================================  overlays  === */

.sheet {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center; padding: 20px;
  background: rgba(15, 23, 42, .5);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.sheet-card {
  width: 100%; max-width: 440px; max-height: min(88dvh, 760px);
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.sheet-head {
  padding: 20px 22px 14px;
  border-block-end: 1px solid var(--border);
}
.sheet-title { font-size: 16px; font-weight: 600; }
.sheet-body { padding: 20px 22px; overflow-y: auto; }
.sheet-foot {
  display: flex; gap: 9px; justify-content: flex-end;
  padding: 14px 22px; background: var(--surface-2);
  border-block-start: 1px solid var(--border);
}
.sheet-choice {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 11px 13px; margin-block-end: 7px;
  font-family: inherit; font-size: 14px; text-align: start;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-md); cursor: pointer;
  transition: background-color .15s, border-color .15s;
}
.sheet-choice:hover:not(:disabled) { background: var(--brand-50); border-color: var(--brand-200); }
.sheet-choice:disabled { opacity: .55; cursor: wait; }

.toast {
  position: fixed; z-index: 80;
  inset-block-end: 24px; inset-inline-start: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 9px;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  font-size: 13.5px; color: #fff; background: #111827;
  border-radius: 999px; box-shadow: var(--shadow-lg);
}
.toast-bad { background: var(--danger); }

/* =========================================================  responsive  === */

@media (max-width: 1100px) {
  :root { --sidebar-w: 212px; --inbox-w: 290px; }
}

@media (max-width: 900px) {
  :root { --header-h: 56px; }

  /* The sidebar becomes a bottom bar: three destinations is exactly what a
     bottom bar is for, and a drawer would hide the only navigation there is
     behind a tap. */
  .app-page { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .sidebar { display: none; }

  .bottom-nav {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-block-start: 1px solid var(--border);
  }
  .bottom-nav .nav-item {
    flex-direction: column; gap: 3px; padding: 7px 4px;
    font-size: 11px; font-weight: 500; text-align: center;
  }
  .bottom-nav .nav-item svg { width: 20px; height: 20px; }
  .bottom-nav .nav-item[aria-current="page"] { background: transparent; color: var(--brand-600); }

  .workspace-head { padding: 10px 14px; }
  .workspace-head .avatar { display: grid; }
  /* Reading a thread on a phone, the page header says "Chats, 4 of them"
     directly above a header naming the one chat on screen. The second is the
     useful one, and the room is worth more than the repetition. */
  body.is-viewing-thread .workspace-head { display: none; }
  .page { padding: 14px; }

  /* One pane at a time. A list squeezed above a thread gives too little of
     either to use, so the thread replaces the list and a back arrow returns. */
  .chats { grid-template-columns: 1fr; }
  .chats .thread { display: none; }
  .chats .inbox { border-inline-end: 0; }
  body.is-viewing-thread .chats .inbox { display: none; }
  body.is-viewing-thread .chats .thread { display: flex; }
  .thread-back { display: inline-flex; }

  .messages { padding: 16px 14px; gap: 12px; }
  .msg { max-width: 86%; }
  .composer { padding: 10px 14px; }
  .thread-head { padding: 10px 14px; }
  .card-actions .btn { flex: 1 1 auto; }
}

@media (max-width: 480px) {
  .signin-card { padding: 28px 22px 24px; border-radius: var(--r-lg); }
  .row-key { min-width: 100%; }
  .toast { inset-block-end: calc(76px + env(safe-area-inset-bottom)); }
}

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