/* Mahtab design system.
   A familiar, Telegram-shaped messenger. Operate surface: the interface should
   be instantly understood, so the system is restrained — soft-neutral surfaces,
   one blue accent, hairline separators, circular avatars, small radii.
   Light is the default theme; dark mirrors it exactly. */

/* --- Self-hosted font (dual-script: Persian + Latin) --- */
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/static/fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ==========================================================================
   Light theme (default)
   ========================================================================== */
:root {
  color-scheme: light;

  /* Surfaces */
  --bg-0: #ffffff;            /* main chat / panels */
  --bg-1: #ffffff;            /* sidebar + content panels */
  --bg-2: #f4f4f5;            /* inputs, hover fills */
  --bg-3: #ebebed;            /* pressed / track */
  --bg-4: #e0e0e3;            /* stronger track, avatar fallback */
  --surface-rail: #ffffff;    /* conversation list background */
  --surface-header: #ffffff;
  --surface-wallpaper: #e9ebe5; /* chat background field */
  --surface-hover: #f2f2f3;
  --surface-active: #e8effa;  /* selected conversation row */

  /* Separators */
  --line-1: rgba(0, 0, 0, 0.08);
  --line-2: rgba(0, 0, 0, 0.13);
  --line-3: rgba(0, 0, 0, 0.2);

  /* Ink */
  --ink-1: #0f1419;   /* primary text */
  --ink-2: #3f4750;   /* secondary text */
  --ink-3: #5f6874;   /* muted / timestamps */
  --ink-4: #68717e;   /* placeholder, faint */

  /* Blue accent (Telegram-family restraint, not its brand mark) */
  --accent: #2f7ce0;
  --accent-strong: #1f6fd6;
  --accent-soft: rgba(47, 124, 224, 0.12);
  --accent-line: rgba(47, 124, 224, 0.4);
  --accent-ink: #0f2f5c;
  --accent-contrast: #ffffff;
  /* A deeper blue for a fully selected row, so white text clears AA. */
  --accent-selected: #2b6fca;

  /* Message bubbles */
  --bubble-out: #e1f0ff;
  --bubble-out-2: #d8ecff;
  --bubble-in: #ffffff;
  --bubble-in-line: var(--line-1);
  --bubble-meta: #7a8b99;
  --msg-link: #2f7ce0;

  /* State colors */
  --ok: #34a853;
  --ok-soft: rgba(52, 168, 83, 0.14);
  --warn: #d98a0b;
  --warn-soft: rgba(217, 138, 11, 0.14);
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.12);

  /* Geometry */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-bubble: 14px;
  --radius-pill: 999px;

  /* Shadows — restrained, offset, soft */
  --shadow-1: 0 1px 2px rgba(16, 23, 32, 0.08);
  --shadow-2: 0 4px 14px rgba(16, 23, 32, 0.1);
  --shadow-lift: 0 12px 36px rgba(16, 23, 32, 0.16);
  --shadow-menu: 0 8px 28px rgba(16, 23, 32, 0.18);

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --rail-w: 360px;

  /* Motion — short and calm */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --dur-fast: 120ms;
  --dur-1: 150ms;
  --dur-2: 220ms;
  --dur-3: 300ms;

  --font: "Vazirmatn", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ==========================================================================
   Dark theme
   ========================================================================== */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg-0: #17212b;
  --bg-1: #17212b;
  --bg-2: #232e3a;
  --bg-3: #2b3846;
  --bg-4: #35424f;
  --surface-rail: #17212b;
  --surface-header: #17212b;
  --surface-wallpaper: #0f1821;
  --surface-hover: #202b36;
  --surface-active: #2b3a4c;

  --line-1: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.13);
  --line-3: rgba(255, 255, 255, 0.22);

  --ink-1: #f1f4f7;
  --ink-2: #c3ccd6;
  --ink-3: #8a97a5;
  --ink-4: #6b7784;

  --accent: #5aa0f0;
  --accent-strong: #7ab3f5;
  --accent-soft: rgba(90, 160, 240, 0.16);
  --accent-line: rgba(90, 160, 240, 0.45);
  --accent-ink: #bcd9ff;
  --accent-contrast: #0b1826;
  --accent-selected: #2f5f96;

  --bubble-out: #2b5278;
  --bubble-out-2: #2b5278;
  --bubble-in: #212d3a;
  --bubble-in-line: transparent;
  --bubble-meta: #93a1ad;
  --msg-link: #7ab3f5;

  --ok: #4bd07a;
  --ok-soft: rgba(75, 208, 122, 0.16);
  --warn: #f0b45f;
  --warn-soft: rgba(240, 180, 95, 0.16);
  --danger: #f0737d;
  --danger-soft: rgba(240, 115, 125, 0.16);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-2: 0 4px 14px rgba(0, 0, 0, 0.36);
  --shadow-lift: 0 12px 36px rgba(0, 0, 0, 0.5);
  --shadow-menu: 0 8px 28px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

/* Smooth theme swap: fade the surface while tokens change, then release. */
html.theme-anim,
html.theme-anim body {
  transition: background-color var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
}
html.theme-anim .rail,
html.theme-anim .thread,
html.theme-anim .thread__head,
html.theme-anim .composer,
html.theme-anim .conv,
html.theme-anim .modal,
html.theme-anim .menu {
  transition: background-color var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease),
    color var(--dur-2) var(--ease);
}

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

body {
  font-family: var(--font);
  background: var(--bg-0);
  color: var(--ink-1);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  transition: background var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* Authored icon system: one stroke, one weight, currentColor. */
.icon {
  width: 22px;
  height: 22px;
  display: inline-block;
  flex: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
.icon-sm { width: 18px; height: 18px; }
.icon-lg { width: 26px; height: 26px; }
.icon-xs { width: 15px; height: 15px; }

/* Browser surfaces themed from the palette. */
::selection { background: var(--accent-soft); color: var(--ink-1); }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
* { scrollbar-width: thin; scrollbar-color: var(--bg-4) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--bg-4);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--line-3); background-clip: content-box; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: var(--ink-1);
  background: var(--bg-2);
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease),
    transform var(--dur-fast) var(--ease), opacity var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--bg-3); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary {
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  box-shadow: var(--shadow-1);
}
.btn--primary:hover { background: var(--accent-strong); }
.btn--ghost { background: transparent; border-color: var(--line-2); }
.btn--ghost:hover { background: var(--bg-2); border-color: var(--line-3); }
.btn--danger { background: var(--danger-soft); color: var(--danger); }
.btn--danger:hover { background: color-mix(in srgb, var(--danger) 22%, transparent); }
.btn--icon {
  padding: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink-2);
}
.btn--icon:hover { background: var(--surface-hover); color: var(--ink-1); }
.btn--sm { padding: 6px 11px; font-size: 13px; }
.btn--sm.btn--icon { width: 34px; height: 34px; }

/* --- Inputs --- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.input, .textarea, .select {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  color: var(--ink-1);
  padding: 10px 13px;
  font-size: 14.5px;
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-4); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-1);
}
.textarea { resize: none; }
.field-hint { font-size: 12.5px; color: var(--ink-3); }
.field-error { font-size: 12.5px; color: var(--danger); }

/* --- Utility --- */
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.strong { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack { display: flex; flex-direction: column; }
.hidden { display: none !important; }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-3);
  color: var(--ink-2);
  border: 1px solid transparent;
}
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--accent { background: var(--accent-soft); color: var(--accent); }

/* --- Avatars --- */
.avatar {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 17px;
  flex: none;
  overflow: hidden;
  position: relative;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--sm { width: 36px; height: 36px; font-size: 14px; }
.avatar--lg { width: 80px; height: 80px; font-size: 30px; }
.avatar--xs { width: 30px; height: 30px; font-size: 12px; }

.presence-dot {
  position: absolute;
  bottom: 0;
  inset-inline-end: 0;
  width: 13px;
  height: 13px;
  border-radius: var(--radius-pill);
  background: var(--ink-4);
  border: 2.5px solid var(--surface-rail);
  transition: background var(--dur-2) var(--ease);
}
.presence-dot.is-online { background: var(--ok); }

/* --- Skeletons --- */
.skel {
  background: linear-gradient(90deg, var(--bg-2) 25%, var(--bg-3) 50%, var(--bg-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s var(--ease) infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* --- Empty states --- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  text-align: center;
  padding: var(--space-7) var(--space-5);
  color: var(--ink-3);
  height: 100%;
  animation: emptyIn var(--dur-3) var(--ease);
}
@keyframes emptyIn { from { opacity: 0; transform: translateY(6px); } }
.empty__art {
  width: 68px;
  height: 68px;
  border-radius: var(--radius-pill);
  display: grid;
  place-items: center;
  background: var(--bg-2);
  color: var(--ink-4);
}
.empty h3 { color: var(--ink-1); font-size: 16px; font-weight: 600; }
.empty p { max-width: 34ch; font-size: 13.5px; }

/* --- Reduced motion: keep feedback, remove spatial movement --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .skel { animation: none; background: var(--bg-2); }
}
