/* ============================================================================
   Unified Inbox — design tokens + base system
   Modern dark-first premium (Linear/Vercel-like). Plain CSS, no build step.
   Phase 4 owns this file; later phases add component styles, not new tokens.
   ========================================================================== */

:root {
  color-scheme: dark;

  /* Surfaces & text */
  --color-bg:          #0A0A0F;
  --color-surface:     #15151B;
  --color-surface-2:   #1E1E26;
  --color-border:      #2A2A35;
  --color-text:        #FFFFFF;
  --color-text-muted:  #A1A1AA;
  --color-text-subtle: #71717A;

  /* Accents & brand */
  --color-accent-blue:   #3B82F6;
  --color-accent-violet: #8B5CF6;
  --gradient-brand: linear-gradient(135deg, #3B82F6, #8B5CF6);

  /* Status */
  --color-success: #22C55E;
  --color-warning: #EAB308;
  --color-danger:  #EF4444;

  /* Channel badges */
  --color-whatsapp: #25D366;

  /* Shape & motion */
  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);

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

  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sidebar-w: 260px;
}

/* ── Reset / base ──────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { font-weight: 600; line-height: 1.25; margin: 0 0 var(--space-3); }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.1rem; }

.muted   { color: var(--color-text-muted); }
.subtle  { color: var(--color-text-subtle); }
.small   { font-size: .85rem; }

/* ── Brand logo placeholder ────────────────────────────────────────── */
/* Real Rosen AI wordmark (white variant, for these dark surfaces) — shown in
   the inbox sidebar and on the /login page, so the unified login, inbox and
   portal all carry the same brand. */
.brand-logo {
  width: 124px; height: 30px;
  background: url(/static/img/rai-white.png) left center / contain no-repeat;
  flex: 0 0 auto;
}
.brand-logo.lg { width: 200px; height: 52px; }

/* ── Buttons ───────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: .6rem .9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text);
  font: inherit; font-weight: 600; font-size: .92rem;
  cursor: pointer;
  transition: filter .12s ease, background .12s ease, border-color .12s ease;
}
.btn:hover { filter: brightness(1.1); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--color-accent-blue); outline-offset: 2px; }

.btn-primary { background: var(--gradient-brand); border-color: transparent; }
.btn-danger  { background: var(--color-danger); border-color: transparent; }
.btn-ghost   { background: transparent; }
.btn-block   { width: 100%; }

/* ── Forms ─────────────────────────────────────────────────────────── */

label { display: block; font-size: .8rem; color: var(--color-text-muted); margin: var(--space-4) 0 var(--space-1); }
.field { margin-bottom: var(--space-2); }

input, textarea, select {
  width: 100%;
  padding: .6rem .7rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text);
  font: inherit; font-size: .95rem;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--color-accent-blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.25);
}
textarea { resize: vertical; }

/* Password field with a show/hide eye toggle (templates/accounts/login.html). */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 2.4rem; }
.pw-toggle {
  position: absolute; top: 50%; right: .35rem; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  width: 1.9rem; height: 1.9rem; padding: 0;
  background: transparent; border: none; border-radius: var(--radius-sm);
  color: var(--color-text-muted); cursor: pointer;
}
.pw-toggle:hover, .pw-toggle:focus-visible { color: var(--color-text); }

/* ── Inline form help (CSS-only tooltip) ───────────────────────────── */
/* A "?" badge next to a field label; reveals its tooltip on hover or keyboard
   focus. No JS. Used via the help_icon() macro in templates/_macros/. */

.help-icon {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin-left: 4px;
  vertical-align: middle;
  border-radius: 999px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  color: var(--color-text-subtle);
  cursor: help;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.help-icon:hover,
.help-icon:focus-visible {
  background: var(--gradient-brand);
  border-color: transparent;
  color: #fff;
  outline: none;
}
.help-icon-mark { font-size: .7rem; font-weight: 700; line-height: 1; }

.help-tooltip {
  position: absolute; bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  width: max-content; max-width: 240px;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: .78rem; font-weight: 400; line-height: 1.4;
  text-align: left; white-space: normal;
  opacity: 0; visibility: hidden;
  transition: opacity .12s ease, visibility .12s ease;
  pointer-events: none;
}
/* Little arrow under the bubble. */
.help-tooltip::after {
  content: ""; position: absolute; top: 100%; left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--color-border);
}
.help-icon:hover .help-tooltip,
.help-icon:focus-visible .help-tooltip,
.help-icon:focus-within .help-tooltip {
  opacity: 1; visibility: visible;
}

/* On narrow screens, anchor to the left edge so the bubble never overflows. */
@media (max-width: 480px) {
  .help-tooltip { left: 0; transform: none; max-width: 200px; }
  .help-tooltip::after { left: 8px; transform: none; }
}

/* ── Cards & alerts ────────────────────────────────────────────────── */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow);
}

.alert { padding: .6rem .7rem; border-radius: var(--radius-sm); font-size: .85rem; margin-bottom: var(--space-3); border: 1px solid; }
.alert-error   { background: rgba(239,68,68,.12);  border-color: var(--color-danger);  color: #FCA5A5; }
.alert-success { background: rgba(34,197,94,.12);  border-color: var(--color-success); color: #86EFAC; }
.alert-info    { background: rgba(59,130,246,.12); border-color: var(--color-accent-blue); color: #93C5FD; }

/* ── Badges ────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: .72rem; font-weight: 600; line-height: 1.6;
  background: var(--color-surface-2); color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.badge-wa      { background: rgba(37,211,102,.15); color: var(--color-whatsapp); border-color: transparent; }
.badge-ig      { background: rgba(225,48,108,.15); color: #E1306C; border-color: transparent; }
.badge-fb      { background: rgba(24,119,242,.15); color: #1877F2; border-color: transparent; }
.badge-tg      { background: rgba(34,158,217,.15); color: #229ED9; border-color: transparent; }
.badge-voice   { background: rgba(139,92,246,.15); color: #8B5CF6; border-color: transparent; }
.badge .ch-logo { width: 14px; height: 14px; border-radius: 3px; object-fit: contain; display: inline-block; }
.badge-warning { background: rgba(234,179,8,.15);  color: var(--color-warning);  border-color: transparent; }
.badge-danger  { background: rgba(239,68,68,.15);  color: var(--color-danger);   border-color: transparent; }
.badge-success { background: rgba(34,197,94,.15);  color: var(--color-success);  border-color: transparent; }

/* ── Flash messages (shared app layout) ────────────────────────────── */

.flash-stack { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3) var(--space-4) 0; }

/* ── Auth layout ───────────────────────────────────────────────────── */

.auth-body { display: grid; place-items: center; min-height: 100vh; padding: var(--space-4); }
.auth-wrap { width: 100%; max-width: 400px; display: flex; flex-direction: column; align-items: center; gap: var(--space-4); }
.auth-brand { display: flex; justify-content: center; }
.auth-card { width: 100%; }
.auth-foot { font-size: .8rem; }
.links { margin-top: var(--space-4); font-size: .85rem; display: flex; justify-content: space-between; gap: var(--space-3); }

/* ── App shell (authenticated) ─────────────────────────────────────── */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex; flex-direction: column;
  padding: var(--space-4);
}
.sidebar-brand { display: flex; align-items: center; gap: var(--space-3); padding-bottom: var(--space-4); margin-bottom: var(--space-2); border-bottom: 1px solid var(--color-border); }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; }
.sidebar-foot { border-top: 1px solid var(--color-border); padding-top: var(--space-3); margin-top: var(--space-3); }

.nav-item { display: block; padding: .5rem .6rem; border-radius: var(--radius-sm); color: var(--color-text-muted); font-weight: 500; }
.nav-item:hover { background: var(--color-surface-2); color: var(--color-text); text-decoration: none; }
.nav-item.is-active { background: var(--color-surface-2); color: var(--color-text); }

.app-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

/* ── Responsive ────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex-basis: auto;
    flex-direction: row; align-items: center;
    border-right: 0; border-bottom: 1px solid var(--color-border);
    overflow-x: auto; padding: var(--space-3);
  }
  .sidebar-brand { border-bottom: 0; padding-bottom: 0; margin-bottom: 0; margin-right: var(--space-3); }
  .sidebar-nav { flex-direction: row; flex: 1 1 auto; }
  .sidebar-foot { border-top: 0; margin: 0 0 0 auto; padding: 0; }
}

/* ── Accessibility ─────────────────────────────────────────────────── */

/* Skip link: visually hidden until focused, then pinned top-left. */
.skip-link {
  position: absolute; left: var(--space-2); top: -100%;
  z-index: 1000;
  padding: .5rem .8rem;
  background: var(--color-surface-2); color: var(--color-text);
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
}
.skip-link:focus { top: var(--space-2); }

.nav-item:focus-visible,
a:focus-visible {
  outline: 2px solid var(--color-accent-blue); outline-offset: 2px;
}
#main-content:focus { outline: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
