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

/* ===== THEME VARIABLES ===== */
:root {
  --bg-primary: #0a0f1e;
  --bg-secondary: #0f172a;
  --bg-card: rgba(255,255,255,0.03);
  --bg-input: rgba(255,255,255,0.06);
  --bg-hover: rgba(255,255,255,0.04);
  --border: rgba(255,255,255,0.08);
  --border-input: rgba(255,255,255,0.12);
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-dim: #475569;
  --accent: #3b82f6;
  --accent-light: #60a5fa;
  --accent-bg: rgba(59,130,246,0.15);
  --accent-border: #3b82f6;
  --green: #4ade80;
  --green-bg: rgba(34,197,94,0.15);
  --green-border: rgba(34,197,94,0.3);
  --red: #f87171;
  --red-bg: rgba(239,68,68,0.15);
  --red-border: rgba(239,68,68,0.3);
  --yellow: #fbbf24;
  --yellow-bg: rgba(245,158,11,0.05);
  --yellow-border: rgba(245,158,11,0.2);
  --shadow-color: rgba(0,0,0,0.3);
  --select-bg: #1e293b;
  --icon-color: #94a3b8;
  --scrollbar-track: #0f172a;
  --scrollbar-thumb: #334155;
  --gradient-start: #334155;
  --gradient-end: #1e293b;
}

[data-theme="light"] {
  --bg-primary: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-card: rgba(0,0,0,0.02);
  --bg-input: rgba(0,0,0,0.04);
  --bg-hover: rgba(0,0,0,0.03);
  --border: rgba(0,0,0,0.08);
  --border-input: rgba(0,0,0,0.15);
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-dim: #94a3b8;
  --accent: #2563eb;
  --accent-light: #3b82f6;
  --accent-bg: rgba(37,99,235,0.1);
  --accent-border: #2563eb;
  --shadow-color: rgba(0,0,0,0.08);
  --select-bg: #ffffff;
  --icon-color: #64748b;
  --scrollbar-track: #e2e8f0;
  --scrollbar-thumb: #94a3b8;
  --gradient-start: #e2e8f0;
  --gradient-end: #f1f5f9;
}

body {
  font-family: 'DM Mono', monospace;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
  transition: background 0.3s, color 0.3s;
}
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
select option { background: var(--select-bg); }

/* ===== SVG ICONS ===== */
.icon {
  width: 16px; height: 16px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.icon svg { width: 16px; height: 16px; stroke: var(--icon-color); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.section-toggle .icon svg { stroke: var(--accent-light); }

/* ===== HEADER ===== */
#header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; border-bottom: 1px solid var(--border);
  background: var(--bg-secondary); backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 100;
  transition: background 0.3s;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.logo-icon {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
}
.logo-icon svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2; }
.logo-text { font-family: 'Syne', sans-serif; font-weight: 800; font-size: 16px; letter-spacing: -0.02em; }
.logo-sub { font-size: 10px; color: var(--text-muted); letter-spacing: 0.08em; }
.header-right { display: flex; gap: 8px; align-items: center; }

/* ===== HEADER ACTIONS ===== */
.header-actions { display: flex; gap: 6px; align-items: center; }
.btn-action {
  padding: 6px 14px; border-radius: 8px; font-size: 11px; cursor: pointer;
  font-family: 'DM Mono', monospace; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text-secondary); transition: all 0.2s;
  display: flex; align-items: center; gap: 5px;
}
.btn-action svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2; }
.btn-action:hover { border-color: var(--accent); color: var(--accent-light); }
.btn-action.delete:hover { border-color: var(--red); color: var(--red); }
.btn-save {
  padding: 6px 18px; border-radius: 8px; font-size: 12px; cursor: pointer;
  font-family: 'DM Mono', monospace; font-weight: 500; border: none;
  background: linear-gradient(135deg, #3b82f6, #6366f1); color: #fff;
  letter-spacing: 0.04em; transition: all 0.2s;
  display: flex; align-items: center; gap: 6px;
}
.btn-save svg { width: 14px; height: 14px; stroke: #fff; fill: none; stroke-width: 2; }
.btn-save:hover { transform: translateY(-1px); box-shadow: 0 4px 15px rgba(59,130,246,0.4); }
.btn-save.unsaved { background: linear-gradient(135deg, #f59e0b, #ef4444); animation: pulse-save 1.5s infinite; }
.btn-save.saving { opacity: 0.6; cursor: wait; }
@keyframes pulse-save {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245,158,11,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(245,158,11,0); }
}

/* ===== THEME TOGGLE ===== */
.btn-theme {
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-card);
  display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.btn-theme:hover { border-color: var(--accent); }
.btn-theme svg { width: 16px; height: 16px; stroke: var(--text-secondary); fill: none; stroke-width: 2; }

/* ===== STATUS ===== */
.status-badge {
  padding: 4px 12px; border-radius: 99px; font-size: 11px; font-family: 'DM Mono', monospace;
}
.status-badge.live { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.status-badge.paused { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-border); }
#header select {
  background: var(--select-bg); border: 1px solid var(--border-input);
  border-radius: 6px; padding: 6px 10px; color: var(--text-primary);
  font-size: 13px; font-family: 'DM Mono', monospace; outline: none;
}

/* ===== NOTIFICATION ===== */
.notification {
  position: fixed; top: -60px; left: 50%; transform: translateX(-50%);
  padding: 10px 24px; border-radius: 10px; font-size: 12px;
  font-family: 'DM Mono', monospace; z-index: 9999;
  transition: top 0.3s ease; pointer-events: none; backdrop-filter: blur(12px);
}
.notification.show { top: 16px; }
.notification.success { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.notification.error { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-border); }

/* ===== LAYOUT ===== */
.app-layout { display: flex; height: calc(100vh - 55px); }

/* ===== AD LIST SIDEBAR ===== */
#adListPanel {
  width: 200px; flex-shrink: 0; overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg-secondary); padding: 0;
  transition: width 0.25s ease, opacity 0.25s ease, padding 0.25s ease;
}
#adListPanel.collapsed { width: 0; overflow: hidden; opacity: 0; padding: 0; border-right: none; }
.ad-list-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.ad-list-title { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.btn-collapse {
  width: 24px; height: 24px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-card);
  display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.btn-collapse:hover { border-color: var(--accent); }
.btn-collapse svg { width: 12px; height: 12px; stroke: var(--text-muted); fill: none; stroke-width: 2; transition: transform 0.25s; }
#adListPanel.collapsed + #controls .btn-expand { display: flex; }
.btn-expand {
  display: none; width: 28px; height: 28px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-card);
  align-items: center; justify-content: center; margin-bottom: 12px; transition: all 0.2s;
}
.btn-expand:hover { border-color: var(--accent); }
.btn-expand svg { width: 12px; height: 12px; stroke: var(--text-muted); fill: none; stroke-width: 2; }

.ad-list-item {
  padding: 10px 14px; cursor: pointer; transition: background 0.15s;
  border-left: 3px solid transparent;
}
.ad-list-item:hover { background: var(--bg-hover); }
.ad-list-item.active { background: var(--accent-bg); border-left-color: var(--accent); }
.ad-list-name { font-size: 12px; color: var(--text-primary); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ad-list-meta { font-size: 10px; color: var(--text-muted); }
.ad-list-empty { padding: 20px 14px; font-size: 11px; color: var(--text-dim); text-align: center; }
.ad-list-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.ad-list-dot.active { background: var(--green); }
.ad-list-dot.paused { background: var(--yellow); }
.ad-list-dot.ended { background: var(--red); }

/* ===== LEFT PANEL ===== */
#controls {
  width: 400px; flex-shrink: 0; overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 16px 16px 40px;
  transition: width 0.25s ease;
}

/* ===== SECTIONS ===== */
.section {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: 12px; overflow: hidden;
  transition: background 0.3s, border-color 0.3s;
}
.section-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; background: none; border: none; cursor: pointer;
  color: var(--text-primary); font-family: 'DM Mono', monospace; font-size: 12px;
  font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase;
}
.section-toggle .icon-label { display: flex; align-items: center; gap: 8px; }
.section-toggle .arrow-icon { transition: transform 0.2s; }
.section-toggle .arrow-icon svg { width: 12px; height: 12px; stroke: var(--text-muted); }
.section.open .section-toggle .arrow-icon { transform: rotate(180deg); }
.section-body { display: none; padding: 4px 16px 16px; border-top: 1px solid var(--border); }
.section.open .section-body { display: block; }

/* ===== ROWS ===== */
.row { display: flex; align-items: flex-start; gap: 12px; margin-top: 13px; }
.row-label { min-width: 125px; padding-top: 6px; color: var(--text-secondary); font-size: 12px; font-family: 'DM Mono', monospace; }
.row-hint { color: var(--text-muted); font-size: 10px; margin-top: 2px; }
.row-ctrl { flex: 1; }
.sub-heading { margin-top: 10px; margin-bottom: 6px; color: var(--text-dim); font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; }

/* ===== INPUTS ===== */
input[type="text"], input[type="number"], input[type="date"], input[type="time"] {
  background: var(--bg-input); border: 1px solid var(--border-input);
  border-radius: 6px; padding: 6px 10px; color: var(--text-primary); font-size: 13px;
  font-family: 'DM Mono', monospace; width: 100%; outline: none;
  transition: border-color 0.2s, background 0.3s;
}
input:focus, textarea:focus { border-color: var(--accent) !important; }
select {
  background: var(--select-bg); border: 1px solid var(--border-input);
  border-radius: 6px; padding: 6px 10px; color: var(--text-primary); font-size: 13px;
  font-family: 'DM Mono', monospace; width: 100%; outline: none;
  transition: background 0.3s;
}
textarea {
  background: var(--bg-input); border: 1px solid var(--border-input);
  border-radius: 6px; padding: 8px 10px; color: var(--text-primary); font-size: 12px;
  font-family: 'DM Mono', monospace; width: 100%; outline: none; resize: vertical;
  transition: background 0.3s;
}
input[type="range"] { width: calc(100% - 50px); accent-color: var(--accent); height: 4px; vertical-align: middle; }
.range-val { display: inline-block; width: 44px; text-align: right; color: var(--accent); font-size: 12px; font-family: 'DM Mono', monospace; }
.color-row { display: flex; align-items: center; gap: 8px; }
.color-row input[type="color"] { width: 32px; height: 32px; border-radius: 6px; border: none; cursor: pointer; background: none; flex-shrink: 0; }
.color-row input[type="text"] { flex: 1; }

/* ===== TOGGLE ===== */
.toggle {
  width: 38px; height: 20px; border-radius: 99px; position: relative;
  background: var(--bg-input); transition: background 0.2s; cursor: pointer; flex-shrink: 0;
  border: 1px solid var(--border-input);
}
.toggle.on { background: var(--accent); border-color: var(--accent); }
.toggle-knob {
  width: 14px; height: 14px; border-radius: 50%; background: #fff;
  position: absolute; top: 2px; left: 2px; transition: left 0.2s;
}
.toggle.on .toggle-knob { left: 20px; }

/* ===== BUTTON GROUP ===== */
.btn-group { display: flex; gap: 6px; }
.btn-group button {
  flex: 1; padding: 6px 0; border-radius: 6px; font-size: 11px;
  cursor: pointer; font-family: 'DM Mono', monospace;
  border: 1px solid var(--border); background: transparent; color: var(--text-muted);
  transition: all 0.2s;
}
.btn-group button.active { border-color: var(--accent); background: var(--accent-bg); color: var(--accent-light); }

/* ===== CHIPS ===== */
.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 4px 10px; border-radius: 99px; font-size: 11px; cursor: pointer;
  font-family: 'DM Mono', monospace; background: var(--bg-input);
  color: var(--text-muted); border: 1px solid var(--border); transition: all 0.2s;
}
.chip.active { background: var(--accent-bg); color: var(--accent-light); border-color: var(--accent); }

/* ===== DAY GROUP ===== */
.day-group { display: flex; gap: 4px; }
.day {
  width: 34px; height: 30px; border-radius: 6px; font-size: 10px; cursor: pointer;
  font-family: 'DM Mono', monospace; background: var(--bg-input);
  color: var(--text-muted); border: 1px solid var(--border); transition: all 0.2s;
}
.day.active { background: var(--accent-bg); color: var(--accent-light); border-color: var(--accent); }

/* ===== RIGHT PANEL ===== */
#preview-panel { flex: 1; overflow-y: auto; padding: 24px; }

/* ===== TABS ===== */
.tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tab {
  padding: 8px 18px; border-radius: 8px; font-size: 12px; cursor: pointer;
  font-family: 'DM Mono', monospace; text-transform: uppercase; letter-spacing: 0.08em;
  background: var(--bg-card); color: var(--text-muted); border: 1px solid var(--border); transition: all 0.2s;
}
.tab.active { background: var(--accent-bg); color: var(--accent-light); border-color: var(--accent); }

/* ===== TAB CONTENT ===== */
.tab-content { display: none; }
.tab-content.active { display: block; }
.preview-label { margin-bottom: 16px; color: var(--text-dim); font-size: 11px; letter-spacing: 0.06em; }
.preview-box {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px; margin-bottom: 16px; transition: all 0.3s;
}
.preview-device-label { margin-bottom: 12px; color: var(--text-dim); font-size: 10px; }

/* ===== AD PREVIEW ===== */
.ad-preview { position: relative; font-family: 'DM Mono', monospace; overflow: hidden; }
.ad-close-btn {
  position: absolute; top: 8px; right: 8px; width: 20px; height: 20px;
  background: rgba(0,0,0,0.2); border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 10px;
  color: #fff; cursor: pointer; border: none;
}
.ad-image-placeholder {
  width: 100%; height: 80px; background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 11px; margin-bottom: 8px;
}
.ad-cta-btn { border: none; cursor: pointer; }

/* ===== SUMMARY ===== */
.summary-box {
  background: var(--accent-bg); border: 1px solid rgba(59,130,246,0.15);
  border-radius: 12px; padding: 20px;
}
.summary-title { color: var(--accent-light); font-size: 12px; margin-bottom: 12px; letter-spacing: 0.06em; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.summary-item { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); }
.summary-key { color: var(--text-muted); font-size: 11px; }
.summary-val { color: var(--text-secondary); font-size: 11px; }

/* ===== CODE TAB ===== */
.code-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
#copyBtn {
  padding: 6px 16px; border-radius: 6px; font-size: 11px; cursor: pointer;
  background: var(--accent-bg); border: 1px solid var(--accent);
  color: var(--accent-light); font-family: 'DM Mono', monospace; transition: all 0.2s;
}
#copyBtn.copied { background: var(--green-bg); border-color: var(--green); color: var(--green); }
.code-block {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; color: var(--text-secondary); font-size: 11px;
  line-height: 1.7; overflow: auto; white-space: pre-wrap;
  font-family: 'DM Mono', monospace; max-height: 70vh; transition: all 0.3s;
}
.code-warning {
  margin-top: 12px; padding: 16px; background: var(--yellow-bg);
  border: 1px solid var(--yellow-border); border-radius: 8px;
  color: var(--yellow); font-size: 11px; line-height: 1.6;
}

/* ===== HIDDEN ===== */
.hidden { display: none !important; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) { #adListPanel { display: none; } }
@media (max-width: 900px) {
  .app-layout { flex-direction: column; height: auto; }
  #controls { width: 100%; border-right: none; border-bottom: 1px solid var(--border); max-height: 50vh; }
  #preview-panel { max-height: 50vh; }
  body { overflow: auto; }
  #adListPanel { display: none; }
  .header-actions { gap: 4px; }
  .btn-action span { display: none; }
}