/* OmniInbox — design tokens & base */

:root {
  /* Neutrals (warm) */
  --bg: oklch(0.99 0.003 90);
  --surface: #ffffff;
  --surface-2: oklch(0.975 0.004 90);
  --surface-3: oklch(0.955 0.005 90);
  --border: oklch(0.92 0.005 90);
  --border-strong: oklch(0.86 0.006 90);
  --text: oklch(0.22 0.01 90);
  --text-muted: oklch(0.5 0.008 90);
  --text-subtle: oklch(0.65 0.008 90);

  /* Brand */
  --accent: oklch(0.5 0.15 162);
  --accent-hover: oklch(0.45 0.16 162);
  --accent-soft: oklch(0.95 0.04 162);
  --accent-soft-2: oklch(0.92 0.06 162);
  --accent-ink: oklch(0.32 0.12 162);

  /* AI */
  --ai: oklch(0.55 0.18 295);
  --ai-hover: oklch(0.5 0.19 295);
  --ai-soft: oklch(0.96 0.03 295);
  --ai-soft-2: oklch(0.92 0.06 295);
  --ai-ink: oklch(0.4 0.14 295);

  /* Channels */
  --ch-ig-1: #f77737;
  --ch-ig-2: #e1306c;
  --ch-ig-3: #833ab4;
  --ch-msg: oklch(0.62 0.19 252);
  --ch-msg-soft: oklch(0.95 0.03 252);
  --ch-wa: oklch(0.62 0.16 145);
  --ch-wa-soft: oklch(0.95 0.04 145);

  /* Status */
  --ok: oklch(0.62 0.15 150);
  --warn: oklch(0.72 0.14 75);
  --busy: oklch(0.65 0.18 35);
  --off: oklch(0.7 0.01 90);

  /* Shape */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(20, 24, 22, 0.04), 0 1px 1px rgba(20, 24, 22, 0.02);
  --shadow-md: 0 2px 4px rgba(20, 24, 22, 0.04), 0 4px 12px rgba(20, 24, 22, 0.06);
  --shadow-lg: 0 8px 24px rgba(20, 24, 22, 0.08), 0 2px 6px rgba(20, 24, 22, 0.04);

  /* Type */
  --font-sans: "Geist", "Geist Fallback", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: "Geist Mono", "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
}

button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; padding: 0; }
input, textarea, select { font: inherit; color: inherit; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: oklch(0.88 0.004 90); border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: oklch(0.8 0.005 90); }

/* Layout */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* === Sidebar === */
.sidebar {
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px 14px;
}
.sb-brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), oklch(0.6 0.16 180));
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: -0.02em;
}
.sb-brand-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.sb-brand-name span { color: var(--text-muted); font-weight: 400; }

.sb-search {
  margin: 4px 12px 8px;
  position: relative;
}
.sb-search input {
  width: 100%;
  padding: 8px 10px 8px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 13px;
  color: var(--text);
}
.sb-search input::placeholder { color: var(--text-subtle); }
.sb-search input:focus { outline: 2px solid var(--accent-soft-2); border-color: var(--accent); }
.sb-search-ico {
  position: absolute;
  top: 50%; left: 10px;
  transform: translateY(-50%);
  color: var(--text-subtle);
}

.sb-nav { padding: 6px 8px; display: flex; flex-direction: column; gap: 1px; }
.sb-section { padding: 12px 12px 4px; font-size: 11px; font-weight: 500; color: var(--text-subtle); text-transform: uppercase; letter-spacing: 0.06em; }
.sb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  width: 100%;
  text-align: left;
}
.sb-item:hover { background: var(--surface-3); }
.sb-item.active { background: var(--surface); box-shadow: var(--shadow-sm); font-weight: 500; }
.sb-item.active .sb-ico { color: var(--accent); }
.sb-item.active.ai .sb-ico { color: var(--ai); }
.sb-item .count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
  background: var(--surface-3);
  padding: 1px 6px;
  border-radius: 999px;
}
.sb-item.active .count { background: var(--accent-soft); color: var(--accent-ink); }
.sb-item .ai-dot { width: 6px; height: 6px; border-radius: 999px; background: var(--ai); margin-left: auto; }
.sb-ico { color: var(--text-muted); display: inline-flex; }

.sb-spacer { flex: 1; }

.sb-user {
  margin: 8px 12px 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sb-user-meta { display: flex; flex-direction: column; min-width: 0; }
.sb-user-name { font-size: 13px; font-weight: 500; }
.sb-user-role { font-size: 11.5px; color: var(--text-muted); }
.sb-user .status-dot { margin-left: auto; }

/* === Pane / main area === */
.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}
.pane-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.pane-title { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.pane-subtitle { font-size: 13px; color: var(--text-muted); }
.pane-body { flex: 1; min-height: 0; overflow: auto; }

/* === Common components === */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
  position: relative;
  letter-spacing: -0.01em;
}
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }
.avatar.md { width: 32px; height: 32px; font-size: 12px; }
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }
.avatar.xl { width: 80px; height: 80px; font-size: 26px; }
.avatar img { width: 100%; height: 100%; border-radius: 999px; object-fit: cover; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
  background: var(--off);
}
.status-dot.ok { background: var(--ok); }
.status-dot.busy { background: var(--busy); }
.status-dot.warn { background: var(--warn); }
.status-dot.off { background: var(--off); }

.avatar .av-status {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 2px solid var(--surface);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  background: var(--surface-3);
  color: var(--text);
  line-height: 1.5;
  white-space: nowrap;
}
.badge.outline { background: transparent; border: 1px solid var(--border); }
.badge.accent { background: var(--accent-soft); color: var(--accent-ink); }
.badge.ai { background: var(--ai-soft); color: var(--ai-ink); }
.badge.warn { background: oklch(0.95 0.04 75); color: oklch(0.4 0.1 75); }
.badge.busy { background: oklch(0.95 0.04 35); color: oklch(0.4 0.12 35); }
.badge.ok { background: oklch(0.95 0.04 150); color: oklch(0.36 0.1 150); }
.badge.muted { background: var(--surface-3); color: var(--text-muted); }
.badge .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; opacity: 0.7; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  transition: background 120ms, border-color 120ms;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ai { background: var(--ai); color: #fff; border-color: var(--ai); }
.btn.ai:hover { background: var(--ai-hover); border-color: var(--ai-hover); }
.btn.ai-outline { background: var(--ai-soft); color: var(--ai-ink); border-color: var(--ai-soft-2); }
.btn.ai-outline:hover { background: var(--ai-soft-2); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-3); color: var(--text); }
.btn.danger { color: var(--busy); }
.btn.sm { padding: 4px 8px; font-size: 12px; border-radius: var(--r-sm); }
.btn.lg { padding: 9px 14px; font-size: 14px; }
.btn.icon { padding: 6px; }
.btn.icon.sm { padding: 4px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip .count { font-size: 11px; opacity: 0.7; font-variant-numeric: tabular-nums; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-sm);
  font-size: 11.5px;
  font-weight: 500;
  background: var(--surface-3);
  color: var(--text);
}
.tag .dot { width: 6px; height: 6px; border-radius: 999px; }

.kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: var(--r-xs);
  color: var(--text-muted);
}

/* === Channel marker === */
.ch-badge {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  display: inline-grid;
  place-items: center;
  color: #fff;
  flex-shrink: 0;
}
.ch-badge.lg { width: 24px; height: 24px; border-radius: 7px; }
.ch-badge.xl { width: 36px; height: 36px; border-radius: 10px; }
.ch-badge.ig { background: linear-gradient(135deg, var(--ch-ig-3) 0%, var(--ch-ig-2) 50%, var(--ch-ig-1) 100%); }
.ch-badge.msg { background: var(--ch-msg); }
.ch-badge.wa { background: var(--ch-wa); }
.ch-badge.ext { background: oklch(0.55 0.13 250); }
.ch-badge svg { width: 60%; height: 60%; }

.avatar .ch-badge {
  position: absolute;
  right: -3px;
  bottom: -3px;
  border: 2px solid var(--surface);
  width: 18px;
  height: 18px;
  border-radius: 6px;
}

/* === Forms === */
.input, .textarea, .select {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 13.5px;
  color: var(--text);
  transition: border-color 120ms;
}
.input:focus, .textarea:focus, .select:focus { outline: 2px solid var(--accent-soft-2); border-color: var(--accent); }
.textarea { resize: vertical; min-height: 80px; line-height: 1.55; }
.label { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); margin-bottom: 6px; }
.field { margin-bottom: 14px; }
.field .help { font-size: 12px; color: var(--text-subtle); margin-top: 4px; }

.switch {
  width: 32px;
  height: 18px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  transition: background 150ms;
  flex-shrink: 0;
  cursor: pointer;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 999px;
  transition: transform 150ms;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.switch.on { background: var(--accent); }
.switch.on.ai { background: var(--ai); }
.switch.on::after { transform: translateX(14px); }

/* === Card === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
}
.card-title { font-size: 14px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.005em; }
.card-subtitle { font-size: 12.5px; color: var(--text-muted); margin: 0 0 14px; }

/* === Table === */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 1;
}
.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:hover td { background: var(--surface-2); }
.table tr.selected td { background: var(--accent-soft); }

/* === Util === */
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; }
.between { justify-content: space-between; }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.mono { font-family: var(--font-mono); }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.divider-v { width: 1px; align-self: stretch; background: var(--border); margin: 0 4px; }
.spacer { flex: 1; }

.hidden { display: none !important; }

/* Animations */
@keyframes fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.fadein { animation: fadein 180ms ease-out; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.pulse { animation: pulse 1.6s ease-in-out infinite; }
