/* ===========================
   JSONZap — Shared Stylesheet
   =========================== */

/* --- DARK THEME (default) --- */
:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #12151e;
  --border: #2a2d3d;
  --accent: #5b8af0;
  --accent-hover: #4a75d9;
  --accent-light: #1e2d50;
  --success: #3ecf8e;
  --success-light: #0d2e20;
  --error: #f66;
  --error-light: #2d0f0f;
  --warning: #f5a623;
  --text: #e2e8f0;
  --text-muted: #6b7280;
  --text-dim: #94a3b8;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  /* syntax colours */
  --syn-string: #98d4a3;
  --syn-number: #79b8ff;
  --syn-bool:   #f97583;
  --syn-key:    #b392f0;
}

/* --- LIGHT THEME --- */
[data-theme="light"] {
  --bg: #f5f6fa;
  --bg-card: #ffffff;
  --bg-input: #f0f1f5;
  --border: #d8dce8;
  --accent: #3b6fe0;
  --accent-hover: #2d5cc9;
  --accent-light: #dce8ff;
  --success: #1a9e6a;
  --success-light: #d4f5e9;
  --error: #d93636;
  --error-light: #fde8e8;
  --warning: #c97a00;
  --text: #1a1d2e;
  --text-muted: #7b8299;
  --text-dim: #4a5068;
  --shadow: 0 4px 24px rgba(0,0,0,0.10);
  /* syntax colours (adjusted for light bg) */
  --syn-string: #1a7a3a;
  --syn-number: #1553aa;
  --syn-bool:   #b5000d;
  --syn-key:    #6b35c0;
}

/* Theme segmented toggle */
.theme-switcher {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
  margin-left: 12px;
  flex-shrink: 0;
}

.theme-switcher button {
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 5px 10px;
  line-height: 1;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.theme-switcher button:hover {
  color: var(--text);
  background: rgba(128,128,128,0.12);
}

.theme-switcher button.active {
  background: var(--bg-card);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

[data-theme="light"] .theme-switcher button.active {
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  line-height: 1.6;
}

/* ---- HEADER ---- */
header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo span {
  color: var(--accent);
}

nav {
  display: flex;
  gap: 4px;
}

nav a {
  color: var(--text-dim);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: all 0.15s;
}

nav a:hover {
  color: var(--text);
  background: rgba(255,255,255,0.05);
}

nav a.active {
  color: var(--accent);
  background: var(--accent-light);
}

/* ---- MAIN LAYOUT ---- */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.hero {
  text-align: center;
  margin-bottom: 32px;
}

.hero h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.hero p {
  color: var(--text-muted);
  font-size: 1rem;
  max-width: 480px;
  margin: 0 auto;
}

/* ---- TOOL CARD ---- */
.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.tool-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---- TWO-PANEL LAYOUT ---- */
.panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 520px;
}

@media (max-width: 720px) {
  .panels {
    grid-template-columns: 1fr;
  }
}

.panel {
  display: flex;
  flex-direction: column;
}

.panel + .panel {
  border-left: 1px solid var(--border);
}

@media (max-width: 720px) {
  .panel + .panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

textarea {
  flex: 1;
  background: var(--bg-input);
  border: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.7;
  padding: 16px;
  resize: none;
  outline: none;
  min-height: 480px;
  width: 100%;
}

textarea::placeholder {
  color: var(--text-muted);
}

textarea:focus {
  background: var(--bg-input);
  filter: brightness(0.96);
}

/* ---- OUTPUT PANEL ---- */
.output-area {
  flex: 1;
  background: var(--bg-input);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.7;
  padding: 16px;
  overflow: auto;
  min-height: 480px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.output-area.error {
  color: var(--error);
}

.output-area.empty {
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex-direction: column;
  gap: 8px;
}

.output-area.empty .icon {
  font-size: 2rem;
  opacity: 0.4;
}

/* ---- STATUS BAR ---- */
.status-bar {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status-dot.ok { background: var(--success); }
.status-dot.err { background: var(--error); }

.status-text { flex: 1; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  white-space: nowrap;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text);
}

.btn-success {
  background: var(--success);
  color: #0a2018;
}

.btn-success:hover {
  background: #35b87c;
}

.btn-danger {
  background: transparent;
  color: var(--error);
  border: 1px solid rgba(255,102,102,0.3);
}

.btn-danger:hover {
  background: var(--error-light);
}

/* ---- SYNTAX HIGHLIGHT ---- */
.json-string  { color: var(--syn-string); }
.json-number  { color: var(--syn-number); }
.json-boolean { color: var(--syn-bool); }
.json-null    { color: var(--syn-bool); }
.json-key     { color: var(--syn-key); }
.json-bracket { color: var(--text-dim); }

/* ---- TREE VIEWER ---- */
.tree-node {
  padding: 1px 0;
}

.tree-toggle {
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tree-arrow {
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.15s;
  width: 12px;
  display: inline-block;
}

.tree-arrow.open { transform: rotate(90deg); }

.tree-children {
  padding-left: 20px;
  border-left: 1px solid var(--border);
  margin-left: 5px;
}

.tree-children.hidden { display: none; }

.tree-key   { color: var(--syn-key); }
.tree-colon { color: var(--text-muted); margin: 0 4px; }
.tree-str   { color: var(--syn-string); }
.tree-num   { color: var(--syn-number); }
.tree-bool  { color: var(--syn-bool); }
.tree-null  { color: var(--syn-bool); }
.tree-count { color: var(--text-muted); font-size: 0.78rem; margin-left: 4px; }

/* ---- CSV TABLE ---- */
.csv-table-wrap {
  overflow: auto;
  flex: 1;
  min-height: 480px;
  background: var(--bg-input);
}

.csv-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.csv-table th {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.csv-table td {
  border: 1px solid var(--border);
  padding: 6px 12px;
  color: var(--text);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.csv-table tr:nth-child(even) td {
  background: rgba(255,255,255,0.02);
}

/* ---- TOAST ---- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  z-index: 9999;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.2s;
  pointer-events: none;
  color: var(--text);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--error); color: var(--error); }

/* ---- FOOTER ---- */
footer {
  border-top: 1px solid var(--border);
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-top: 48px;
}

footer a {
  color: var(--text-dim);
  text-decoration: none;
}

footer a:hover { color: var(--accent); }
