/* ==========================================================================
   TaskFlow — design system (Pass 1)
   Sections: tokens · base · auth · layout · sidebar · topbar · cards ·
             buttons · forms · alerts · toasts · skeleton · responsive
   ========================================================================== */

/* ------------------------------- Tokens -------------------------------- */

:root {
  --primary:        #4f46e5;
  --primary-hover:  #4338ca;
  --primary-soft:   rgba(79, 70, 229, .14);
  --bg:             #f3f4f6;
  --surface:        #ffffff;
  --surface-2:      #f9fafb;
  --text:           #111827;
  --text-muted:     #6b7280;
  --border:         #e5e7eb;
  --hover:          rgba(17, 24, 39, .06);
  --danger:         #dc2626;
  --danger-soft:    #fef2f2;
  --success:        #16a34a;
  --success-soft:   #f0fdf4;
  --warning:        #d97706;
  --warning-soft:   #fffbeb;
  --sidebar-bg:     #ffffff;
  --band-bg:        linear-gradient(180deg, #e6e9ff 0%, #dfe3fd 100%);
  --band-edge:      rgba(79, 70, 229, .18);
  --band-surface:   rgba(255, 255, 255, .55);
  --band-border:    rgba(255, 255, 255, .7);
  --sidebar-w:      248px;
  --sidebar-wc:     68px;
  --radius:         12px;
  --radius-sm:      9px;
  --shadow-sm:      0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md:      0 8px 24px rgba(16, 24, 40, .10);
  --ring:           0 0 0 3px var(--primary-soft);
  color-scheme: light;
}

[data-theme="dark"] {
  --primary:        #6366f1;
  --primary-hover:  #818cf8;
  --primary-soft:   rgba(99, 102, 241, .22);
  --bg:             #0f1115;
  --surface:        #171a21;
  --surface-2:      #1e222b;
  --text:           #e5e7eb;
  --text-muted:     #9ca3af;
  --border:         #2a2f3a;
  --hover:          rgba(229, 231, 235, .07);
  --danger:         #f87171;
  --danger-soft:    rgba(248, 113, 113, .12);
  --success:        #4ade80;
  --success-soft:   rgba(74, 222, 128, .12);
  --warning:        #fbbf24;
  --warning-soft:   rgba(251, 191, 36, .12);
  --sidebar-bg:     #14171d;
  --band-bg:        linear-gradient(180deg, #262244 0%, #1c1930 100%);
  --band-edge:      rgba(99, 102, 241, .28);
  --band-surface:   rgba(23, 26, 33, .55);
  --band-border:    rgba(255, 255, 255, .08);
  --shadow-sm:      0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md:      0 8px 24px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

/* -------------------------------- Base --------------------------------- */

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  transition: background-color .2s ease, color .2s ease;
}

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

h1, h2, h3 { margin: 0; line-height: 1.25; }

button { font: inherit; color: inherit; }

svg { display: block; }

[hidden] { display: none !important; }

::selection { background: var(--primary-soft); }

.text-muted { color: var(--text-muted); }

/* -------------------------------- Auth ---------------------------------- */
/* Standalone centered-card pages (login / register).                       */

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
  padding: 28px;
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 4px;
  font-size: 20px;
  font-weight: 800;
}

.auth-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 20px;
}

/* Friendly error pages (403.php / 404.php) */
.error-card { text-align: center; }
.error-code {
  font-size: 56px;
  font-weight: 800;
  letter-spacing: 0.04em;
  margin: 12px 0 4px;
  color: var(--primary, #4f46e5);
}

.auth-alt {
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
  margin: 18px 0 0;
}

.demo-hint {
  text-align: center;
  margin-top: 16px;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

/* -------------------------------- Layout -------------------------------- */

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

.main {
  flex: 1;
  min-width: 0;               /* lets grid children shrink properly */
  display: flex;
  flex-direction: column;
}

.content {
  flex: 1;
  width: 100%;
  /* No max-width cap: on widescreen monitors the dashboard uses the full
     window width (the 24px side padding stays as the only gutter). */
  margin: 0 auto;
  padding: 24px;
}

/* ------------------------------- Sidebar -------------------------------- */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;           /* clips labels during the width transition */
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  transition: width .22s ease, transform .25s ease;
  z-index: 40;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
}
.sidebar-logo:hover { text-decoration: none; }

.logo-mark {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
}
.logo-mark svg { width: 20px; height: 20px; }

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
}
.nav-link svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-link:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }

.nav-text { transition: opacity .15s ease; }

.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
}

.avatar {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
}

.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-name {
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: capitalize;
}

.logout-form { margin: 0; }
.logout-btn { color: var(--text-muted); }
.logout-btn:hover { color: var(--danger); }

/* Collapsed sidebar — desktop only. State lives on <html> (set by JS and
   restored pre-paint from localStorage). The .nav-text span is REMOVED from
   the flex layout (not just faded): with gap:12px an invisible label still
   ate width and shoved every icon off-center. */
@media (min-width: 768px) {
  html.sidebar-collapsed .sidebar { width: var(--sidebar-wc); }
  html.sidebar-collapsed .nav-text { display: none; }
  html.sidebar-collapsed .nav-link {
    justify-content: center;
    gap: 0;
    padding-left: 0;
    padding-right: 0;
  }
  html.sidebar-collapsed .sidebar-logo {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
  }
  html.sidebar-collapsed .sidebar-user { justify-content: center; padding: 6px 0; }
}

/* Mobile: sidebar becomes an overlay drawer with a backdrop. */
.sidebar-backdrop { display: none; }

@media (max-width: 767.98px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-w) !important;
    transform: translateX(-105%);
    box-shadow: var(--shadow-md);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }

  /* Ignore the collapsed state on mobile — the drawer is either open or closed. */
  html.sidebar-collapsed .nav-text { display: inline; }
  html.sidebar-collapsed .nav-link {
    justify-content: flex-start;
    gap: 12px;
    padding-left: 10px;
    padding-right: 10px;
  }
  html.sidebar-collapsed .sidebar-logo { justify-content: flex-start; padding: 16px; }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
    z-index: 39;
  }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
}

/* -------------------------------- Topbar -------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-title { flex: 1; font-size: 18px; font-weight: 800; }

.topbar-actions { display: flex; align-items: center; gap: 6px; }

/* Theme toggle: show the icon for the theme you'd switch TO. */
[data-theme="light"] .icon-sun  { display: none; }
[data-theme="dark"]  .icon-moon { display: none; }

/* ------------------------------ Card grid ------------------------------- */

/* Free-form layout: cards sit DIRECTLY in a 3-column grid. Placement comes
   from inline grid-column-start (set per card by the layout editor), which
   is also what makes real spanning possible: a wide card's grid-column is
   clamped to the available room (span 2 from column 2, span 3 from columns
   1–2), so a card can never stretch past the grid or start a phantom row. */
.cards {
  display: grid;
  /* --cols is set inline by dashboard.php / share.php when the dashboard has
     a FIXED column count (1–9); otherwise the no-JS fallback stays 3-wide
     and the masonry engine guesses a good count from the screen width. */
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
  gap: 16px;
  align-items: start;
  /* The column preview overlay (picker + drag highlight) anchors here. */
  position: relative;
  /* Dense packing: cards keep moving forward only when an explicitly-placed
     item conflicts with already-placed ones. Without it, a span-2 card in
     column 0 pushes every later single-column card a row down instead of
     letting them backfill the free track beside the wide card. */
  grid-auto-flow: dense;
}

/* The empty-state message spans the full width. */
.cards > .empty-state { grid-column: 1 / -1; }

/* Two-column tablet fallback (no-JS only — the JS engine guesses the track
   count from the real width or uses the dashboard's fixed column count). */
@media (max-width: 1100px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Phone fallback: single column — JS flattens placement to source order. */
@media (max-width: 640px) {
  .cards { grid-template-columns: minmax(0, 1fr); }
}

/* ------------------------------------------------------------------------
   Column preview overlay: purple dashed column tracks shown on top of the
   grid while picking a dashboard width, flashing after a change, and during
   card drag & drop (with the hovered column "hot"). Same look as the
   drop placeholder. Inserted by dashboard.js as the grid's last child.
   --------------------------------------------------------------------- */
.cols-preview {
  position: absolute;
  inset: 0;
  display: flex;
  pointer-events: none;
  z-index: 6;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.cols-preview.show { opacity: 1; }
.cols-preview > span {
  flex: 1 1 0;
  min-width: 0;
  border: 2px dashed var(--primary);
  background: var(--primary-soft);
  border-radius: var(--radius);
}
.cols-preview > span.hot {
  border-style: solid;
  background: rgba(79, 70, 229, 0.20);
}

/* ------------------------------------------------------------------------
   Dashboard columns picker (dashbar). Without JS it is a plain select +
   Apply button; with JS a toggle button + popover of numbered choices.
   --------------------------------------------------------------------- */
.dash-cols { position: relative; }
.dash-cols .dash-cols-label { font-size: 13px; color: var(--text-muted); }
.dash-cols select { width: auto; padding: 5px 8px; }
.dash-cols .cols-toggle { display: none; }
.dash-cols.dash-cols--js .cols-toggle { display: inline-flex; }
.dash-cols.dash-cols--js select,
.dash-cols.dash-cols--js [data-cols-apply],
.dash-cols.dash-cols--js .dash-cols-label { display: none; }

.cols-pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 80;
  width: 220px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.cols-pop-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cols-pop-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.cols-pop-grid button {
  height: 34px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  color: var(--text);
}
.cols-pop-grid button:hover { border-color: var(--primary); color: var(--primary); }
.cols-pop-grid button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.cols-pop-grid .cols-auto { grid-column: 1 / -1; }

/* Small screens: anchor the popover to the form's LEFT edge so it never
   spills past the viewport. */
@media (max-width: 768px) {
  .cols-pop { right: auto; left: 0; }
}

/* Drag affordances (the layout editor uses pointer-based dragging). */
.drag-handle { cursor: grab; touch-action: none; }

.module-card.card-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  opacity: 0.92;
  margin: 0;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  transform: rotate(1.2deg);
}

.module-card.card-placeholder {
  border: 2px dashed var(--primary);
  background: var(--primary-soft);
  box-shadow: none;
  min-height: 56px;
}

.module-card.card-placeholder > * { visibility: hidden; }

/* ==========================================================================
   Masonry layout (JS-enhanced) — independent column stacks.
   The grid above remains the no-JS fallback; once dashboard.js measures the
   cards it switches the container to absolute positioning, where every
   column stacks its cards directly below each other (no cross-column row
   coupling) and wide cards form bands.
   ========================================================================== */

.cards--masonry {
  display: block;
  position: relative;
}

.cards--masonry .module-card {
  position: absolute;
  top: 0;
  margin: 0;
}

/* Enabled only after the first layout, so later reflows glide. */
.cards--animate .module-card {
  transition: top 0.18s ease, left 0.18s ease, width 0.18s ease;
}

.module-card.card-ghost { transition: none !important; }

.card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* Content containment: a card holds its allocated grid space — text wraps,
   code/URLs break, media scales down. Unbreakable leftovers are reported
   by the layout engine, which widens the card's span (or the layout's
   effective track count) instead of letting anything spill. */
.module-card .card-body { overflow-x: hidden; }
.module-card .card-body pre,
.module-card .card-body code { overflow-wrap: anywhere; white-space: pre-wrap; }
.module-card .card-body img,
.module-card .card-body video,
.module-card .card-body canvas { max-width: 100%; }

/* While the layout engine measures a card's min-content width, containment
   must not hide the spill it is measuring. Canvas stays clamped: a Chart.js
   canvas re-renders to fit any width (responsive), so its intrinsic size is
   just the last rendered pixel size — treating it as min-content would
   inflate the card's floor every time it grows. */
/* No transitions while measuring: .cards--animate transitions width, and a
   synchronous scrollWidth read would then see the OLD painted width (the
   transition's start value) instead of width:0 — and scrollWidth never
   reports less than the box itself. The measured floor could only ever
   ratchet up, so cards would widen but never shrink. */
.module-card.min-measure { transition: none !important; }
/* Whole-pass suppression: measuring flips a card's width to 0 and back
   inside layoutNow. Class-local suppression (min-measure) ends before the
   pass finishes, and Firefox then animates the restore — pass 2 measures
   heights at the transition's start width and the RO chases the animation
   frame by frame (a running pomodoro made the card wobble every second). */
.cards--noanim .module-card { transition: none !important; }
.module-card.min-measure .card-body { overflow: visible; }
.module-card.min-measure .card-body img,
.module-card.min-measure .card-body video { max-width: none; }

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.card-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
}
.card-icon svg { width: 16px; height: 16px; }

.card-title {
  flex: 1;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-actions { display: flex; gap: 2px; }
.card-actions .icon-btn { width: 28px; height: 28px; }
.card-actions .icon-btn svg { width: 15px; height: 15px; }

.card-body { flex: 1; padding: 14px; }

/* Empty state (also reused by placeholder pages) */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 64px 24px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-state h2 { font-size: 18px; margin: 14px 0 6px; }
.empty-state p {
  max-width: 480px;
  margin: 0 auto 18px;
  color: var(--text-muted);
}
.empty-state .btn { text-decoration: none; }
.empty-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
}
.empty-icon svg { width: 26px; height: 26px; }

/* ------------------------------- Buttons -------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--hover); text-decoration: none; }

.btn-danger { background: var(--danger); color: #fff; }

.btn-block { width: 100%; }

.btn-sm {
  padding: 5px 10px;
  font-size: 12.5px;
  gap: 6px;
}

/* "keep data" checkbox next to uninstall buttons (library + admin) */
.keep-data { font-size: 12.5px; color: var(--text-muted); }

.icon-btn {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
/* Width toggle pinned at full width by its own min-content floor. */
.icon-btn:disabled { opacity: 0.4; cursor: default; }
.icon-btn:disabled:hover { background: transparent; color: var(--text-muted); }
.icon-btn svg { width: 18px; height: 18px; }

.btn:focus-visible,
.icon-btn:focus-visible,
.nav-link:focus-visible,
.input:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* -------------------------------- Forms --------------------------------- */

.field { margin-bottom: 14px; }

.label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
}

.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}

.form-error { margin: 5px 0 0; font-size: 12.5px; color: var(--danger); }
.form-hint  { margin: 5px 0 0; font-size: 12.5px; color: var(--text-muted); }

.radio-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: 18px;
  cursor: pointer;
}
.radio-inline input { accent-color: var(--primary); }

/* -------------------------------- Alerts -------------------------------- */

.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  margin-bottom: 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: opacity .3s ease;
}
.alert span { flex: 1; }

.alert-success {
  background: var(--success-soft);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
}
.alert-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}

.alert-close {
  border: 0;
  background: none;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  opacity: .7;
}
.alert-close:hover { opacity: 1; }

.alert-hide { opacity: 0; }

/* -------------------------------- Toasts -------------------------------- */

.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;   /* above drag ghosts (1000) and the chatbot (200) */
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: 14px;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .25s ease, transform .25s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

.toast-success { border-left-color: var(--success); }
.toast-error   { border-left-color: var(--danger); }
.toast-info    { border-left-color: var(--primary); }

.toast-msg { flex: 1; }

.toast-close {
  border: 0;
  background: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
}

/* ------------------------------- Skeleton ------------------------------- */
/* Shown while the card grid initializes. Without JS, the skeleton is hidden
   and the real grid is shown instead (see the html:not(.js) rules).        */

html:not(.js) .cards-skeleton { display: none; }
html.js .cards-swap { display: none; }

.skeleton-card .card-body { display: flex; flex-direction: column; gap: 10px; }

.sk-block {
  display: block;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--hover) 25%, var(--surface-2) 37%, var(--hover) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
.sk-icon { width: 28px; height: 28px; border-radius: 8px; }
.sk-line { height: 12px; }

.w-40 { width: 40%; }
.w-70 { width: 70%; }
.w-80 { width: 80%; }
.w-90 { width: 90%; }

@keyframes shimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* ------------------------------ Responsive ------------------------------ */

@media (max-width: 640px) {
  .content { padding: 16px; }
  .topband { margin: -16px -16px 14px; padding: 12px 16px; }
  .topbar  { padding: 10px 14px; }
  .topbar-title { font-size: 16px; }
  .empty-state { padding: 48px 16px; }
}

/* ==========================================================================
   Pass 2 — module engine UI
   ========================================================================== */

/* Drag handle on module cards */
.drag-handle { cursor: grab; touch-action: none; }
.drag-handle:active { cursor: grabbing; }

/* Card being dragged */
.module-card.dragging {
  opacity: .45;
  border-style: dashed;
}

/* Minimized card: header only */
.module-card.minimized .card-body { display: none; }

/* Error card shown when a module crashes (never breaks the grid) */
.module-error {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px;
  line-height: 1.5;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-success {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
  color: var(--success);
}
.badge-disabled {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 30%, transparent);
  color: var(--warning);
}

/* Library cards */
.lib-body { display: flex; flex-direction: column; gap: 10px; }
.lib-desc { margin: 0; color: var(--text-muted); font-size: 14px; }
.lib-meta { margin: 0; font-size: 12.5px; color: var(--text-muted); }

.lib-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}
.lib-actions form { margin: 0; display: inline-flex; align-items: center; gap: 8px; }
.lib-uninstall .keep-data { font-size: 12.5px; color: var(--text-muted); margin-right: 0; }

/* Stacked cards on plain content pages (admin, settings) get breathing room
   — the dashboard grid handles its own gaps, these siblings had none. */
.content > .card + .card { margin-top: 18px; }

/* ------------------------- Library refine toolbar ---------------------- */
.lib-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
}
.lib-toolbar [data-lib-search] { flex: 1 1 200px; max-width: 360px; }
.lib-toolbar [data-lib-filter] { width: auto; }
.lib-view-toggle span { display: inline-flex; align-items: center; gap: 6px; }
.lib-view-toggle svg { width: 14px; height: 14px; }

/* Compact library grid: auto-fill tracks of ≥280 px — about 6 across on an
   ultrawide, stepping down through desktop/tablet to a single column on
   phones (overrides the dashboard's fixed 3/2/1 .cards columns). */
.cards.lib-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* Cap the grid at 7 columns on very wide screens (7×280 + 6×16 px gaps). */
@media (min-width: 2056px) {
  .cards.lib-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }
}
.lib-grid .card-body { padding: 12px 14px; }
.lib-grid .lib-body { gap: 8px; }
.lib-grid .lib-desc { font-size: 13px; }

/* Smaller library controls (both views). */
.lib-actions .btn { padding: 4px 10px; font-size: 12px; }
.lib-actions .input-sm { padding: 4px 6px; font-size: 12px; }
.lib-actions form { gap: 6px; }

/* Library table view (the refine toolbar filters its rows too). */
.lib-table-wrap { overflow-x: auto; }
.lib-table td { vertical-align: top; }
.lib-table-desc { max-width: 340px; color: var(--text-muted); font-size: 13px; }
.lib-table-icon svg { width: 16px; height: 16px; vertical-align: -3px; }
.lib-table .lib-actions { border-top: 0; padding-top: 0; margin-top: 4px; }

/* Sortable column headers. */
.lib-table th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
.lib-table th[data-sort]:hover { color: var(--primary); }
.lib-table th.sort-asc::after { content: ' ▲'; font-size: 9px; }
.lib-table th.sort-desc::after { content: ' ▼'; font-size: 9px; }

/* Upload drop zone */
.upload-drop {
  padding: 18px;
  margin-bottom: 14px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.upload-drop:hover { border-color: var(--primary); }
.upload-drop.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.upload-drop input[type="file"] {
  /* the native control stays for no-JS, but tucked out of the way */
  margin-bottom: 8px;
  font-size: 12.5px;
}
.upload-drop-hint {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}
.upload-files {
  list-style: none;
  margin: 10px 0 0;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.upload-warn { color: var(--warning); }

.upload-access {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 0 0 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.upload-access legend {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0 6px;
}

.upload-results {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.upload-result {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  border: 1px solid var(--border);
}
.upload-result.ok   { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.upload-result.fail { background: var(--danger-soft);  border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.upload-result.warn { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 35%, transparent); flex-wrap: wrap; }
.upload-confirm { display: inline-flex; gap: 8px; margin-left: auto; }

/* Code blocks (package format docs on the upload page) */
.code-block {
  margin: 8px 0 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre;
}
.code-block em { color: var(--text-muted); font-style: normal; }

/* Installed-module list on the upload page */
.installed-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.installed-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

code {
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

/* ==========================================================================
   Wide module cards — handled by the per-card layout system above:
   wide-capable modules (kanban, calendar, stats) carry .module-card--wide2 /
   .module-card--wide3, and the layout editor assigns a clamped grid-column
   (inline) so spanning always works, from any column.
   ========================================================================== */

/* ==========================================================================
   Admin panel (Pass 5) — user table, module table, activity log, pager.
   ========================================================================== */

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.admin-table th,
.admin-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
}
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tr.is-inactive td { opacity: 0.55; }
.admin-table .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}
.admin-table .row-actions form { display: inline; }
.admin-meta {
  font-size: 12.5px;
  color: var(--text-muted);
  word-break: break-word;
}
.admin-meta code { word-break: break-all; }

/* Pager for the activity log */
.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
  font-size: 13.5px;
  color: var(--text-muted);
}

/* Tables scroll sideways on narrow screens instead of crushing the layout */
.table-scroll { overflow-x: auto; }

@media (max-width: 640px) {
  .admin-table th, .admin-table td { padding: 7px 8px; font-size: 13px; }
}

/* ==========================================================================
   My Tasks page (my-tasks.php + assets/js/my-tasks.js)
   ========================================================================== */

.mt-page { display: flex; flex-direction: column; gap: 14px; }

.mt-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mt-pills { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.mt-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.mt-pill.active {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary);
}
.mt-count { font-size: 11.5px; opacity: .8; }

.mt-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.mt-select { width: auto; padding: 7px 10px; font-size: 13px; }
.mt-search { width: 190px; padding: 7px 10px; font-size: 13px; }

.mt-form-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}
.mt-edit-grid { grid-template-columns: 1fr 1fr 1fr 1fr; margin: 8px 0; }
.mt-form-actions { display: flex; gap: 8px; margin-top: 8px; }

.mt-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mt-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.mt-check {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  margin-top: 2px;
  border: 2px solid var(--border);
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: transparent;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.mt-check:hover { border-color: var(--primary); }
.mt-done .mt-check {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.mt-check::after {
  content: '';
  width: 12px;
  height: 12px;
  background: currentColor;
  clip-path: polygon(14% 46%, 0 62%, 40% 100%, 100% 18%, 86% 4%, 38% 72%);
}

.mt-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.mt-title { font-weight: 700; font-size: 14.5px; word-break: break-word; }
.mt-done .mt-title { text-decoration: line-through; color: var(--text-muted); }
.mt-desc { font-size: 13px; color: var(--text-muted); white-space: pre-wrap; word-break: break-word; }
.mt-badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 3px; }

.mt-cat-business { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.mt-cat-personal  { background: var(--surface-2); color: var(--text-muted); }

.mt-pri-high   { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.mt-pri-medium { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.mt-pri-low    { background: var(--surface-2); color: var(--text-muted); }

.mt-due-overdue { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.mt-due-today   { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.mt-due-soon    { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

.mt-status-open        { background: var(--surface-2); color: var(--text-muted); }
.mt-status-in_progress { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.mt-status-done        { background: var(--success-soft); color: var(--success); border-color: transparent; }

.mt-actions { display: flex; gap: 2px; flex-shrink: 0; }

.mt-edit { flex: 1; min-width: 0; }
.mt-edit .input { margin-bottom: 0; }

.mt-empty { color: var(--text-muted); font-size: 14px; padding: 12px 2px; }
.mt-error { margin: 0; font-size: 14px; color: var(--danger); }

@media (max-width: 900px) {
  .mt-form-grid { grid-template-columns: 1fr 1fr; }
  .mt-search { flex: 1; min-width: 140px; }
}

/* ==========================================================================
   Public share page (share.php) + shared-links list (modules.php) — Pass 6
   ========================================================================== */

.share-page {
  min-height: 100vh;
  background: var(--bg);
}
/* .share-wrap rides on .content's padding/max-width so the shared view
   matches the logged-in dashboard's gutters exactly */
.share-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.share-wrap:not(.share-wrap-wide) { max-width: 760px; margin: 0 auto; }
.share-top {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
}
.share-brand { font-weight: 800; font-size: 17px; color: var(--text); }
.share-top .logo-mark { width: 32px; height: 32px; }
.share-by { margin-left: auto; }
.share-foot {
  margin: 0;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
}
/* Share pages use the SAME masonry as the logged-in dashboard
   (assets/js/share-layout.js) — .cards--masonry positions the cards. */

.share-url {
  width: 100%;
  margin-top: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  padding: 6px 8px;
  cursor: text;
}

.input-sm { padding: 6px 8px; font-size: 12.5px; width: 200px; }

/* ------------------ Searchable selects (select2-lite) -------------------
   app.js enhances every <select> element: the source element is visually
   hidden (its value still submits), a filterable dropdown takes its place. */
select.s2-source {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0;
  pointer-events: none;
}
.s2 { position: relative; display: inline-block; }
.s2-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-width: 140px;
  cursor: pointer;
  text-align: left;
}
.s2-toggle:disabled { opacity: 0.5; cursor: default; }
.s2-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s2-chevron { flex-shrink: 0; display: inline-flex; color: var(--text-muted); }
.s2-drop {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 90;
  min-width: 100%;
  width: max-content;
  max-width: 300px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
.s2-search { width: 100%; min-width: 160px; }
.s2-list {
  display: flex;
  flex-direction: column;
  max-height: 220px;
  overflow-y: auto;
}
.s2-option {
  padding: 6px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.s2-option:hover,
.s2-option.active { background: var(--hover); }
.s2-option.selected { color: var(--primary); font-weight: 600; }
.s2-empty { padding: 6px 8px; color: var(--text-muted); font-size: 12px; }

@media (max-width: 640px) {
  .input-sm { width: 100%; }
}

/* ==========================================================================
   Dashboard tabs + dashboard share rows (Pass 7)
   ========================================================================== */

.dashbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

/* ==========================================================================
   Top band — unified dashboard/board toolbar. Full-bleed purple gradient:
   negative margins cancel .content's 24px gutter so the band runs corner
   to corner. Row 1: dashboard pills + action cluster. Row 2: board tabs.
   (The legacy .dashbar/.dash-tab styles above still serve pages that use
   them, e.g. modules/calendar/dashboard.php.)
   ========================================================================== */

.topband {
  background: var(--band-bg);
  border-bottom: 1px solid var(--band-edge);
  margin: -24px -24px 14px;
  padding: 14px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.band-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.band-main { justify-content: space-between; }

/* Segmented dashboard pills */
.seg {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--band-surface);
  border: 1px solid var(--band-border);
  border-radius: 999px;
  padding: 4px;
  box-shadow: var(--shadow-sm);
}
.seg-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}
.seg-pill:hover { color: var(--text); }
.seg-pill.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, .35);
}

/* Inline "add" pill: round + button + borderless input */
.seg-add,
.btab-add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 12px 3px 4px;
  border: 1.5px dashed rgba(79, 70, 229, .45);
  border-radius: 999px;
  color: var(--primary);
}
.seg-add input,
.btab-add input {
  border: 0;
  background: transparent;
  outline: none;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  width: 134px;
}
.seg-add input::placeholder,
.btab-add input::placeholder { color: rgba(79, 70, 229, .65); }
.seg-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex: none;
  border: 0;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.seg-add-btn:hover { background: var(--primary); color: #fff; }

/* Action cluster — quiet ghost group of icon forms */
.actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--band-surface);
  border: 1px solid var(--band-border);
  border-radius: 999px;
  padding: 4px;
  box-shadow: var(--shadow-sm);
}
.act {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.act:hover { background: var(--surface); color: var(--text); }
.act svg { width: 14px; height: 14px; flex: none; }
.act button {
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.act + .act { position: relative; }
.act + .act::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 22%;
  bottom: 22%;
  width: 1px;
  background: var(--border);
}
.act-mini {
  border: 0;
  border-bottom: 1px dashed var(--text-muted);
  background: transparent;
  outline: none;
  font: inherit;
  color: var(--text);
  width: 96px;
  padding: 1px 0;
}
.act-mini[type="email"] { width: 132px; }
.act select {
  border: 0;
  background: transparent;
  font: inherit;
  color: inherit;
  outline: none;
  cursor: pointer;
  width: auto;
  padding: 0;
  margin: 0;
}
.act-danger { color: #b91c1c; }
.act-danger:hover { background: var(--danger-soft); color: var(--danger); }
[data-theme="dark"] .act-danger { color: var(--danger); }

/* The JS columns toggle blends into the action cluster. */
.actions .cols-toggle {
  background: transparent;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: inherit;
}
.actions .cols-toggle:hover { background: transparent; }

/* Board tabs — second, lighter row */
.btabs { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.btab {
  display: inline-flex;
  align-items: center;
  padding: 5px 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}
.btab:hover { color: var(--text); background: var(--band-surface); }
.btab.active {
  background: var(--surface);
  border-color: var(--band-edge);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}
.btab-add { padding: 3px 12px 3px 4px; background: transparent; }
.btab-add input { width: 74px; }

/* Share-link bars: slim white pills under the band */
.sharebars {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: -4px 0 14px;
}
.sharebar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  box-shadow: var(--shadow-sm);
  font-size: 12.5px;
}
.share-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--primary);
  background: var(--primary-soft);
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 700;
  white-space: nowrap;
}
.share-tag svg { width: 12px; height: 12px; }
.share-for { color: var(--text-muted); white-space: nowrap; }
.sharebar .share-url {
  flex: 1;
  min-width: 180px;
  border: 0;
  background: transparent;
  outline: none;
  color: var(--text-muted);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover { background: var(--hover); }
.chip-danger { color: var(--danger); }
.chip-danger:hover { background: var(--danger-soft); }
.chip-form { display: inline-flex; }

.dash-tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.dash-tab {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-decoration: none;
  background: var(--surface);
}
.dash-tab:hover { color: var(--text); border-color: var(--primary); }
.dash-tab.active {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary);
}

.dash-new,
.dash-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.dash-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.dash-name-input {
  width: 130px;
  padding: 6px 9px;
  font-size: 12.5px;
}

.dash-shares {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: -6px 0 14px;
}
.dash-share-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.dash-share-row .share-url { flex: 1; min-width: 220px; width: auto; margin-top: 0; }
.dash-share-row .badge { display: inline-flex; align-items: center; gap: 5px; }
.dash-share-row .badge svg { width: 13px; height: 13px; }

/* Whole-dashboard share pages: no max-width cap — .content's full-width,
   24px-gutter box matches the logged-in dashboard exactly, so the shared
   grid (same .cards, same 16px gap, same percentage-based card widths)
   renders pixel-identical proportions. */

.lib-hint { margin: 0 0 12px; font-size: 13px; }

@media (max-width: 768px) {
  .dashbar { flex-direction: column; align-items: stretch; }
  .dash-actions { justify-content: flex-start; }
  .dash-name-input { width: 110px; }
}

/* ==========================================================================
   Boards — sub-dashboards (Pass 10). The board bar is a second-level tab
   strip under the dashboard tabs; section boards stack inline on the page,
   each with a titled header carrying its rename/move/delete forms.
   ========================================================================== */

.boardbar {
  margin: -6px 0 14px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.boardbar .dash-tab {
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 600;
}
.boardbar .dash-name-input { width: 110px; }

.board-section {
  margin-bottom: 22px;
  padding: 14px 16px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.board-section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}
.board-title { margin: 0; font-size: 15px; font-weight: 700; }
.board-head-form .dash-name-input { width: 110px; }

/* Section creation form: dashed pill matching the band's add-pills. */
.section-new {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  margin: -4px 0 16px;
  padding: 5px 6px 5px 16px;
  border: 1.5px dashed var(--border);
  border-radius: 999px;
  background: var(--surface);
}
.section-new input {
  border: 0;
  background: transparent;
  outline: none;
  font: inherit;
  font-size: 12.5px;
  color: var(--text);
  width: 110px;
}
.section-new input::placeholder { color: var(--text-muted); }
.section-new button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.section-new button:hover { background: var(--primary); color: #fff; }

/* Compact per-board empty note when several sections are stacked. */
.empty-state-compact { padding: 20px 16px; }
.empty-state-compact p { margin: 0; max-width: none; font-size: 13px; }

/* Shared pages stack every board (tabs included) with its title. */
.share-board-title { margin: 18px 0 10px; font-size: 15px; font-weight: 700; }
.share-board-title:first-of-type { margin-top: 0; }

/* ==========================================================================
   Module Generator page (module-generator.php)
   ========================================================================== */

.mg-page .card-header .card-actions { margin-left: auto; }

.mg-steps {
  margin: 0 0 10px;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

.mg-prompt,
.mg-after {
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12.5px;
  line-height: 1.55;
}

.mg-after { max-height: 260px; }

/* ==========================================================================
   AI chatbot widget — floating bubble + panel (api/chat.php, local LLM).
   ========================================================================== */
.chatbot { position: fixed; right: 20px; bottom: 20px; z-index: 200; }

.chat-bubble {
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow-md);
}
.chat-bubble:hover { background: var(--primary-hover); }
.chat-bubble svg { width: 24px; height: 24px; }

.chat-panel {
  position: absolute;
  right: 0;
  bottom: 64px;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 480px;
  max-height: calc(100vh - 110px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.chat-close {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.chat-close:hover { color: var(--text); }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-msg {
  max-width: 85%;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.chat-assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}
.chat-typing { color: var(--text-muted); font-style: italic; }

.chat-chip {
  align-self: flex-start;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 11.5px;
  font-weight: 600;
}
.chat-chip.error { background: var(--danger-soft, rgba(220,38,38,.12)); color: var(--danger); }

.chat-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}
.chat-form .input { flex: 1; }

@media (max-width: 640px) {
  .chatbot { right: 12px; bottom: 12px; }
  .chat-panel { width: calc(100vw - 24px); }
}
