/* ═══════════════════════════════════════
   CSS VARIABLES & RESET
   ═══════════════════════════════════════ */
:root {
  --bg-deep: #0a0a16;
  --bg-sidebar: #0e0e1a;
  --bg-card: #12121f;
  --bg-card-hover: #1a1a2e;
  --bg-input: #0d0d18;
  --bg-code: #0a0a16;
  --border: #2a2a40;
  --border-light: #1e1e35;
  --text: #e2e2f0;
  --text-dim: #6b6b8a;
  --text-dimmer: #4b4b6b;
  --text-muted: #8888a8;
  --text-code: #b8b8d0;
  --accent: #6366f1;
  --accent-dim: rgba(99,102,241,0.12);
  --green: #10b981;
  --yellow: #f59e0b;
  --red: #ef4444;
  --pink: #ec4899;
  --blue: #0ea5e9;
  --purple: #a855f7;
  --orange: #f97316;
  --mono: 'JetBrains Mono','Fira Code',monospace;
  --sans: 'DM Sans',sans-serif;
  --sidebar-w: 220px;
}

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

body {
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  display: flex;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
}

.sidebar-brand {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-brand h1 {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.sidebar-brand h1 .accent { color: var(--accent); }
.sidebar-brand h1 .dim    { color: var(--text-dimmer); }

.sidebar-brand p {
  color: var(--text-dim);
  font-size: 11px;
  margin-top: 4px;
  font-family: var(--mono);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 13px;
  font-family: var(--sans);
  font-weight: 500;
  text-align: left;
  width: 100%;
  transition: all 0.15s;
}

.nav-item:hover  { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.nav-item .icon  { font-size: 16px; width: 22px; text-align: center; }

.nav-section {
  color: var(--text-dimmer);
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 16px 12px 6px;
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border-light);
  font-size: 10px;
  color: var(--text-dimmer);
  font-family: var(--mono);
}

/* ── Main ── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
}

/* ── Shared page components ── */
.page-header {
  background: linear-gradient(135deg,#12121f 0%,#1a1a32 100%);
  border-bottom: 1px solid var(--border-light);
  padding: 24px 28px 20px;
}

.page-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: -0.5px;
}

.page-subtitle {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.save-badge {
  color: var(--green);
  font-size: 11px;
  font-family: var(--mono);
  background: rgba(16,185,129,0.09);
  padding: 2px 8px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.3s;
}

.save-badge.visible { opacity: 1; }

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

/* ── Buttons ── */
.btn {
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-family: var(--mono);
  font-weight: 600;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  transition: all 0.15s;
}

.btn:hover { border-color: var(--text-dim); color: var(--text); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-primary:hover { background: #5558e6; }

.btn-sm {
  padding: 5px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-dim);
}

.btn-sm.danger { color: var(--red); border-color: rgba(239,68,68,0.2); }

.btn-cancel {
  padding: 9px 20px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-family: var(--sans);
}

.btn-save {
  padding: 9px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--sans);
}

.btn-save:disabled { opacity: 0.4; cursor: default; }

/* ── Search ── */
.search-wrap { position: relative; }

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dimmer);
  font-size: 15px;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--mono);
  outline: none;
}

.search-input:focus { border-color: var(--accent); }

/* ── Category / filter tabs ── */
.cat-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.cat-tab {
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--mono);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  transition: all 0.15s;
}

.cat-tab:hover { border-color: var(--text-dim); }

/* ── Content area ── */
.content-area {
  padding: 16px 28px 40px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-state { text-align: center; padding: 48px 0; color: var(--text-dimmer); }
.empty-state .icon  { font-size: 32px; margin-bottom: 8px; }
.empty-state .text  { font-family: var(--mono); font-size: 14px; }

/* ── Query Cards ── */
.query-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: all 0.2s;
  background: var(--bg-card);
}

.query-card.expanded { background: var(--bg-card-hover); }

.query-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
}

.cat-badge {
  font-size: 11px;
  font-weight: 700;
  font-family: var(--mono);
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
}

.query-info { flex: 1; min-width: 0; }
.query-title { color: var(--text); font-weight: 600; font-size: 14px; font-family: var(--mono); }
.query-desc  { color: var(--text-dim); font-size: 12px; margin-top: 2px; }

.chevron { color: var(--text-dim); font-size: 18px; transition: transform 0.2s; }
.chevron.open { transform: rotate(180deg); }

.query-body { padding: 0 18px 18px; }

.params-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.param-label {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.param-input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--mono);
  outline: none;
}

.param-input:focus { border-color: rgba(99,102,241,0.5); }

.sql-wrap { position: relative; }

.sql-output {
  background: var(--bg-code);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 16px;
  margin: 0;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-code);
  font-family: var(--mono);
  max-height: 400px;
  white-space: pre;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 6px 14px;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--sans);
  transition: all 0.15s;
}

.param-hint { margin-top: 8px; color: var(--yellow); font-size: 11px; opacity: 0.7; }

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  justify-content: flex-end;
}

/* ── URL Cards ── */
.url-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}

.url-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  transition: all 0.15s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
  position: relative;
}

.url-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(99,102,241,0.3);
  transform: translateY(-1px);
}

.url-card-top { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }

.url-favicon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.url-card-info { flex: 1; min-width: 0; }

.url-card-name {
  font-weight: 600;
  font-size: 13px;
  font-family: var(--mono);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.url-card-url {
  font-size: 11px;
  color: var(--text-dimmer);
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.url-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }

.url-tag {
  font-size: 10px;
  font-weight: 600;
  font-family: var(--mono);
  padding: 2px 7px;
  border-radius: 3px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.url-card-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.url-card:hover .url-card-actions { opacity: 1; }

.url-action-btn {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  color: var(--text-dim);
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
}

.url-action-btn:hover        { background: var(--bg-card-hover); color: var(--text); }
.url-action-btn.danger:hover { color: var(--red); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: 90%;
  max-width: 580px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal h3 { color: var(--text); margin: 0 0 20px; font-size: 18px; font-family: var(--mono); }

.modal-field { margin-bottom: 14px; }

.modal-label {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.modal-input,
.modal-select,
.modal-textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--mono);
  outline: none;
}

.modal-input:focus,
.modal-select:focus,
.modal-textarea:focus { border-color: var(--accent); }

.modal-select { cursor: pointer; }

.modal-textarea {
  resize: vertical;
  line-height: 1.5;
  min-height: 200px;
}

.modal-hint { color: var(--text-dim); font-size: 11px; margin-top: 4px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ── Home page ── */
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  padding: 28px;
}

.home-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  cursor: pointer;
  transition: all 0.15s;
}

.home-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(99,102,241,0.3);
  transform: translateY(-2px);
}

.home-card .icon  { font-size: 28px; margin-bottom: 12px; }
.home-card .title { font-family: var(--mono); font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.home-card .desc  { color: var(--text-dim); font-size: 13px; line-height: 1.5; }

/* ── Utilities ── */
#importFile { display: none; }

/* ── Mobile ── */
@media (max-width: 768px) {
  .sidebar { width: 60px; overflow: hidden; }
  .sidebar-brand h1,
  .sidebar-brand p,
  .nav-item span:not(.icon),
  .nav-section,
  .sidebar-footer { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
  .nav-item .icon { width: auto; font-size: 20px; }
  .main { margin-left: 60px; }
  .page-header,
  .content-area { padding-left: 16px; padding-right: 16px; }
  .url-grid { grid-template-columns: 1fr; }
}
