/* ═══════════════════════════════════════════════════════════════════════════
   Nidin BOS — Apple-Inspired Design System
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap');

:root {
  color-scheme: light;

  /* ── Surface palette (Apple light) ──────────────────────────────────── */
  --bg:           #f5f5f7;       /* Apple light gray */
  --surface:      #ffffff;
  --surface-alt:  #fbfbfd;
  --line:         #d2d2d7;       /* Apple border */
  --line-soft:    #e8e8ed;

  /* ── Sidebar ─────────────────────────────────────────────────────────── */
  --sb-bg:        rgba(255, 255, 255, 0.72);
  --sb-text:      #86868b;
  --sb-text-hover:#1d1d1f;
  --sb-active-bg: rgba(0, 122, 255, 0.08);
  --sb-active-text: #007aff;
  --sb-line:      rgba(0, 0, 0, 0.06);
  --sb-width:     64px;
  --sb-width-expanded: 220px;

  /* ── Typography ──────────────────────────────────────────────────────── */
  --font:         'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', system-ui, sans-serif;
  --text:         #1d1d1f;       /* Apple primary text */
  --text-secondary:#424245;
  --text-muted:   #6e6e73;
  --text-faint:   #86868b;

  /* ── Type Scale ─────────────────────────────────────────────────────── */
  --text-2xs:  0.62rem;   /* 9.9px  — uppercase labels, tiny meta */
  --text-xs:   0.68rem;   /* 10.9px — labels, meta, tooltips */
  --text-sm:   0.78rem;   /* 12.5px — body small, buttons, table headers */
  --text-base: 0.85rem;   /* 13.6px — body, form inputs, chat */
  --text-lg:   1.05rem;   /* 16.8px — section titles, nav brand */
  --text-xl:   1.2rem;    /* 19.2px — page titles, KPI values */
  --text-2xl:  1.65rem;   /* 26.4px — dashboard greeting, hero numbers */
  --text-3xl:  2.4rem;    /* 38.4px — giant display numbers */

  /* ── Brand (Apple Blue) ─────────────────────────────────────────────── */
  --brand:        #007aff;
  --brand-hover:  #0062cc;
  --brand-soft:   rgba(0, 122, 255, 0.08);
  --focus-ring:   rgba(0, 122, 255, 0.4);
  --motion-fast:  120ms;
  --motion-base:  200ms;

  /* ── Semantic (Apple System Colors) ─────────────────────────────────── */
  --ok:           #34c759;
  --ok-soft:      rgba(52, 199, 89, 0.08);
  --ok-border:    rgba(52, 199, 89, 0.25);
  --warn:         #ff9f0a;
  --warn-soft:    rgba(255, 159, 10, 0.08);
  --warn-border:  rgba(255, 159, 10, 0.25);
  --danger:       #ff3b30;
  --danger-soft:  rgba(255, 59, 48, 0.08);
  --danger-border:rgba(255, 59, 48, 0.25);
  --info:         #5856d6;
  --info-soft:    rgba(88, 86, 214, 0.08);
  --info-border:  rgba(88, 86, 214, 0.25);

  /* ── Spacing ─────────────────────────────────────────────────────────── */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px;  --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 32px;  --sp-8: 40px;

  /* ── Elevation ───────────────────────────────────────────────────────── */
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow:     0 1px 4px rgba(0, 0, 0, 0.05);
  --shadow-md:  0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg:  0 8px 24px rgba(0, 0, 0, 0.1);
  --radius:     8px;
  --radius-sm:  6px;
  --radius-lg:  10px;
}

/* ── Dark Mode ────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:           #000000;
  --surface:      #1c1c1e;
  --surface-alt:  #2c2c2e;
  --line:         #38383a;
  --line-soft:    #2c2c2e;
  --sb-bg:        rgba(28, 28, 30, 0.88);
  --sb-text:      #98989d;
  --sb-text-hover:#f5f5f7;
  --sb-active-bg: rgba(0, 122, 255, 0.15);
  --sb-active-text: #0a84ff;
  --sb-line:      rgba(255, 255, 255, 0.06);
  --text:         #f5f5f7;
  --text-secondary:#a1a1a6;
  --text-muted:   #8e8e93;
  --text-faint:   #636366;
  --brand:        #0a84ff;
  --brand-hover:  #409cff;
  --brand-soft:   rgba(10, 132, 255, 0.12);
  --focus-ring:   rgba(10, 132, 255, 0.5);
  --ok:           #30d158;
  --ok-soft:      rgba(48, 209, 88, 0.12);
  --ok-border:    rgba(48, 209, 88, 0.3);
  --warn:         #ff9f0a;
  --warn-soft:    rgba(255, 159, 10, 0.12);
  --warn-border:  rgba(255, 159, 10, 0.3);
  --danger:       #ff453a;
  --danger-soft:  rgba(255, 69, 58, 0.12);
  --danger-border:rgba(255, 69, 58, 0.3);
  --info:         #5e5ce6;
  --info-soft:    rgba(94, 92, 230, 0.12);
  --info-border:  rgba(94, 92, 230, 0.3);
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow:     0 1px 4px rgba(0, 0, 0, 0.35);
  --shadow-md:  0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg:  0 8px 24px rgba(0, 0, 0, 0.5);
}
[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--line);
}
[data-theme="dark"] .card,
[data-theme="dark"] .section,
[data-theme="dark"] .ai-card {
  background: var(--surface);
  border-color: var(--line);
}
[data-theme="dark"] .btn {
  border-color: var(--line);
}
[data-theme="dark"] .pill.connected { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-border); }
[data-theme="dark"] .pill.disconnected { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }

/* Dark mode sidebar hover */
[data-theme="dark"] .sidebar { background: #1c1c1e; border-right-color: var(--sb-line); }
[data-theme="dark"] .sidebar:hover { background: #1c1c1e; }
[data-theme="dark"] .sb-item:hover { background: rgba(255, 255, 255, 0.06); }
[data-theme="dark"] .sb-label { color: var(--sb-text); }
[data-theme="dark"] .sb-item.active .sb-label { color: var(--sb-active-text); }
[data-theme="dark"] .sb-brand-text { color: var(--text); }
[data-theme="dark"] .sb-user-email { color: var(--text-faint); }

/* Dark mode skeleton shimmer */
[data-theme="dark"] .skeleton-shimmer {
  background: linear-gradient(90deg, var(--surface-alt) 25%, #3a3a3c 50%, var(--surface-alt) 75%) !important;
  background-size: 200% 100% !important;
}

/* Dark mode empty state */
[data-theme="dark"] .empty-state-icon { background: var(--surface-alt); }

/* Dark mode KPI and card borders */
[data-theme="dark"] .kpi { border-color: var(--line); }
[data-theme="dark"] .card { border-color: var(--line); }

/* Theme toggle */
.theme-toggle {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.35rem 0.7rem;
  font-size: var(--text-sm); color: var(--sb-text);
  cursor: pointer; border: none; background: none;
  width: 100%;
}
.theme-toggle:hover { color: var(--sb-text-hover); }

/* prefers-color-scheme auto-dark removed — light-only by default.
   Dark mode still available via manual toggle (data-theme="dark"). */

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}

html {
  font-feature-settings: 'cv01' 1, 'cv02' 1, 'ss01' 1;
  text-rendering: optimizeLegibility;
  font-optical-sizing: auto;
}

::selection {
  background: rgba(0, 122, 255, 0.2);
  color: var(--text);
}

:where(button, [type="button"], [type="submit"], a, input, textarea, select):focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ── Scrollbar ────────────────────────────────────────────────────────── */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.12) transparent;
}
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.12); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.22); }
::-webkit-scrollbar-corner { background: transparent; }

[data-theme="dark"] * { scrollbar-color: rgba(255, 255, 255, 0.1) transparent; }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

/* ═══════════════════════════════════════════════════════════════════════════
   SIDEBAR — Hover-Expand (64px → 220px)
   ═══════════════════════════════════════════════════════════════════════════ */

.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sb-width);
  z-index: 60;
  background: var(--surface);
  border-right: 1px solid var(--sb-line);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width .2s cubic-bezier(.4, 0, .2, 1);
  will-change: width;
}
.sidebar:hover { width: var(--sb-width-expanded, 220px); }

/* ── Text labels — hidden by default, revealed on expand ─────────────── */
.sb-label {
  font-size: var(--text-sm); font-weight: 500;
  white-space: nowrap;
  opacity: 0; width: 0; overflow: hidden;
  transition: opacity .15s ease, width .2s cubic-bezier(.4, 0, .2, 1);
  pointer-events: none;
  color: var(--sb-text);
}
.sidebar:hover .sb-label {
  opacity: 1; width: auto;
  pointer-events: auto;
}

/* ── Brand ────────────────────────────────────────────────────────────── */
.sb-brand {
  display: flex; align-items: center; gap: .65rem;
  padding: .85rem .85rem .85rem 1rem;
  width: 100%;
  border-bottom: 1px solid var(--sb-line);
  min-height: 56px;
}
.sb-brand-icon {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(135deg, #007aff 0%, #5856d6 100%);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: var(--text-sm); font-weight: 800;
}
.sb-brand-text {
  font-weight: 700; font-size: var(--text-sm); color: var(--text);
  letter-spacing: -.01em;
}
.sb-pulse { display: none; }

/* ── Nav ──────────────────────────────────────────────────────────────── */
.sb-nav {
  flex: 1; padding: .5rem .7rem;
  display: flex; flex-direction: column; gap: 2px;
  width: 100%; overflow-y: auto; overflow-x: hidden;
}

.sb-section { display: none; }
.sb-more { display: none; }
.sb-group { display: none; }
.sb-group-title { display: none; }
.sb-divider { display: none; }

/* ── Nav item ─────────────────────────────────────────────────────────── */
.sb-item {
  display: flex; align-items: center; gap: .65rem;
  height: 36px; min-width: 36px;
  padding: 0 .55rem;
  border-radius: 8px;
  color: var(--sb-text); text-decoration: none;
  transition: background .15s ease, color .15s ease;
  cursor: pointer; border: none; background: transparent;
  position: relative;
  font-size: var(--text-sm);
}
.sb-item:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--sb-text-hover);
}
.sb-item.active {
  background: var(--sb-active-bg);
  color: var(--sb-active-text);
}
.sb-item.active .sb-label { color: var(--sb-active-text); }
.sb-item svg, .sb-item i { width: 18px; height: 18px; flex-shrink: 0; opacity: .5; }
.sb-item:hover svg, .sb-item:hover i { opacity: .85; }
.sb-item.active svg, .sb-item.active i { opacity: 1; color: var(--sb-active-text); }

/* ── Footer ───────────────────────────────────────────────────────────── */
.sb-footer {
  padding: .5rem .7rem; border-top: 1px solid var(--sb-line);
  display: flex; flex-direction: column; gap: 2px;
  width: 100%;
}
.sb-footer .sb-item:hover { color: var(--danger); background: var(--danger-soft); }
.sb-footer .sb-item:hover .sb-label { color: var(--danger); }

/* ── User row ─────────────────────────────────────────────────────────── */
.sb-user-row {
  display: flex; align-items: center; gap: .5rem;
  padding: .25rem .55rem;
}
.sb-user-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #007aff 0%, #5856d6 100%);
  color: #fff; font-size: var(--text-xs); font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border: none;
}
.sb-user-email {
  font-size: var(--text-xs); color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MAIN CONTENT
   ═══════════════════════════════════════════════════════════════════════════ */

.main-wrap {
  margin-left: var(--sb-width);
  padding: 1.25rem 1.75rem;
  max-width: 1280px;
  min-height: 100vh;
}

.page-title {
  font-size: var(--text-xl); font-weight: 700; color: var(--text);
  margin-bottom: 1.25rem; letter-spacing: -.01em;
}
.page-subtitle {
  font-size: var(--text-sm); color: var(--text-muted); font-weight: 400;
  margin-top: .15rem;
}

/* ── Page entrance ────────────────────────────────────────────────────── */
@keyframes page-enter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
main, .main-wrap {
  animation: page-enter 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ═══════════════════════════════════════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════════════════════════════════════ */

.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: .75rem;
}

.card-head {
  padding: .55rem .85rem;
  border-bottom: 1px solid var(--line-soft);
  font-size: var(--text-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted);
  display: flex; justify-content: space-between; align-items: center;
}

.card-body { padding: .65rem .85rem; }

/* ═══════════════════════════════════════════════════════════════════════════
   KPI ROW
   ═══════════════════════════════════════════════════════════════════════════ */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .5rem;
  margin-bottom: 1rem;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: .55rem .75rem;
}
.kpi .label {
  font-size: var(--text-2xs); text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-faint);
  font-weight: 600; margin-bottom: .3rem;
}
.kpi .val {
  font-size: var(--text-xl); font-weight: 700; color: var(--text);
  line-height: 1.2;
  font-feature-settings: 'tnum' 1, 'lnum' 1;
  font-variant-numeric: tabular-nums;
}
.kpi .sub { font-size: var(--text-xs); color: var(--text-muted); margin-top: .15rem; }

/* ═══════════════════════════════════════════════════════════════════════════
   BUTTONS — Apple style
   ═══════════════════════════════════════════════════════════════════════════ */

.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .35rem .7rem;
  font-size: var(--text-sm); font-weight: 500; font-family: var(--font);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all .15s ease;
  text-decoration: none;
  line-height: 1.35;
  white-space: nowrap;
}
.btn:hover { border-color: var(--text-faint); background: var(--surface-alt); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn.primary {
  background: var(--brand); color: #fff; border-color: var(--brand);
  box-shadow: 0 1px 4px rgba(0, 122, 255, 0.2);
}
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

.btn.danger { color: var(--danger); border-color: var(--danger-border); }
.btn.danger:hover { background: var(--danger-soft); }

.btn.success { color: var(--ok); border-color: var(--ok-border); }
.btn.success:hover { background: var(--ok-soft); }

.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-alt); border-color: var(--line); }

.btn.sm { font-size: var(--text-xs); padding: .3rem .55rem; }

/* ═══════════════════════════════════════════════════════════════════════════
   TABLES
   ═══════════════════════════════════════════════════════════════════════════ */

table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
th {
  text-align: left; font-size: var(--text-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); padding: .4rem .55rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface-alt);
}
td {
  padding: .4rem .55rem;
  border-bottom: 1px solid var(--line-soft);
  color: var(--text-secondary);
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-alt); }

/* ═══════════════════════════════════════════════════════════════════════════
   TAGS / BADGES
   ═══════════════════════════════════════════════════════════════════════════ */

.tag {
  display: inline-block;
  font-size: var(--text-2xs); font-weight: 600;
  padding: .12rem .4rem; border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .03em;
}
.tag.ok      { border-color: var(--ok-border);     color: var(--ok);     background: var(--ok-soft); }
.tag.warn    { border-color: var(--warn-border);    color: var(--warn);   background: var(--warn-soft); }
.tag.err,
.tag.danger  { border-color: var(--danger-border);  color: var(--danger); background: var(--danger-soft); }
.tag.info    { border-color: var(--info-border);    color: var(--info);   background: var(--info-soft); }
.tag.draft   { border-color: var(--line); color: var(--text-muted); background: var(--surface-alt); }

/* ═══════════════════════════════════════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════════════════════════════════════ */

.input, input[type="text"], input[type="email"], input[type="password"],
input[type="url"], input[type="number"], input[type="date"], select, textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: .5rem .7rem;
  font-size: var(--text-base);
  font-family: var(--font);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.input:focus, input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

label {
  display: block;
  font-size: var(--text-sm); font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .3rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TABS
   ═══════════════════════════════════════════════════════════════════════════ */

.tab-bar {
  display: flex; gap: .1rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1rem;
}

.tab {
  padding: .5rem .9rem;
  font-size: var(--text-sm); font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border: none; background: none;
  border-bottom: 2px solid transparent;
  transition: all .15s ease;
  font-family: var(--font);
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ═══════════════════════════════════════════════════════════════════════════ */

.toast-container {
  position: fixed; top: 1rem; right: 1rem; z-index: 9999;
  display: flex; flex-direction: column; gap: .5rem;
  pointer-events: none;
}
.toast {
  padding: .6rem 1rem;
  border-radius: var(--radius);
  font-size: var(--text-sm); font-weight: 500;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toast-in .3s ease;
  max-width: 360px;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.toast.info    { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.toast.success { background: var(--ok-soft); color: var(--ok); border: 1px solid var(--ok-border); }
.toast.error   { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger-border); }
.toast.warn    { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-border); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: none; }
}

@keyframes toast-out {
  from { opacity: 1; transform: none; }
  to   { opacity: 0; transform: translateX(20px); }
}
.toast.removing {
  animation: toast-out .25s ease forwards;
}

/* ═══════════════════════════════════════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════════════════════════════════════ */

.empty {
  text-align: center; padding: 2.5rem 1rem;
  color: var(--text-faint); font-size: var(--text-base);
}

/* ═══════════════════════════════════════════════════════════════════════════
   SYNC STATUS BADGES
   ═══════════════════════════════════════════════════════════════════════════ */

.sync-status { font-size: var(--text-xs); color: var(--text-faint); margin-left: .5rem; }

/* ═══════════════════════════════════════════════════════════════════════════
   LOADING
   ═══════════════════════════════════════════════════════════════════════════ */

.loading {
  display: flex; align-items: center; justify-content: center;
  padding: 3rem; color: var(--text-faint); font-size: var(--text-base);
}

/* ── Loading spinner ──────────────────────────────────────────────────── */
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
.spinner.lg { width: 28px; height: 28px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-center {
  display: flex; align-items: center; justify-content: center;
  gap: .5rem; padding: 2rem; color: var(--text-faint); font-size: var(--text-base);
}

/* ── Skeleton loading ────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg,
    var(--line-soft) 25%,
    var(--surface-alt) 50%,
    var(--line-soft) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.8s ease infinite;
  border-radius: 6px;
  color: transparent !important;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}
.skeleton * { visibility: hidden; }
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Skeleton presets — drop-in placeholders */
.skel-line {
  height: .85rem; border-radius: 4px; margin-bottom: .5rem;
  background: inherit; background-size: inherit; animation: inherit;
}
.skel-line.short { width: 45%; }
.skel-line.medium { width: 70%; }
.skel-circle {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
}
.skel-kpi {
  height: 72px; border-radius: var(--radius); width: 100%;
}
.skel-card {
  height: 120px; border-radius: var(--radius); width: 100%;
}
.skel-row {
  display: flex; gap: .75rem; align-items: center; padding: .6rem 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   STAGGERED ENTRANCE ANIMATIONS
   ═══════════════════════════════════════════════════════════════════════════ */

@keyframes enter-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes enter-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes enter-scale {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

/* Apply to any container: children auto-stagger */
.stagger-enter > * {
  opacity: 0;
  animation: enter-up 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.stagger-enter > *:nth-child(1)  { animation-delay: 0.04s; }
.stagger-enter > *:nth-child(2)  { animation-delay: 0.08s; }
.stagger-enter > *:nth-child(3)  { animation-delay: 0.12s; }
.stagger-enter > *:nth-child(4)  { animation-delay: 0.14s; }
.stagger-enter > *:nth-child(5)  { animation-delay: 0.16s; }
.stagger-enter > *:nth-child(6)  { animation-delay: 0.18s; }
.stagger-enter > *:nth-child(7)  { animation-delay: 0.20s; }
.stagger-enter > *:nth-child(8)  { animation-delay: 0.22s; }
.stagger-enter > *:nth-child(9)  { animation-delay: 0.24s; }
.stagger-enter > *:nth-child(10) { animation-delay: 0.26s; }
.stagger-enter > *:nth-child(n+11) { animation-delay: 0.28s; }

/* Fade variant (subtler) */
.stagger-fade > * {
  opacity: 0;
  animation: enter-fade 0.35s ease both;
}
.stagger-fade > *:nth-child(1)  { animation-delay: 0.03s; }
.stagger-fade > *:nth-child(2)  { animation-delay: 0.06s; }
.stagger-fade > *:nth-child(3)  { animation-delay: 0.09s; }
.stagger-fade > *:nth-child(4)  { animation-delay: 0.12s; }
.stagger-fade > *:nth-child(5)  { animation-delay: 0.15s; }
.stagger-fade > *:nth-child(n+6) { animation-delay: 0.18s; }

/* ═══════════════════════════════════════════════════════════════════════════
   NUMBER COUNT-UP (applied via JS data-count-to="123")
   ═══════════════════════════════════════════════════════════════════════════ */

[data-count-to] {
  font-feature-settings: 'tnum' 1, 'lnum' 1;
  font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════════════════════════════════
   PAGE TRANSITIONS (View Transition API + fallback)
   ═══════════════════════════════════════════════════════════════════════════ */

@view-transition { navigation: auto; }
::view-transition-old(root) {
  animation: 150ms ease both fade-out;
}
::view-transition-new(root) {
  animation: 200ms ease both fade-in;
}
@keyframes fade-out { to { opacity: 0; } }
@keyframes fade-in  { from { opacity: 0; } }

/* Named transitions for specific elements */
.main-wrap, main { view-transition-name: main-content; }
.sidebar  { view-transition-name: sidebar; }
::view-transition-old(sidebar) { animation: none; }
::view-transition-new(sidebar) { animation: none; }

/* ═══════════════════════════════════════════════════════════════════════════
   EMPTY STATES — Rich placeholders with icon + message + action
   ═══════════════════════════════════════════════════════════════════════════ */

.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center;
  padding: 3rem 1.5rem; gap: .6rem;
}
.empty-state-icon {
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--surface-alt); border: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: .25rem;
}
.empty-state-icon i, .empty-state-icon svg {
  width: 24px; height: 24px; color: var(--text-faint); opacity: .5;
}
.empty-state-title {
  font-size: var(--text-base); font-weight: 600; color: var(--text-secondary);
}
.empty-state-desc {
  font-size: var(--text-sm); color: var(--text-faint); max-width: 280px;
  line-height: 1.5;
}
.empty-state-action {
  margin-top: .5rem;
}

/* ═══════════════════════════════════════════════════════════════════════════
   LIST ITEM HOVER + ACTIVE MICROINTERACTIONS
   ═══════════════════════════════════════════════════════════════════════════ */

.list-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .75rem; border-radius: var(--radius-sm);
  transition: background 120ms ease, transform 120ms ease;
  cursor: pointer;
}
.list-item:hover { background: var(--surface-alt); }
.list-item:active { transform: scale(0.99); }

/* Row highlight flash (used after create/update) */
@keyframes row-flash {
  0%   { background: var(--brand-soft); }
  100% { background: transparent; }
}
.row-flash { animation: row-flash 1.2s ease both; }

/* ═══════════════════════════════════════════════════════════════════════════
   PROGRESS BAR (reusable)
   ═══════════════════════════════════════════════════════════════════════════ */

.progress-bar {
  height: 4px; background: var(--line-soft); border-radius: 99px;
  overflow: hidden; width: 100%;
}
.progress-bar-fill {
  height: 100%; border-radius: 99px;
  background: var(--brand);
  transition: width 600ms cubic-bezier(0.16, 1, 0.3, 1);
}
.progress-bar-fill.ok     { background: var(--ok); }
.progress-bar-fill.warn   { background: var(--warn); }
.progress-bar-fill.danger { background: var(--danger); }

/* ═══════════════════════════════════════════════════════════════════════════
   TOOLTIP — hover-triggered, pure CSS
   ═══════════════════════════════════════════════════════════════════════════ */

[data-tip] { position: relative; }
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  font-size: var(--text-xs); font-weight: 600;
  padding: .25rem .5rem; border-radius: 6px;
  white-space: nowrap; z-index: 200;
  pointer-events: none;
  animation: enter-fade .12s ease;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════════════════════════════════ */

.modal-mask {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, .3);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  display: none; align-items: center; justify-content: center;
}
.modal-mask.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); max-width: 520px; width: 90%;
  padding: 1.5rem;
}
.modal-title {
  font-size: var(--text-base); font-weight: 700; margin-bottom: 1rem;
}
.modal-actions {
  display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem;
}
.modal-form {
  display: flex; flex-direction: column; gap: .6rem;
}

/* ── Form validation states ───────────────────────────────────────────── */
.input-error,
input.input-error,
select.input-error,
textarea.input-error {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px var(--danger-soft);
}
.field-error {
  font-size: var(--text-xs); color: var(--danger); margin-top: .15rem;
}

/* ── Compose form area ────────────────────────────────────────────────── */
.compose-area {
  display: none; padding: .8rem 1.1rem; border-bottom: 1px solid var(--line-soft);
}
.compose-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: .6rem;
}
.compose-footer {
  display: flex; justify-content: space-between; align-items: center; margin-top: .6rem;
}

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE NAVIGATION
   ═══════════════════════════════════════════════════════════════════════════ */

.mobile-hamburger {
  display: none;
  position: fixed; top: .75rem; left: .75rem; z-index: 200;
  width: 42px; height: 42px;
  border: none; border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer; align-items: center; justify-content: center;
  padding: 0; -webkit-tap-highlight-color: transparent;
}
.mobile-hamburger span,
.mobile-hamburger span::before,
.mobile-hamburger span::after {
  display: block; width: 16px; height: 2px;
  background: var(--text); border-radius: 2px;
  transition: transform .25s ease, opacity .2s ease;
  position: relative;
}
.mobile-hamburger span::before, .mobile-hamburger span::after {
  content: ''; position: absolute; left: 0; width: 100%;
}
.mobile-hamburger span::before { top: -5px; }
.mobile-hamburger span::after  { top: 5px; }
.mobile-hamburger.open span { background: transparent; }
.mobile-hamburger.open span::before { top: 0; transform: rotate(45deg); }
.mobile-hamburger.open span::after  { top: 0; transform: rotate(-45deg); }

.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 55;
  background: rgba(0, 0, 0, .25);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  opacity: 0; transition: opacity .25s ease;
}
.sidebar-overlay.visible { display: block; opacity: 1; }

/* ── Tablet ────────────────────────────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar { width: var(--sb-width); }
  .main-wrap { margin-left: var(--sb-width); }
}

/* ── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  html, body { overflow-x: hidden; }
  .mobile-hamburger { display: flex; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    z-index: 150 !important; width: var(--sb-width-expanded) !important;
    background: var(--surface);
  }
  .sidebar:hover { width: var(--sb-width-expanded) !important; }
  .sidebar .sb-label { opacity: 1; width: auto; pointer-events: auto; }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-wrap { margin-left: 0 !important; padding: 1rem !important; padding-top: 3.5rem !important; }
  .sb-item { min-height: 44px !important; }
  .kpi-row { grid-template-columns: repeat(2, 1fr) !important; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   UTILITY
   ═══════════════════════════════════════════════════════════════════════════ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.mt-2 { margin-top: .5rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.text-ok { color: var(--ok) !important; }
.text-warn { color: var(--warn) !important; }
.text-danger { color: var(--danger) !important; }
.text-muted { color: var(--text-muted) !important; }
.font-mono { font-family: 'SF Mono', 'Fira Code', monospace; }

/* ═══════════════════════════════════════════════════════════════════════════
   INTERACTION POLISH
   ═══════════════════════════════════════════════════════════════════════════ */

:where(.btn, .btn-run, .chat-send, .role-btn, .ia-btn, .filter-btn, .btn-agent-action) {
  transition: transform 160ms ease, box-shadow 180ms ease, border-color 180ms ease, background 180ms ease, color 180ms ease;
}

:where(.btn, .btn-run, .chat-send, .role-btn, .ia-btn, .filter-btn, .btn-agent-action):hover {
  transform: translateY(-1px);
}

:where(.btn, .btn-run, .chat-send, .role-btn, .ia-btn, .filter-btn, .btn-agent-action):active {
  transform: translateY(0) scale(0.98);
}

:where(.btn, .btn-run, .chat-send, .role-btn, .ia-btn, .filter-btn, .btn-agent-action):focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ── Number typography ────────────────────────────────────────────────── */
.stat strong, .kpi .val, .kpi .value, .fin-val, .card-count {
  font-feature-settings: 'tnum' 1, 'lnum' 1;
  font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOUCH ERGONOMICS
   ═══════════════════════════════════════════════════════════════════════════ */

@media (pointer: coarse) {
  html, body {
    overscroll-behavior-y: contain;
    -webkit-tap-highlight-color: transparent;
  }

  :where(button, a, input, textarea, select, summary, .sb-item) {
    touch-action: manipulation;
  }

  :where(.btn, .btn-run, .chat-send, .role-btn, .ia-btn, .filter-btn, .btn-agent-action, .sb-item) {
    min-height: 44px;
  }

  :where(.btn, .btn-run, .chat-send, .role-btn, .ia-btn, .filter-btn, .btn-agent-action):active {
    transform: scale(0.985);
  }

  .chat-history,
  #tasks-list,
  #inbox-list,
  #audit-list,
  #integrations-list {
    -webkit-overflow-scrolling: touch;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   ACCESSIBILITY
   ═══════════════════════════════════════════════════════════════════════════ */

@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;
  }
}

@media (forced-colors: active) {
  :where(button, [type="button"], [type="submit"], a, input, textarea, select):focus-visible {
    outline: 2px solid Highlight !important;
    outline-offset: 2px;
  }
}
