/* ════════════════════════════════════════════════════════════════
   Jsimple Dashboard — styles.css
   Brand tokens are isolated in :root / [data-theme] blocks below.
   To match the core site exactly, replace these values with the
   real CSS variables — nothing else in the file needs to change.
   ════════════════════════════════════════════════════════════════ */

:root {
  --brand-cyan: #1BA8E8;        /* the J */
  --brand-cyan-strong: #1391cc;

  /* Light mode (default) */
  --bg:           #f6f8fa;
  --surface:      #ffffff;
  --surface-2:    #f0f3f6;
  --border:       rgba(14, 23, 38, 0.12);
  --border-strong:rgba(14, 23, 38, 0.22);
  --text:         #0E1726;
  --text-2:       #56627a;
  --text-3:       #8b95a8;
  --accent:       var(--brand-cyan);
  --accent-soft:  rgba(27, 168, 232, 0.10);
  --danger:       #d8453b;
  --danger-soft:  rgba(216, 69, 59, 0.10);
  --success:      #1d9e75;
  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 1px 2px rgba(14,23,38,0.04), 0 6px 24px rgba(14,23,38,0.06);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg:           #0b1018;
  --surface:      #121a26;
  --surface-2:    #0f1722;
  --border:       rgba(255,255,255,0.10);
  --border-strong:rgba(255,255,255,0.20);
  --text:         #eef2f7;
  --text-2:       #9aa6b8;
  --text-3:       #6b7689;
  --accent:       var(--brand-cyan);
  --accent-soft:  rgba(27, 168, 232, 0.16);
  --danger:       #ef6a61;
  --danger-soft:  rgba(239,106,97,0.14);
  --success:      #34c896;
  --shadow:       0 1px 2px rgba(0,0,0,0.3), 0 8px 30px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }

/* ── Top bar ───────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.logo { height: 26px; display: block; }
.logo-dark { display: none; }
[data-theme="dark"] .logo-light { display: none; }
[data-theme="dark"] .logo-dark  { display: block; }
.topbar-spacer { flex: 1; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid var(--border);
  color: var(--text-2); font-size: 16px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: 13.5px; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn-primary {
  background: var(--accent); border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--brand-cyan-strong); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }

/* ── Layout shell ──────────────────────────────────────────────── */
.page { max-width: 1080px; margin: 0 auto; padding: 24px; }

/* ── Source bar ────────────────────────────────────────────────── */
.sourcebar {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 20px;
  font-size: 13px; color: var(--text-2);
}
.sourcebar select {
  background: var(--surface); border: 1px solid var(--border-strong);
  color: var(--text); border-radius: var(--radius-sm); padding: 5px 8px; font-size: 13px;
}

/* ── Dashboard title input ─────────────────────────────────────── */
.dash-title-input {
  font-size: 18px; font-weight: 600; color: var(--text);
  background: transparent; border: none; outline: none;
  border-bottom: 1px solid transparent; padding: 2px 0; min-width: 200px;
}
.dash-title-input:focus { border-bottom-color: var(--accent); }
.dash-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ── Sections & layout engine ──────────────────────────────────── */
.section { margin-bottom: 14px; }
.section-row {
  display: grid; gap: 12px;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
}
@media (max-width: 640px) {
  .section-row { grid-template-columns: 1fr; }  /* collapse on mobile */
}

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; position: relative;
  box-shadow: var(--shadow);
}
.card-title { font-size: 14px; font-weight: 600; color: var(--text); margin: 0 0 2px; }
.card-caption { font-size: 12px; color: var(--text-3); margin: 0 0 10px; }
.card-actions {
  position: absolute; top: 10px; right: 10px; display: flex; gap: 4px;
  opacity: 0; transition: opacity .12s;
}
.card:hover .card-actions { opacity: 1; }
.mini-btn {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center;
}
.mini-btn:hover { background: var(--surface-2); color: var(--text); }
.chart-wrap { position: relative; width: 100%; min-height: 180px; }

/* rich-text block (read view) */
.richtext-view { font-size: 14.5px; color: var(--text); line-height: 1.6; }
.richtext-view h1, .richtext-view h2, .richtext-view h3 { color: var(--text); margin: 0 0 6px; }

/* ── Add bar ───────────────────────────────────────────────────── */
.addbar { display: flex; gap: 10px; margin-top: 6px; }
.add-tile {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  padding: 12px; color: var(--text-2); font-size: 13px; background: transparent;
}
.add-tile:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.add-tile.primary { color: var(--accent); border-color: var(--accent); }

.section-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-3); margin-bottom: 8px; display: flex; align-items: center; gap: 8px;
}

/* ── Modal / panels ────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 16px; z-index: 100; overflow-y: auto;
}
.panel {
  width: 100%; max-width: 560px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.panel-head { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.panel-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.field-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: var(--text-2); margin: 14px 0 6px;
}
.field-label .hint { margin-left: auto; font-weight: 400; color: var(--text-3); }

.text-input, .sql-input {
  width: 100%; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 9px 11px; font-size: 14px; outline: none;
}
.text-input:focus, .sql-input:focus { border-color: var(--accent); }
.sql-input { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; resize: vertical; min-height: 96px; white-space: pre; }

.status-line { font-size: 11.5px; margin-top: 6px; }
.status-ok { color: var(--success); }
.status-err { color: var(--danger); }

.type-row { display: flex; gap: 6px; flex-wrap: wrap; }
.type-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 6px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
}
.type-chip.sel { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.type-chip.poor { opacity: 0.55; }
.type-chip .fit { opacity: 0.7; font-size: 11px; }

.swatches { display: flex; gap: 8px; align-items: center; }
.swatch { width: 30px; height: 30px; border-radius: var(--radius-sm); border: 2px solid transparent; cursor: pointer; }
.swatch.sel { border-color: var(--text); }

.panel-foot {
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid var(--border); padding-top: 14px; margin-top: 18px;
}
.panel-foot .spacer { flex: 1; }

/* ── Dashboards list ───────────────────────────────────────────── */
.list-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 8px;
  text-align: left; width: 100%;
}
.list-row:hover { border-color: var(--accent); }
.list-icon {
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0;
}
.list-name { font-size: 14px; font-weight: 600; }
.list-meta { font-size: 12px; color: var(--text-3); }

.empty {
  text-align: center; padding: 48px 24px; color: var(--text-3);
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
}

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px;
  border-radius: var(--radius-sm); font-size: 13px; z-index: 200;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }

.hidden { display: none !important; }

/* Quill dark-mode adjustments */
[data-theme="dark"] .ql-toolbar.ql-snow,
[data-theme="dark"] .ql-container.ql-snow { border-color: var(--border) !important; }
[data-theme="dark"] .ql-snow .ql-stroke { stroke: var(--text-2); }
[data-theme="dark"] .ql-snow .ql-fill { fill: var(--text-2); }
[data-theme="dark"] .ql-snow .ql-picker { color: var(--text-2); }
[data-theme="dark"] .ql-editor { color: var(--text); }
.ql-container { font-family: var(--sans); font-size: 14.5px; }
.ql-editor { min-height: 90px; }
