@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

/* ── Tokens ─────────────────────────────────────── */
:root {
  --accent:        #7c6fee;
  --accent-2:      #ec4899;
  --accent-3:      #06b6d4;
  --accent-glow:   rgba(124,111,238,0.22);

  --bg:            #f0f2f8;
  --surface:       rgba(255,255,255,0.88);
  --surface-s:     #ffffff;
  --surface-secondary: rgba(0,0,0,0.04);
  --input-bg:      rgba(0,0,0,0.04);
  --border:        rgba(0,0,0,0.07);
  --text-h:        #0d0f1a;
  --text-p:        #4a5069;
  --text-muted:    #8892b0;
  --shadow:        0 4px 24px rgba(0,0,0,0.07);
  --shadow-lg:     0 16px 48px rgba(0,0,0,0.13);
  --header-bg:     rgba(240,242,248,0.92);

  --r-xl: 24px; --r-lg: 18px; --r-md: 14px; --r-sm: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* legacy compat */
  --primary:           #7c6fee;
  --primary-gradient:  linear-gradient(135deg, #7c6fee 0%, #ec4899 100%);
  --bg-color:          #f0f2f8;
  --text-main:         #0d0f1a;
  --radius-lg:         var(--r-xl);
  --radius-md:         var(--r-lg);
  --radius-sm:         var(--r-md);
  --shadow-sm:         0 2px 8px rgba(0,0,0,0.06);
  --shadow-glass:      var(--shadow);
}

[data-theme="dark"],
body.dark-mode {
  --bg:            #0a0a0f;
  --surface:       rgba(22,22,34,0.85);
  --surface-s:     #16161f;
  --surface-secondary: rgba(255,255,255,0.05);
  --input-bg:      rgba(255,255,255,0.05);
  --border:        rgba(255,255,255,0.08);
  --text-h:        #f0f2ff;
  --text-p:        #8892b0;
  --text-muted:    #4a5069;
  --shadow:        0 4px 24px rgba(0,0,0,0.5);
  --shadow-lg:     0 16px 48px rgba(0,0,0,0.7);
  --header-bg:     rgba(10,10,15,0.92);

  --bg-color:   #0a0a0f;
  --text-main:  #f0f2ff;
}

/* ── Reset ──────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box; margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-h);
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  transition: background 0.4s, color 0.4s;
}

::selection { background: rgba(124,111,238,0.18); }

/* ── Mesh Background ────────────────────────────── */
.bg-mesh {
  position: fixed; inset: 0; z-index: 0;
  overflow: hidden; pointer-events: none;
}
.bg-mesh::before, .bg-mesh::after {
  content: ''; position: absolute; border-radius: 50%;
  filter: blur(80px); opacity: 0.22;
}
[data-theme="dark"] .bg-mesh::before,
[data-theme="dark"] .bg-mesh::after,
body.dark-mode .bg-mesh::before,
body.dark-mode .bg-mesh::after { opacity: 0.11; }

.bg-mesh::before {
  width: 65vw; height: 65vw; top: -18vw; left: -18vw;
  background: radial-gradient(circle, #7c6fee, #ec4899);
  animation: floatA 18s ease-in-out infinite alternate;
}
.bg-mesh::after {
  width: 50vw; height: 50vw; bottom: -14vw; right: -14vw;
  background: radial-gradient(circle, #06b6d4, #7c6fee);
  animation: floatB 22s ease-in-out infinite alternate;
}
@keyframes floatA { from{transform:translate(0,0) scale(1)} to{transform:translate(5vw,4vw) scale(1.1)} }
@keyframes floatB { from{transform:translate(0,0) scale(1)} to{transform:translate(-4vw,-5vw) scale(1.08)} }

/* ── Header ─────────────────────────────────────── */
header {
  position: sticky; top: 0; z-index: 100;
  height: 56px; padding: 0 16px;
  display: flex; align-items: center; gap: 10px;
  background: var(--header-bg);
  backdrop-filter: saturate(1.8) blur(24px);
  -webkit-backdrop-filter: saturate(1.8) blur(24px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  animation: slideDown 0.55s cubic-bezier(0.16,1,0.3,1);
}
@keyframes slideDown {
  from{opacity:0;transform:translateY(-16px)} to{opacity:1;transform:translateY(0)}
}
@keyframes fadeInUp {
  from{opacity:0;transform:translateY(20px)} to{opacity:1;transform:translateY(0)}
}

.header-title-block {
  display: flex; flex-direction: column; gap: 0;
}
.header-eyebrow {
  font-size: 10px; font-weight: 600; letter-spacing: 1px;
  text-transform: uppercase; color: var(--accent); line-height: 1;
}
.brand {
  font-weight: 800; font-size: 15px; letter-spacing: -0.3px;
  background: linear-gradient(135deg, var(--text-h) 40%, var(--text-p));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap; line-height: 1.2;
}

/* Back button */
.back-btn-absolute {
  width: 34px; height: 34px; border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-h); text-decoration: none;
  backdrop-filter: blur(10px); box-shadow: var(--shadow);
  transition: all 0.2s ease;
}
.back-btn-absolute:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.back-btn-absolute:active { transform: scale(0.9); }

/* Header right extras */
.header-extras {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0; margin-left: auto; z-index: 102;
}

/* Menu / icon buttons */
.menu-btn, .icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-p); cursor: pointer;
  backdrop-filter: blur(10px); box-shadow: var(--shadow);
  transition: all 0.2s ease; flex-shrink: 0; font-size: 0;
}
/* Reset namelist-specific menu-btn overrides */
.menu-btn {
  position: static; transform: none; width: 36px; height: 36px;
}
.menu-btn:hover, .icon-btn:hover {
  color: var(--text-h); border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.menu-btn:active, .icon-btn:active { transform: scale(0.93); }

/* ── Click-outside ──────────────────────────────── */
.click-outside { position: fixed; inset: 0; z-index: 101; display: none; }

/* ── Popover menu ───────────────────────────────── */
.popover-menu {
  position: fixed; top: 64px; right: 16px;
  background: var(--surface-s); border: 1px solid var(--border);
  border-radius: var(--r-xl); padding: 8px; width: 220px;
  display: none; flex-direction: column; gap: 2px;
  z-index: 2000; box-shadow: var(--shadow-lg);
  transform-origin: top right;
  animation: menuIn 0.2s cubic-bezier(0.16,1,0.3,1);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
}
@keyframes menuIn { from{opacity:0;transform:scale(0.9)} to{opacity:1;transform:scale(1)} }
.popover-menu.active { display: flex; }

.menu-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 14px; border-radius: 12px; cursor: pointer;
  color: var(--text-h); font-size: 14px; font-weight: 600;
  background: transparent; border: none; width: 100%; text-align: left;
  transition: background 0.15s; font-family: var(--font); text-decoration: none;
}
.menu-item:hover { background: color-mix(in srgb,var(--text-h) 6%,transparent); }

/* Toggle switch */
.switch { position: relative; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--text-muted); transition: .3s; border-radius: 34px;
}
.slider:before {
  position: absolute; content: ""; height: 16px; width: 16px;
  left: 3px; bottom: 3px; background: white; transition: .3s;
  border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
input:checked + .slider { background: var(--accent); }
input:checked + .slider:before { transform: translateX(16px); }

/* ── Mobile Tab Switcher ────────────────────────── */
.mobile-tabs {
  display: none;
  padding: 10px 16px;
  background: var(--bg);
  flex-shrink: 0;
  z-index: 2;
  animation: fadeInUp 0.5s cubic-bezier(0.16,1,0.3,1) 0.15s backwards;
}
.segment-control {
  display: flex; width: 100%;
  background: var(--surface-secondary);
  border: 1px solid var(--border);
  padding: 3px; border-radius: 14px;
  position: relative; height: 36px;
}
.tab-btn {
  flex: 1; text-align: center; border: none;
  background: transparent; border-radius: 11px;
  font-size: 13px; font-weight: 600; color: var(--text-p);
  cursor: pointer; z-index: 1; font-family: var(--font);
  transition: color 0.2s;
}
.tab-btn.active {
  background: var(--surface-s);
  color: var(--text-h);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ── Layout ─────────────────────────────────────── */
main {
  flex: 1;
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 1px; background: var(--border);
  overflow: hidden; position: relative; z-index: 1;
}

.panel {
  display: flex; flex-direction: column;
  height: 100%; overflow: hidden; position: relative;
  background: var(--bg);
  animation: fadeInUp 0.5s cubic-bezier(0.16,1,0.3,1) 0.1s backwards;
}

.panel-header {
  padding: 12px 16px;
  background: var(--bg);
  display: flex; flex-direction: column; gap: 12px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.scroll-area {
  flex: 1; overflow-y: auto;
  padding: 12px 16px 16px;
  scrollbar-width: thin;
  overscroll-behavior: contain; position: relative;
}
.scroll-area::-webkit-scrollbar { width: 4px; }
.scroll-area::-webkit-scrollbar-track { background: transparent; }
.scroll-area::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 4px;
}

/* ── Tables ─────────────────────────────────────── */
table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  backdrop-filter: blur(12px);
  overflow: hidden;
}

th {
  position: sticky; top: 0;
  background: var(--surface-s);
  z-index: 20;
  box-shadow: 0 1px 0 var(--border);
  padding: 10px 14px;
  text-align: left; font-weight: 700; font-size: 11px;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px;
}
th:first-child { border-top-left-radius: var(--r-lg); }
th:last-child  { border-top-right-radius: var(--r-lg); }

td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-h); vertical-align: middle;
  font-size: 13px; font-weight: 500;
}
th:first-child, td:first-child {
  width: 46px; text-align: center !important;
  padding-left: 10px; padding-right: 4px; color: var(--text-muted);
}
tr:last-child td { border-bottom: none; }
tr:active td { background: var(--surface-secondary); }

.clickable-row { cursor: pointer; transition: background 0.12s; user-select: none; }
.clickable-row:hover td { background: color-mix(in srgb,var(--accent) 5%,transparent); }

/* ── Panel Footer ────────────────────────────────── */
.panel-footer {
  padding: 12px 16px;
  background: var(--header-bg);
  backdrop-filter: saturate(1.8) blur(20px);
  -webkit-backdrop-filter: saturate(1.8) blur(20px);
  border-top: 1px solid var(--border);
  display: flex; gap: 10px;
  align-items: center; justify-content: space-between;
  flex-shrink: 0;
}

/* ── Search Box ─────────────────────────────────── */
.search-box { position: relative; width: 100%; }
.search-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 15px;
}
.search-box input {
  width: 100%; padding: 9px 14px 9px 38px;
  border-radius: var(--r-lg); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-h);
  font-size: 14px; font-weight: 500; font-family: var(--font);
  transition: all 0.2s ease; backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.search-box input::placeholder { color: var(--text-muted); }
.search-box input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--surface-s);
}

/* ── Buttons ─────────────────────────────────────── */
.btn {
  height: 40px; padding: 0 18px;
  border-radius: 99px; border: none;
  font-weight: 700; font-size: 14px; font-family: var(--font);
  cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  transition: all 0.2s cubic-bezier(0.25,1,0.5,1);
  justify-content: center; user-select: none;
}
.btn:active { opacity: 0.75; transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  box-shadow: 0 6px 18px var(--accent-glow);
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: 0 8px 22px var(--accent-glow); }

.btn-secondary {
  background: var(--surface); color: var(--text-h);
  border: 1px solid var(--border); font-weight: 600;
  backdrop-filter: blur(10px); box-shadow: var(--shadow);
  transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.icon-only {
  padding: 0; width: 40px; height: 40px;
  border-radius: 50% !important;
  display: flex; justify-content: center; align-items: center; flex-shrink: 0;
}
.icon-only svg { width: 18px; height: 18px; }

.btn-icon {
  padding: 8px; border-radius: 50%; background: transparent; color: var(--accent);
}

.btn-link {
  background: none; border: none;
  color: var(--accent); text-decoration: none;
  font-weight: 700; cursor: pointer; font-size: 14px;
  margin-top: 16px; padding: 8px; font-family: var(--font);
  transition: opacity 0.2s;
}
.btn-link:active { opacity: 0.5; }

/* ── Toggle Pills ────────────────────────────────── */
.toggles-row {
  display: flex; gap: 8px; align-items: center;
  flex-wrap: wrap; margin-bottom: 2px;
}
.label-sm {
  font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; font-size: 11px; letter-spacing: 0.6px;
  margin-bottom: 8px; display: block;
}
.toggle-pill {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer;
  color: var(--text-p); font-size: 13px; font-weight: 600;
  transition: all 0.2s cubic-bezier(0.34,1.56,0.64,1);
  user-select: none; box-shadow: var(--shadow);
  font-family: var(--font);
}
.toggle-pill:active { scale: 0.95; }
.toggle-pill:has(input:checked) {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white; border-color: transparent;
  box-shadow: 0 4px 14px var(--accent-glow);
}
.toggle-pill:has(input[type="radio"]:checked) {
  background: var(--surface-s);
  color: var(--accent); border-color: var(--accent);
  box-shadow: var(--shadow);
}
.toggle-pill input { display: none; }

/* ── Format scroll ───────────────────────────────── */
.options-grid-scroll {
  display: flex; gap: 8px; flex-wrap: nowrap;
  overflow-x: auto; padding-bottom: 4px; scrollbar-width: none;
}
.options-grid-scroll::-webkit-scrollbar { display: none; }
.options-grid-scroll .toggle-pill {
  flex: 1; min-width: 0; height: 38px;
  padding: 0 4px; border-radius: 10px;
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* ── Empty State ─────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  flex: 1; min-height: 200px;
  color: var(--text-muted); text-align: center; padding: 24px;
  font-size: 14px; font-weight: 500;
}
.empty-state svg { margin-bottom: 12px; color: var(--text-muted); }

/* ── Action Groups ───────────────────────────────── */
.action-group { display: flex; gap: 10px; width: 100%; }
.flex-grow { flex: 1; }

/* ── Mobile view ─────────────────────────────────── */
@media (max-width: 768px) {
  main { display: block; background: var(--bg); }

  .panel {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    display: none; border: none; background: var(--bg);
  }
  .panel.active { display: flex; }
  .mobile-tabs { display: block; }
}

/* ── Toast ───────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  z-index: 3000; pointer-events: none;
}
.toast {
  background: rgba(13,15,26,0.92);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  color: white; padding: 12px 24px; border-radius: 99px;
  font-size: 13px; font-weight: 600; font-family: var(--font);
  box-shadow: 0 8px 28px rgba(0,0,0,0.25);
  opacity: 0; transform: translateY(20px) scale(0.95);
  animation: toast-in 0.3s cubic-bezier(0.16,1,0.3,1) forwards;
  display: flex; align-items: center; gap: 10px;
}
.toast.success { background: rgba(16,185,129,0.95); }
.toast.error   { background: rgba(239,68,68,0.95); }
@keyframes toast-in {
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-10px) scale(0.95); }
}

/* ── Modals ──────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  z-index: 1001;
  display: flex; align-items: center; justify-content: center;
  animation: fade-in 0.2s;
}
@keyframes fade-in { from { opacity: 0; } }

.modal-content {
  background: var(--surface-s);
  width: 90%; max-width: 400px;
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: scale-up 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes scale-up {
  from { transform: scale(0.92) translateY(12px); opacity: 0; }
}

.modal-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface-secondary);
}
.modal-header h3 {
  font-size: 16px; font-weight: 800; letter-spacing: -0.3px;
  margin: 0; color: var(--text-h);
}

.btn-close {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--input-bg); border: 1px solid var(--border);
  color: var(--text-p); font-size: 13px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.btn-close:hover {
  background: color-mix(in srgb,var(--accent) 10%,transparent);
  border-color: var(--accent); color: var(--text-h);
}

.modal-body { padding: 16px 20px; }
.modal-footer {
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end;
}

/* ── Settings rows ────────────────────────────────── */
.settings-group {
  display: flex; flex-direction: column;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden; margin-bottom: 16px;
}
.settings-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: none; border-bottom: 1px solid var(--border);
  color: var(--text-h); font-size: 14px; font-weight: 500; font-family: var(--font);
  cursor: pointer; text-align: left; width: 100%;
  transition: background 0.15s; text-decoration: none; position: relative;
}
.settings-row:last-child { border-bottom: none; }
.settings-row:hover { background: color-mix(in srgb,var(--accent) 6%,transparent); }
.settings-row svg { width: 20px; height: 20px; color: var(--accent); flex-shrink: 0; }
.settings-row span { flex: 1; }
.settings-row input[type="radio"] {
  margin: 0; accent-color: var(--accent); width: 18px; height: 18px;
}
.settings-row.text-danger { color: #ef4444; }
.settings-row.text-danger svg { color: #ef4444; }
.text-danger { color: #ef4444 !important; }

/* ── Format preview ──────────────────────────────── */
.format-preview-box {
  background: transparent; padding: 0; border: none;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 12px; color: var(--text-muted);
  margin-bottom: 8px; white-space: pre-wrap; word-break: break-all;
  min-height: 80px; display: flex; align-items: center;
  justify-content: center; text-align: center; margin-top: 0;
}

/* ── Radio rows ──────────────────────────────────── */
.options-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.radio-row {
  display: flex; align-items: center; gap: 8px;
  padding: 10px; border-radius: var(--r-md);
  background: var(--input-bg); cursor: pointer;
  transition: background 0.15s; font-size: 13px; font-weight: 500;
  color: var(--text-h);
}
.radio-row:hover { background: color-mix(in srgb,var(--accent) 8%,transparent); }
.radio-row:has(input:checked) { background: color-mix(in srgb,var(--accent) 12%,transparent); color: var(--accent); font-weight: 700; }
.radio-row input { margin: 0; accent-color: var(--accent); }

/* ── Btn-surface alias ───────────────────────────── */
.btn-surface {
  background: var(--surface); color: var(--text-h);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  font-weight: 600; transition: all 0.2s;
}
.btn-surface:active { transform: scale(0.97); }