/* ============================================================
   SyncBridge — adapted from Impulsionaê DS for SaaS app context
   Sober, functional. Orange accent reserved for actions.
   ============================================================ */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
a { text-decoration: none; color: inherit; }
ul { list-style: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; }

:root {
  /* ---- DARK (default) ---- */
  --bg-base: #0B0613;
  --bg-surface: #140A22;
  --bg-elevated: #1E1233;
  --bg-hover: #261841;
  --bg-card: rgba(20, 10, 34, 0.6);
  --bg-overlay: rgba(11, 6, 19, 0.78);

  --border: #2A1B45;
  --border-strong: #3A2658;
  --border-subtle: rgba(255,255,255,0.06);

  --text-primary: rgba(255, 255, 255, 0.94);
  --text-secondary: rgba(255, 255, 255, 0.62);
  --text-muted: rgba(255, 255, 255, 0.38);
  --text-faint: rgba(255, 255, 255, 0.22);

  --accent: #FF7A00;
  --accent-hover: #FF8E22;
  --accent-soft: rgba(255, 122, 0, 0.14);
  --accent-glow: rgba(255, 122, 0, 0.28);
  --accent-fg: #0B0613;

  --ok: #08C26B;
  --ok-soft: rgba(8, 194, 107, 0.14);
  --warn: #F2B23A;
  --warn-soft: rgba(242, 178, 58, 0.14);
  --err: #FF4D6D;
  --err-soft: rgba(255, 77, 109, 0.14);
  --info: #3FB8E8;
  --info-soft: rgba(63, 184, 232, 0.14);

  --pink: #FF3D8B;
  --cyan: #29C7C7;
  --green: #25D682;

  /* density */
  --row-h: 40px;
  --pad-x: 24px;
  --pad-y: 20px;
  --gap: 16px;
  --card-pad: 20px;
  --font-base: 14px;
  --font-sm: 13px;
  --font-xs: 12px;

  /* radii */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;
  --r-pill: 9999px;

  /* layout */
  --sidebar-w: 232px;
  --topbar-h: 56px;

  /* font */
  --font: 'Cairo', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --shadow-sm: 0 2px 6px rgba(0,0,0,0.18);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.32);
  --shadow-lg: 0 24px 60px rgba(0,0,0,0.42);
  --shadow-glow: 0 0 24px var(--accent-glow);
}

[data-theme="light"] {
  --bg-base: #F5F2FA;
  --bg-surface: #FFFFFF;
  --bg-elevated: #FFFFFF;
  --bg-hover: #F0EBF7;
  --bg-card: #FFFFFF;
  --bg-overlay: rgba(245, 242, 250, 0.78);

  --border: #E6E1F0;
  --border-strong: #D6CEE5;
  --border-subtle: rgba(20, 10, 34, 0.06);

  --text-primary: #140A22;
  --text-secondary: rgba(20, 10, 34, 0.66);
  --text-muted: rgba(20, 10, 34, 0.42);
  --text-faint: rgba(20, 10, 34, 0.22);

  --accent: #E66A00;
  --accent-hover: #FF7A00;
  --accent-soft: rgba(230, 106, 0, 0.10);
  --accent-glow: rgba(230, 106, 0, 0.18);
  --accent-fg: #FFFFFF;

  --shadow-sm: 0 1px 2px rgba(20,10,34,0.06), 0 1px 3px rgba(20,10,34,0.04);
  --shadow-md: 0 4px 16px rgba(20,10,34,0.08);
  --shadow-lg: 0 16px 48px rgba(20,10,34,0.12);
}

[data-density="compact"] {
  --row-h: 32px;
  --pad-x: 16px;
  --pad-y: 14px;
  --gap: 12px;
  --card-pad: 14px;
  --font-base: 13px;
  --font-sm: 12px;
  --font-xs: 11px;
}

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: var(--font-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ============================================================
   APP SHELL
   ============================================================ */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 100vh;
  height: 100vh;
}
.app[data-nav="top"] {
  grid-template-columns: 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
}

/* ---- SIDEBAR ---- */
.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.app[data-nav="top"] .sidebar { display: none; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-subtle);
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #FF3D8B);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 900;
  font-size: 13px;
  letter-spacing: -0.5px;
  position: relative;
  box-shadow: 0 4px 12px rgba(255, 122, 0, 0.32);
}
.brand-mark::after {
  content: '';
  position: absolute; inset: 6px;
  border-radius: 4px;
  border: 1.5px solid rgba(255,255,255,0.85);
  border-top-color: transparent;
  border-right-color: transparent;
  transform: rotate(45deg);
}
.brand-name {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.3px;
}
.brand-sub {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--text-muted);
  font-weight: 700;
  margin-top: 1px;
}

.nav-group { padding: 14px 10px 6px; }
.nav-group-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--text-muted);
  font-weight: 700;
  padding: 0 10px 8px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  position: relative;
  margin-bottom: 1px;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -10px; top: 8px; bottom: 8px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.nav-item iconify-icon { font-size: 17px; flex-shrink: 0; }
.nav-item .badge-count {
  margin-left: auto;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: var(--r-pill);
  font-family: var(--font-mono);
}

.sidebar-foot {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---- TOPBAR (when nav=top) ---- */
.topbar-nav-mode {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 0 18px;
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}
.app[data-nav="top"] .topbar-nav-mode { display: flex; }
.topbar-nav-mode .brand { border: none; padding: 0 14px 0 0; }
.topbar-nav-mode .nav-item { padding: 6px 12px; margin: 0; }
.topbar-nav-mode .nav-item.active::before { display: none; }
.topbar-nav-mode .nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---- MAIN ---- */
.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}
.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--pad-x);
  gap: 16px;
  background: var(--bg-surface);
  flex-shrink: 0;
}
.app[data-nav="top"] .topbar { background: var(--bg-base); }
.crumbs {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--text-secondary); font-weight: 600;
}
.crumbs .sep { color: var(--text-faint); }
.crumbs .here { color: var(--text-primary); }
.topbar-spacer { flex: 1; }

.role-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 3px;
  border-radius: var(--r-pill);
}
.role-pill button {
  font-size: 11px;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: var(--r-pill);
  color: var(--text-muted);
  transition: all 0.15s;
}
.role-pill button.on {
  background: var(--accent);
  color: var(--accent-fg);
}

.iconbtn {
  width: 34px; height: 34px;
  border-radius: var(--r-md);
  display: grid; place-items: center;
  color: var(--text-secondary);
  border: 1px solid transparent;
  position: relative;
}
.iconbtn:hover { background: var(--bg-hover); color: var(--text-primary); }
.iconbtn iconify-icon { font-size: 18px; }
.iconbtn .dot {
  position: absolute; top: 7px; right: 8px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-surface);
}

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF3D8B, var(--accent));
  display: grid; place-items: center;
  font-size: 12px; font-weight: 800;
  color: #fff;
}

.content {
  flex: 1;
  overflow: auto;
  padding: var(--pad-y) var(--pad-x);
}

/* ============================================================
   PRIMITIVES
   ============================================================ */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--card-pad);
}
.card-elev {
  background: var(--bg-elevated);
}
.card-glass {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--card-pad);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--r-md);
  font-size: var(--font-sm);
  font-weight: 700;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-primary);
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn iconify-icon { font-size: 15px; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-sm { padding: 5px 10px; font-size: var(--font-xs); }
.btn-icon { padding: 8px; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 700;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  letter-spacing: 0;
  text-transform: none;
}
.tag-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag-err { background: var(--err-soft); color: var(--err); border-color: transparent; }
.tag-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.tag-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.tag-dot::before {
  content: '';
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}

.kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.divider { height: 1px; background: var(--border-subtle); margin: 16px 0; }

.input {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 8px 12px;
  font-size: var(--font-sm);
  color: var(--text-primary);
  width: 100%;
  outline: none;
  transition: border 0.15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder { color: var(--text-muted); }

.select {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 6px 10px;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
}
.select:hover { border-color: var(--border-strong); color: var(--text-primary); }
.select iconify-icon { font-size: 14px; opacity: 0.7; }

/* ---- PAGE HEADER ---- */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.page-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.15;
}
.page-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.page-actions { display: flex; gap: 8px; align-items: center; }

/* ---- TWEAKS PANEL ---- */
.tweaks {
  position: fixed;
  right: 20px; bottom: 20px;
  width: 280px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  padding: 14px;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  display: none;
}
.tweaks[data-open="true"] { display: block; }
.tweaks-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
  font-size: 13px; font-weight: 800;
}
.tweaks-row { margin-bottom: 12px; }
.tweaks-row:last-child { margin-bottom: 0; }
.tweaks-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted); font-weight: 700; margin-bottom: 6px;
}
.tweaks-options { display: flex; gap: 4px; background: var(--bg-base); border: 1px solid var(--border); padding: 3px; border-radius: var(--r-md); }
.tweaks-options button {
  flex: 1;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 6px;
  color: var(--text-muted);
}
.tweaks-options button.on { background: var(--accent); color: var(--accent-fg); }

/* ---- MODAL ---- */
.modal-back {
  position: fixed; inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.modal-back[data-open="true"] { display: flex; }
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  width: 100%;
  max-width: 720px;
  max-height: calc(100vh - 80px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-body { padding: 18px 22px; overflow: auto; flex: 1; }
.modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ---- SCROLL ---- */
.content::-webkit-scrollbar, .modal-body::-webkit-scrollbar { width: 8px; height: 8px; }
.content::-webkit-scrollbar-thumb, .modal-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

/* ---- ANIMATIONS ---- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}
@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes shimmer {
  to { background-position: 200% center; }
}
.fade-up { animation: fade-up 0.4s ease both; }
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 0%, var(--bg-hover) 50%, var(--bg-elevated) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: 6px;
}

/* utility */
.row { display: flex; align-items: center; }
.gap-sm { gap: 8px; } .gap-md { gap: 12px; } .gap-lg { gap: 16px; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.mono { font-family: var(--font-mono); }
.center { display: grid; place-items: center; }
.spacer { flex: 1; }

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty .icon {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: var(--bg-elevated);
  display: grid; place-items: center;
  color: var(--text-secondary);
  margin: 0 auto 14px;
  font-size: 24px;
}

/* ---- KPI CARD ---- */
.kpi {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--card-pad);
  position: relative;
  overflow: hidden;
}
.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  font-weight: 700;
  display: flex; align-items: center; gap: 6px;
}
.kpi-value {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -1px;
  margin: 8px 0 6px;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--r-pill);
}
.kpi-delta.up { background: var(--ok-soft); color: var(--ok); }
.kpi-delta.down { background: var(--err-soft); color: var(--err); }
.kpi-foot { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ---- TABLE ---- */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-sm);
}
.tbl th {
  text-align: left;
  padding: 10px 12px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  z-index: 1;
}
.tbl td {
  padding: 0 12px;
  height: var(--row-h);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: middle;
}
.tbl tr:hover td { background: var(--bg-hover); color: var(--text-primary); cursor: pointer; }
.tbl td.strong { color: var(--text-primary); font-weight: 600; }

/* ---- PROGRESS ---- */
.progress {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-pill);
  transition: width 0.4s ease;
}
.progress-bar.warn { background: var(--warn); }
.progress-bar.err { background: var(--err); }

/* ---- TABS ---- */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}
.tab {
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  position: relative;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text-secondary); }
.tab.on { color: var(--text-primary); border-bottom-color: var(--accent); }
.tab .count {
  margin-left: 6px;
  font-size: 10px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  padding: 1px 6px;
  border-radius: var(--r-pill);
  font-family: var(--font-mono);
}
