/* CSV → Zulip Table — app-specific styles.
   Reuses the shared dark/light mechanism: light lives in :root, dark overrides
   under html[data-bs-theme="dark"] (set by js/theme.js). The extra `html` in the
   dark selector wins on specificity, so cascade order is safe.
   All colours are namespaced --cz-* so they never collide with other apps.   */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --cz-border: #cdd9ea;
  --cz-border-strong: #b6c5dc;
  --cz-panel-bg: #f6f9fc;
  --cz-strip-bg: #eaf0f7;
  --cz-surface: #ffffff;
  --cz-surface-2: #f0f5fa;
  --cz-input-bg: #ffffff;
  --cz-text: #1e2a3d;
  --cz-text-dim: #3c4c62;
  --cz-text-faint: #63748d;
  --cz-accent: #1d4ed8;
  --cz-accent-soft: #e6eefc;
  --cz-good: #059669;
  --cz-good-soft: #d7f5e5;
  --cz-warn: #b45309;
  --cz-scrollbar: #c0cde0;
}

html[data-bs-theme="dark"] {
  --cz-border: #1e2d4a;
  --cz-border-strong: #2a3d5e;
  --cz-panel-bg: #0e1422;
  --cz-strip-bg: #090d17;
  --cz-surface: #0b1020;
  --cz-surface-2: #0d1424;
  --cz-input-bg: #060a12;
  --cz-text: #d8e4f5;
  --cz-text-dim: #a9c0de;
  --cz-text-faint: #8296b5;
  --cz-accent: #60a5fa;
  --cz-accent-soft: #12233d;
  --cz-good: #34d399;
  --cz-good-soft: #052e16;
  --cz-warn: #fbbf24;
  --cz-scrollbar: #1e2d4a;
}

body {
  font-family: var(--bs-body-font-family);
  background: var(--cz-panel-bg);
  color: var(--cz-text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background 0.2s, color 0.2s;
}
.app-navbar { flex-shrink: 0; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.cz-main {
  display: grid;
  grid-template-columns: 46% 1fr;
  flex: 1;
  overflow: hidden;
}
@media (max-width: 820px) {
  .cz-main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; overflow: auto; }
  body { overflow: auto; height: auto; min-height: 100vh; }
}

.cz-input-panel {
  background: var(--cz-panel-bg);
  border-right: 1px solid var(--cz-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px;
  gap: 14px;
}
.cz-output-panel {
  background: var(--cz-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Dropzone ───────────────────────────────────────────────────────────── */
.cz-drop {
  border: 1.5px dashed var(--cz-border-strong);
  border-radius: 10px;
  background: var(--cz-surface-2);
  padding: 24px 18px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.cz-drop:hover { border-color: var(--cz-accent); }
.cz-drop:focus-visible { outline: 2px solid var(--cz-accent); outline-offset: 2px; }
.cz-drop.over { border-color: var(--cz-accent); background: var(--cz-accent-soft); }
.cz-drop .cz-drop-icon { font-size: 1.7rem; color: var(--cz-accent); }
.cz-drop p { margin: 8px 0 0; font-size: 0.85rem; color: var(--cz-text-dim); }
.cz-drop p b { color: var(--cz-accent); }
.cz-drop .cz-file-name {
  margin-top: 8px;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.75rem;
  color: var(--cz-good);
  word-break: break-all;
}

/* ── Options ────────────────────────────────────────────────────────────── */
.cz-opts { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: flex-end; }
.cz-opt { display: flex; flex-direction: column; gap: 5px; }
.cz-opt label {
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--cz-text-faint);
}
.cz-select {
  font-family: inherit; font-size: 0.82rem; color: var(--cz-text);
  background: var(--cz-input-bg); border: 1px solid var(--cz-border);
  border-radius: 6px; padding: 7px 10px; outline: none; cursor: pointer;
  transition: border-color 0.15s;
}
.cz-select:focus { border-color: var(--cz-accent); }
.cz-check {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  user-select: none; font-size: 0.85rem; color: var(--cz-text-dim);
}
.cz-check input { width: 16px; height: 16px; accent-color: var(--cz-accent); cursor: pointer; }

.cz-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cz-btn {
  font: inherit; font-size: 0.82rem; font-weight: 600;
  padding: 8px 15px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--cz-border); background: var(--cz-surface-2);
  color: var(--cz-text); transition: border-color 0.15s, background 0.15s;
}
.cz-btn:hover { border-color: var(--cz-border-strong); background: var(--cz-strip-bg); }

.cz-hint {
  font-size: 0.75rem; color: var(--cz-text-faint); line-height: 1.5;
  border-left: 3px solid var(--cz-border); padding-left: 10px;
}
.cz-hint code { font-family: 'Cascadia Code', 'Consolas', monospace; color: var(--cz-accent); }

/* ── Input-mode switch (Upload / Build) ─────────────────────────────────── */
.cz-seg {
  display: flex; border: 1px solid var(--cz-border);
  border-radius: 8px; overflow: hidden; background: var(--cz-surface-2);
}
.cz-seg-btn {
  flex: 1; font: inherit; font-size: 0.82rem; font-weight: 600;
  padding: 9px 12px; cursor: pointer; border: none; background: transparent;
  color: var(--cz-text-dim); display: inline-flex; align-items: center;
  justify-content: center; gap: 7px; transition: background 0.12s, color 0.12s;
}
.cz-seg-btn + .cz-seg-btn { border-left: 1px solid var(--cz-border); }
.cz-seg-btn.active { background: var(--cz-accent); color: #fff; }

/* ── Table builder grid ─────────────────────────────────────────────────── */
.cz-grid-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.cz-grid-tip { font-size: 0.72rem; color: var(--cz-text-faint); }
.cz-grid-tip [aria-hidden] { font-weight: 700; color: var(--cz-warn); }

.cz-grid-wrap { overflow: auto; border-radius: 8px; }
.cz-grid-wrap::-webkit-scrollbar { width: 6px; height: 6px; }
.cz-grid-wrap::-webkit-scrollbar-thumb { background: var(--cz-scrollbar); border-radius: 4px; }

.cz-grid-table { border-collapse: separate; border-spacing: 0; }
.cz-grid-table th, .cz-grid-table td { padding: 0; }
.cz-grid-table .cz-corner { width: 26px; }
.cz-grid-table .cz-colctl { text-align: center; padding-bottom: 3px; }
.cz-grid-table .cz-rowctl { width: 26px; text-align: center; padding-right: 3px; }

.cz-grid-table input {
  width: 100%; min-width: 92px; font: inherit; font-size: 0.8rem;
  color: var(--cz-text); background: var(--cz-input-bg);
  border: 1px solid var(--cz-border); padding: 7px 9px; outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.cz-grid-table input:focus {
  border-color: var(--cz-accent);
  box-shadow: 0 0 0 2px var(--cz-accent-soft); position: relative; z-index: 1;
}
.cz-grid-table input.cz-head-input { font-weight: 700; background: var(--cz-surface-2); }

.cz-cell-del {
  font: inherit; font-size: 0.85rem; line-height: 1; font-weight: 700;
  width: 20px; height: 20px; border-radius: 4px; cursor: pointer;
  border: 1px solid transparent; background: transparent; color: var(--cz-text-faint);
  transition: background 0.12s, color 0.12s;
}
.cz-cell-del:hover:not(:disabled) { background: var(--cz-good-soft); color: var(--cz-warn); }
.cz-cell-del:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Excel sheet picker (input) ─────────────────────────────────────────── */
.cz-sheets { margin-top: 12px; }
.cz-sheets-label {
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--cz-text-faint); margin-bottom: 7px;
}
.cz-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.cz-chip {
  font: inherit; font-size: 0.78rem; font-weight: 600; cursor: pointer;
  padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--cz-border); background: var(--cz-surface-2);
  color: var(--cz-text-dim); display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.cz-chip::before {
  content: "\2713";                         /* check — plain glyph, no icon font */
  font-weight: 900; font-size: 0.72rem; line-height: 1;
  opacity: 0; transition: opacity 0.12s;
}
.cz-chip.on {
  background: var(--cz-accent-soft); color: var(--cz-accent);
  border-color: var(--cz-accent);
}
.cz-chip.on::before { opacity: 1; }

/* ── Sheet tabs (output) ────────────────────────────────────────────────── */
.cz-sheet-bar {
  display: flex; gap: 4px; overflow-x: auto;
  padding: 8px 12px; border-bottom: 1px solid var(--cz-border);
  background: var(--cz-panel-bg); flex-shrink: 0;
}
.cz-sheet-bar::-webkit-scrollbar { height: 5px; }
.cz-sheet-bar::-webkit-scrollbar-thumb { background: var(--cz-scrollbar); border-radius: 4px; }
.cz-sheet-tab {
  font: inherit; font-size: 0.76rem; font-weight: 600; cursor: pointer;
  white-space: nowrap; padding: 5px 12px; border-radius: 6px 6px 0 0;
  border: 1px solid transparent; border-bottom: none; background: transparent;
  color: var(--cz-text-dim); transition: background 0.12s, color 0.12s;
}
.cz-sheet-tab:hover { background: var(--cz-surface-2); color: var(--cz-text); }
.cz-sheet-tab.active {
  background: var(--cz-surface); color: var(--cz-accent);
  border-color: var(--cz-border); font-weight: 700;
}

/* ── Output header ──────────────────────────────────────────────────────── */
.cz-out-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--cz-border);
  background: var(--cz-strip-bg); flex-shrink: 0;
}
.cz-tabs { display: flex; gap: 4px; }
.cz-tab {
  font: inherit; font-size: 0.78rem; font-weight: 600;
  padding: 6px 13px; border-radius: 6px; cursor: pointer;
  border: 1px solid transparent; background: transparent; color: var(--cz-text-dim);
  transition: background 0.12s, color 0.12s;
}
.cz-tab.active { background: var(--cz-surface); color: var(--cz-text); border-color: var(--cz-border); }

.cz-stat {
  font-family: 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.7rem; color: var(--cz-text-dim);
  background: var(--cz-surface); border: 1px solid var(--cz-border);
  padding: 4px 9px; border-radius: 5px; white-space: nowrap;
}
.cz-copy {
  margin-left: auto; font: inherit; font-size: 0.78rem; font-weight: 700;
  padding: 7px 14px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--cz-accent); background: var(--cz-accent); color: #fff;
  display: inline-flex; align-items: center; gap: 7px; transition: filter 0.15s, background 0.15s;
}
.cz-copy:hover { filter: brightness(1.07); }
.cz-copy.done { background: var(--cz-good); border-color: var(--cz-good); }
.cz-copy:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Output body ────────────────────────────────────────────────────────── */
.cz-out-body {
  flex: 1; overflow: auto; padding: 16px; min-height: 0;
}
.cz-out-body::-webkit-scrollbar { width: 6px; height: 6px; }
.cz-out-body::-webkit-scrollbar-thumb { background: var(--cz-scrollbar); border-radius: 4px; }

.cz-md {
  margin: 0; font-family: 'Cascadia Code', 'Consolas', 'Courier New', monospace;
  font-size: 0.78rem; line-height: 1.7; color: var(--cz-text);
  white-space: pre; tab-size: 2;
}
.cz-md .cz-pipe { color: var(--cz-text-faint); }
.cz-md .cz-esc { color: var(--cz-warn); font-weight: 700; }
.cz-md .cz-sep { color: var(--cz-accent); }

.cz-table { border-collapse: collapse; width: 100%; font-size: 0.82rem; }
.cz-table th, .cz-table td {
  border: 1px solid var(--cz-border); padding: 7px 11px;
  text-align: left; vertical-align: top;
}
.cz-table th {
  background: var(--cz-surface-2); font-weight: 700;
  color: var(--cz-text); white-space: nowrap;
}
.cz-table tbody tr:nth-child(even) td { background: var(--cz-surface-2); }

.cz-empty {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  text-align: center; color: var(--cz-text-faint); padding: 30px;
}
.cz-empty .cz-empty-icon { font-size: 2.6rem; opacity: 0.5; }
.cz-empty p { font-size: 0.85rem; line-height: 1.6; max-width: 320px; }
