:root {
  --radius: 14px;
  --radius-sm: 10px;
  --gap: 14px;
  --shadow: 0 10px 30px rgba(0,0,0,.08);

  --accent: #2bbdc6;
  --accent-2: #0ea5e9;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #2563eb;

  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f2f4f8;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
}

html[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #111827;
  --surface-2: #1f2937;
  --border: #2b3648;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, Segoe UI, Arial, sans-serif; background: var(--bg); color: var(--text); }

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.app-shell__sidebar {
  background: linear-gradient(180deg, #0f172a 0%, #111827 100%);
  color: #e5e7eb;
  border-right: 1px solid rgba(255,255,255,.05);
  padding: 16px 14px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding: 8px;
}
.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent);
  color: #052a2d;
  display: grid;
  place-items: center;
  font-weight: 700;
}
.brand-name { font-weight: 700; }
.brand-sub { color: #9ca3af; font-size: 12px; }

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.side-nav__item {
  display: block;
  text-decoration: none;
  color: #d1d5db;
  padding: 10px 12px;
  border-radius: 10px;
  transition: .15s ease;
  font-size: 14px;
}
.side-nav__item:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-nav__item.active {
  background: rgba(43,189,198,.18);
  color: #dffbfc;
  border: 1px solid rgba(43,189,198,.25);
}

.app-shell__main {
  display: grid;
  grid-template-rows: 64px 1fr;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.workspace-switcher { display: flex; gap: 8px; flex-wrap: wrap; }
.ws-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
}
.ws-btn.is-active {
  border-color: color-mix(in oklab, var(--accent) 45%, var(--border));
  background: color-mix(in oklab, var(--accent) 12%, var(--surface));
}

.global-search {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}

.topbar__right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  padding: 8px 12px;
}
.user-chip__name   { font-size: 13px; }
.user-chip__logout { font-size: 12px; color: var(--text-muted); text-decoration: none; }
.user-chip__logout:hover { color: var(--danger); }

.content-canvas {
  padding: 16px;
  min-width: 0;
}

/* Page header */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.page-title { margin: 0; font-size: 20px; }
.page-subtitle { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }

.action-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
.btn-primary {
  border-color: color-mix(in oklab, var(--accent) 40%, var(--border));
  background: color-mix(in oklab, var(--accent) 12%, var(--surface));
}

/* GridStack cards */
.grid-stack {
  background: transparent;
  min-height: 500px;
}

.grid-stack-item-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.widget-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  background: color-mix(in oklab, var(--surface) 85%, var(--surface-2));
}

.widget-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.widget-actions { display: flex; gap: 6px; }
.widget-actions button {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  border-radius: 8px;
  width: 28px;
  height: 28px;
  cursor: pointer;
}

.widget-body {
  padding: 12px;
  min-height: 80px;
}

.kpi {
  display: grid;
  gap: 6px;
}
.kpi__label { color: var(--text-muted); font-size: 12px; }
.kpi__value { font-weight: 700; font-size: 24px; letter-spacing: -.02em; }
.kpi__meta { color: var(--text-muted); font-size: 12px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.badge--success { color: #065f46; background: #ecfdf5; border-color: #a7f3d0; }
.badge--warning { color: #92400e; background: #fffbeb; border-color: #fde68a; }
.badge--danger { color: #991b1b; background: #fef2f2; border-color: #fecaca; }

html[data-theme="dark"] .badge--success { color: #a7f3d0; background: rgba(16,185,129,.1); border-color: rgba(16,185,129,.25); }
html[data-theme="dark"] .badge--warning { color: #fde68a; background: rgba(245,158,11,.08); border-color: rgba(245,158,11,.25); }
html[data-theme="dark"] .badge--danger { color: #fecaca; background: rgba(239,68,68,.08); border-color: rgba(239,68,68,.25); }

.save-indicator {
  font-size: 12px;
  color: var(--text-muted);
}
.save-indicator.is-saving { color: var(--warning); }
.save-indicator.is-saved { color: var(--success); }

/* Responsive */
@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 78px 1fr; }
  .brand-meta, .side-nav__item { font-size: 0; }
  .brand-logo { margin-inline: auto; }
  .side-nav__item { min-height: 40px; }
}
@media (max-width: 768px) {
  .topbar { grid-template-columns: 1fr; height: auto; }
}
/* === DataTable === */
.dt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.dt-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface) 86%, var(--surface-2));
  flex-wrap: wrap;
}

.dt-toolbar__left, .dt-toolbar__right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.dt-search, .dt-filter, .dt-saved-views {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 36px;
}

.dt-search { min-width: 240px; }

.dt-table-wrap {
  overflow: auto;
  max-height: calc(100vh - 240px);
}

.dt-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 980px;
}

.dt-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  color: var(--text-muted);
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.dt-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: top;
}

.dt-row[data-clickable="1"] { cursor: pointer; }
.dt-row[data-clickable="1"]:hover { background: color-mix(in oklab, var(--accent) 4%, var(--surface)); }

.dt-table [data-hidden="1"] { display: none; }
.dt-empty { text-align: center; color: var(--text-muted); padding: 20px; }

.dt-column-menu-wrap { position: relative; }
.dt-column-menu {
  position: absolute;
  right: 0;
  top: 42px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 8px;
  min-width: 180px;
  z-index: 20;
}
.dt-column-menu__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  font-size: 13px;
}

/* === Right drawer === */
.detail-drawer {
  position: fixed;
  top: 64px;
  right: 0;
  width: min(720px, 95vw);
  height: calc(100vh - 64px);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 30px rgba(0,0,0,.12);
  transform: translateX(100%);
  transition: transform .2s ease;
  z-index: 70;
  display: grid;
  grid-template-rows: auto auto 1fr;
}
.detail-drawer.is-open { transform: translateX(0); }

.detail-drawer__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.detail-drawer__title { margin: 0; font-size: 16px; }
.detail-drawer__sub { color: var(--text-muted); font-size: 12px; }

.detail-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.detail-tab {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 10px;
  cursor: pointer;
  white-space: nowrap;
  font-size: 12px;
}
.detail-tab.is-active {
  border-color: color-mix(in oklab, var(--accent) 40%, var(--border));
  background: color-mix(in oklab, var(--accent) 12%, var(--surface));
}

.detail-drawer__body {
  overflow: auto;
  padding: 14px;
}
.detail-section {
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 12px;
  overflow: hidden;
}
.detail-section__head {
  padding: 10px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
}
.detail-section__body {
  padding: 12px;
}
.kv-grid {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 8px 12px;
}
.kv-label { color: var(--text-muted); font-size: 12px; }
.kv-value { font-size: 13px; }

/* ================================================================
 * Dashboard — extended components
 * ================================================================ */

/* ── Preview banner ──────────────────────────────────────────── */
.preview-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: color-mix(in oklab, var(--warning) 8%, var(--surface));
  border: 1px solid color-mix(in oklab, var(--warning) 30%, var(--border));
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.preview-banner__icon { color: var(--warning); }
.preview-banner__err  { color: var(--warning); margin-left: auto; }

/* ── Edit layout toggle button ───────────────────────────────── */
.btn--edit-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
}
.btn--edit-toggle.is-active {
  border-color: color-mix(in oklab, var(--accent) 50%, var(--border));
  background:   color-mix(in oklab, var(--accent) 14%, var(--surface));
  color:        var(--accent);
}
.edit-toggle__icon { font-size: 14px; line-height: 1; }

/* ── Hidden widgets restore bar ──────────────────────────────── */
.hidden-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  background: color-mix(in oklab, var(--info) 6%, var(--surface));
  border: 1px solid color-mix(in oklab, var(--info) 25%, var(--border));
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  margin-bottom: 10px;
  font-size: 12px;
}
.hidden-bar__label {
  color: var(--text-muted);
  margin-right: 4px;
}
.hidden-bar__btn {
  border: 1px solid color-mix(in oklab, var(--info) 30%, var(--border));
  background: color-mix(in oklab, var(--info) 8%, var(--surface));
  color: var(--info);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11px;
  cursor: pointer;
  transition: background .12s ease;
}
.hidden-bar__btn:hover {
  background: color-mix(in oklab, var(--info) 16%, var(--surface));
}

/* ── KPI card improvements ───────────────────────────────────── */
.kpi { display: flex; flex-direction: column; gap: 5px; height: 100%; }
.kpi__label { color: var(--text-muted); font-size: 12px; font-weight: 500; }
.kpi__value { font-weight: 700; font-size: 26px; letter-spacing: -.03em; }
.kpi__value--status { font-size: inherit; }
.kpi__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
}
.kpi__meta  { color: var(--text-muted); font-size: 12px; }
.kpi__trend { font-size: 11px; font-weight: 600; }
.kpi__trend--up   { color: var(--success); }
.kpi__trend--down { color: var(--danger);  }

/* ── Widget body fills card height ──────────────────────────── */
.widget-body { padding: 12px; flex: 1; min-height: 0; overflow: hidden; }

/* ── Icon action buttons ──────────────────────────────────────*/
.icon-action {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  border-radius: 8px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .12s ease, color .12s ease;
}
.icon-action:hover {
  background: color-mix(in oklab, var(--accent) 10%, var(--surface));
  color: var(--text);
  border-color: color-mix(in oklab, var(--accent) 30%, var(--border));
}

/* ── Chart widget ────────────────────────────────────────────── */
.chart-widget {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chart-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  flex-shrink: 0;
}
.chart-tab {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.chart-tab.is-active {
  border-color: color-mix(in oklab, var(--accent) 45%, var(--border));
  background:   color-mix(in oklab, var(--accent) 12%, var(--surface));
  color:        var(--accent);
}

.chart-panels { flex: 1; min-height: 0; position: relative; }
.chart-panel  { display: none; height: 100%; }
.chart-panel.is-active { display: block; }
.chart-panel canvas   { width: 100% !important; height: 100% !important; }

/* ── GridStack: ensure items fill cell height ────────────────── */
.grid-stack-item-content {
  inset: 4px !important;
  display: flex;
  flex-direction: column;
}

/* ── Floating tip bubbles ────────────────────────────────────── */
.tip-anchor {
  position: relative;
  display: inline-flex;   /* shrink-wraps the button */
}

.tip-bubble {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 200;
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,.14);
  padding: 12px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  /* entrance animation */
  animation: tipIn .22s ease both;
}

/* right-aligned variant — anchors to the right edge of its button */
.tip-bubble--left {
  left: auto;
  right: 0;
}

/* upward arrow */
.tip-bubble__arrow {
  position: absolute;
  top: -5px;
  left: 16px;
  width: 10px;
  height: 10px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
  transform: rotate(45deg);
  border-radius: 2px 0 0 0;
}
.tip-bubble--left .tip-bubble__arrow {
  left: auto;
  right: 16px;
}

.tip-bubble__title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.tip-bubble__text {
  margin: 0;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-muted);
}
.tip-bubble__text em { font-style: normal; font-weight: 600; color: var(--text); }

.tip-bubble__close {
  align-self: flex-end;
  border: 1px solid color-mix(in oklab, var(--accent) 40%, var(--border));
  background: color-mix(in oklab, var(--accent) 10%, var(--surface));
  color: var(--accent);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 2px;
  transition: background .12s ease;
}
.tip-bubble__close:hover {
  background: color-mix(in oklab, var(--accent) 18%, var(--surface));
}

/* hidden state */
.tip-bubble.is-dismissed {
  display: none;
}

@keyframes tipIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Widget title group (icon + label) ──────────────────────── */
.widget-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Alert / announcement bell icon ─────────────────────────── */
.widget-alert-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: color-mix(in oklab, var(--warning) 12%, var(--surface));
  border: 1px solid color-mix(in oklab, var(--warning) 30%, var(--border));
  flex-shrink: 0;
}
.widget-alert-icon__bell {
  font-size: 13px;
  line-height: 1;
  filter: saturate(1.2);
}

/* ── "+ New" announcement button in widget header ────────────── */
.ann-new-btn {
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  color: var(--accent) !important;
  border-color: color-mix(in oklab, var(--accent) 30%, var(--border)) !important;
  background: color-mix(in oklab, var(--accent) 8%, var(--surface)) !important;
}
.ann-new-btn:hover {
  background: color-mix(in oklab, var(--accent) 18%, var(--surface)) !important;
}

/* ── Announcements widget container ──────────────────────────── */
.ann-widget {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ── List ────────────────────────────────────────────────────── */
.ann-list {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── Individual announcement item ────────────────────────────── */
.ann-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.ann-item:last-child { border-bottom: none; }

/* Coloured left dot */
.ann-item__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
  flex-shrink: 0;
  margin-top: 5px;
}

.ann-item__content { flex: 1; min-width: 0; }

.ann-item__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.ann-item__snippet {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
  line-height: 1.4;
}

.ann-item__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 5px;
}

.ann-item__time {
  font-size: 10.5px;
  color: var(--text-muted);
}

.ann-item__type-badge {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .02em;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  text-transform: capitalize;
}

.ann-item__read {
  font-size: 10.5px;
  font-weight: 600;
  margin-left: auto;
}
.ann-read--good { color: var(--success); }
.ann-read--mid  { color: var(--warning); }
.ann-read--low  { color: var(--text-muted); }

/* ── Read-rate progress bar ──────────────────────────────────── */
.ann-read-bar {
  height: 3px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.ann-read-bar__fill {
  height: 100%;
  border-radius: 999px;
  transition: width .4s ease;
}
.ann-read-bar__fill.ann-read--good { background: var(--success); }
.ann-read-bar__fill.ann-read--mid  { background: var(--warning); }
.ann-read-bar__fill.ann-read--low  { background: var(--text-muted); }

/* ── Empty state ─────────────────────────────────────────────── */
.ann-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px 12px;
  color: var(--text-muted);
  text-align: center;
}
.ann-empty__icon { font-size: 28px; line-height: 1; }
.ann-empty p     { font-size: 13px; }
.ann-create-link {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}
.ann-create-link:hover { text-decoration: underline; }

/* ── Footer "View all" link ──────────────────────────────────── */
.ann-footer {
  padding: 8px 0 2px;
  border-top: 1px solid var(--border);
  margin-top: auto;
  flex-shrink: 0;
}
.ann-footer__link {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: opacity .15s;
}
.ann-footer__link:hover { opacity: .75; }

/* ── Responsive: stack toolbar on narrow screens ─────────────── */
@media (max-width: 640px) {
  .page-head { flex-direction: column; align-items: flex-start; }
  .action-row { flex-wrap: wrap; }
  .tip-bubble, .tip-bubble--left { left: 0; right: auto; width: 220px; }
}