/* ═══════════════════════════════════════════════════════
   Grafana Dashboard Builder — Global Design System
   ═══════════════════════════════════════════════════════ */
:root {
  --bg:          #111217;
  --bg-panel:    #1f2235;
  --bg-sidebar:  #0b0c10;
  --bg-card:     #181b2e;
  --bg-input:    #0d0e14;
  --bg-modal:    #1a1d2e;
  --border:      #22253a;
  --border-l:    #383b4a;
  --text:        #d9d9d9;
  --text-muted:  #8e8e8e;
  --text-dim:    #4a4a5a;
  --orange:      #f58400;
  --orange-dim:  rgba(245,132,0,0.15);
  --orange-glow: rgba(245,132,0,0.08);
  --blue:        #5794f2;
  --blue-dim:    rgba(87,148,242,0.15);
  --green:       #73bf69;
  --green-dim:   rgba(115,191,105,0.15);
  --yellow:      #fade2a;
  --yellow-dim:  rgba(250,222,42,0.12);
  --red:         #f2495c;
  --red-dim:     rgba(242,73,92,0.15);
  --purple:      #b877d9;
  --purple-dim:  rgba(184,119,217,0.15);
  --cyan:        #37872d;
  --teal:        #00c9c9;
  --pink:        #ff7f7f;
  --header-h:    56px;
  --sidebar-w:   280px;
  --radius:      6px;
  --radius-lg:   10px;
  --shadow:      0 4px 20px rgba(0,0,0,0.5);
  --shadow-panel:0 2px 10px rgba(0,0,0,0.4);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Typography ────────────────────────────────────────── */
h1 { font-size: 28px; font-weight: 700; line-height: 1.2; }
h2 { font-size: 20px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
h4 { font-size: 14px; font-weight: 600; }
p  { color: var(--text-muted); line-height: 1.7; }
a  { color: var(--orange); text-decoration: none; }
a:hover { text-decoration: underline; }
strong { color: var(--text); font-weight: 600; }
code {
  font-family: 'JetBrains Mono', Consolas, monospace;
  font-size: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-l);
  border-radius: 4px;
  padding: 2px 6px;
  color: var(--orange);
}

/* ── Scrollbars ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-l); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
  white-space: nowrap;
  font-family: inherit;
  text-decoration: none !important;
}
.btn-primary {
  background: var(--orange);
  color: #111;
  border-color: var(--orange);
}
.btn-primary:hover { background: #ff9800; filter: brightness(1.1); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border-color: var(--border-l);
}
.btn-secondary:hover { background: var(--border); border-color: var(--border-l); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-card); color: var(--text); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: var(--red-dim);
}
.btn-danger:hover { background: var(--red-dim); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 10px 24px; font-size: 15px; }
.btn-icon { padding: 7px; width: 34px; height: 34px; justify-content: center; }

/* ── Top Bar ────────────────────────────────────────────── */
.topbar {
  height: var(--header-h);
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 200;
}
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none !important;
  white-space: nowrap;
}
.topbar-logo .logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--orange), #ff5722);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.topbar-logo span { color: var(--orange); }
.topbar-divider { width: 1px; height: 24px; background: var(--border-l); }
.topbar-nav { display: flex; gap: 2px; margin-left: 8px; }
.topbar-nav a {
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  transition: all 0.15s;
}
.topbar-nav a:hover, .topbar-nav a.active {
  background: var(--bg-card);
  color: var(--text);
}
.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ── Hero ───────────────────────────────────────────────── */
.hero {
  position: relative;
  overflow: hidden;
  padding: 80px 48px;
  text-align: center;
  background:
    radial-gradient(ellipse 70% 50% at 30% 100%, rgba(245,132,0,0.12) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 20%,  rgba(87,148,242,0.08) 0%, transparent 60%),
    var(--bg);
}
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: 0.3;
}
.hero-content { position: relative; z-index: 1; max-width: 720px; margin: 0 auto; }
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--orange-dim);
  border: 1px solid rgba(245,132,0,0.3);
  color: var(--orange);
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 20px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.hero h1 { font-size: 48px; margin-bottom: 16px; line-height: 1.15; }
.hero h1 em { font-style: normal; color: var(--orange); }
.hero p { font-size: 18px; color: var(--text-muted); margin-bottom: 32px; max-width: 580px; margin-left: auto; margin-right: auto; }
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.hero-stats {
  display: flex;
  gap: 40px;
  justify-content: center;
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}
.hero-stat-num { font-size: 28px; font-weight: 700; color: var(--orange); }
.hero-stat-lbl { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* ── Section ────────────────────────────────────────────── */
.section { padding: 60px 48px; }
.section-head { margin-bottom: 36px; }
.section-head .tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--orange);
  margin-bottom: 8px;
  display: block;
}
.section-head h2 { font-size: 28px; margin-bottom: 10px; }
.section-head p { font-size: 16px; max-width: 540px; }

/* ── Template Cards ─────────────────────────────────────── */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
}
.template-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
}
.template-card:hover {
  border-color: var(--orange);
  box-shadow: 0 0 0 1px var(--orange), var(--shadow);
  transform: translateY(-3px);
}
.template-card:hover .tc-preview { opacity: 1; }
.tc-preview {
  height: 200px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  opacity: 0.9;
  transition: opacity 0.2s;
}
.tc-preview svg, .tc-preview canvas { width: 100%; height: 100%; }
.tc-meta { padding: 18px 20px; flex: 1; }
.tc-category {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 6px;
}
.tc-title { font-size: 16px; font-weight: 700; margin-bottom: 6px; color: var(--text); }
.tc-desc { font-size: 13px; color: var(--text-muted); line-height: 1.5; margin-bottom: 14px; }
.tc-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tc-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border-l);
  color: var(--text-dim);
}
.tc-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tc-panels { font-size: 12px; color: var(--text-dim); }
.tc-actions { display: flex; gap: 6px; }

/* ── Filter Bar ─────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.filter-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-l);
  border-radius: var(--radius);
  padding: 0 12px;
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}
.filter-search input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  padding: 8px 0;
  width: 100%;
  font-family: inherit;
}
.filter-search input::placeholder { color: var(--text-dim); }
.filter-search .icon { color: var(--text-dim); font-size: 14px; }
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-l);
  background: var(--bg-card);
  color: var(--text-muted);
  transition: all 0.15s;
}
.chip:hover, .chip.active {
  background: var(--orange-dim);
  border-color: rgba(245,132,0,0.4);
  color: var(--orange);
}

/* ── Feature List ───────────────────────────────────────── */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}
.feature-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin-bottom: 14px;
  background: var(--orange-dim);
}
.feature-card h3 { font-size: 15px; margin-bottom: 8px; }
.feature-card p { font-size: 13px; line-height: 1.6; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge-orange { background: var(--orange-dim); color: var(--orange); border: 1px solid rgba(245,132,0,0.3); }
.badge-blue   { background: var(--blue-dim);   color: var(--blue);   border: 1px solid rgba(87,148,242,0.3); }
.badge-green  { background: var(--green-dim);  color: var(--green);  border: 1px solid rgba(115,191,105,0.3); }
.badge-red    { background: var(--red-dim);    color: var(--red);    border: 1px solid rgba(242,73,92,0.3); }
.badge-purple { background: var(--purple-dim); color: var(--purple); border: 1px solid rgba(184,119,217,0.3); }

/* ── Toast ──────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-modal);
  border: 1px solid var(--border-l);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  box-shadow: var(--shadow);
  animation: slideIn 0.2s ease;
}
.toast-success { border-left: 3px solid var(--green); }
.toast-error   { border-left: 3px solid var(--red); }
.toast-info    { border-left: 3px solid var(--blue); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* ── Modal ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border-l);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  animation: scaleIn 0.15s ease;
}
@keyframes scaleIn { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-wide { max-width: 960px; }
.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* ── Form Fields ────────────────────────────────────────── */
.form-row { margin-bottom: 18px; }
.form-row label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-l);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.form-control:focus { border-color: var(--orange); }
.form-control::placeholder { color: var(--text-dim); }
textarea.form-control { resize: vertical; min-height: 80px; font-family: 'JetBrains Mono', monospace; font-size: 12px; }
select.form-control { cursor: pointer; }

.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ── Tabs ───────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--orange); border-bottom-color: var(--orange); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Panel Type Selector ────────────────────────────────── */
.panel-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
}
.panel-type-option {
  background: var(--bg-input);
  border: 2px solid var(--border-l);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}
.panel-type-option:hover { border-color: var(--orange); background: var(--orange-dim); }
.panel-type-option.active { border-color: var(--orange); background: var(--orange-dim); color: var(--orange); }
.panel-type-option .pto-icon { font-size: 24px; margin-bottom: 6px; }
.panel-type-option .pto-name { font-size: 11px; font-weight: 600; }

/* ── Color Picker Row ───────────────────────────────────── */
.color-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.color-swatch {
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: white; }

/* ── Threshold Editor ───────────────────────────────────── */
.threshold-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.threshold-row input[type=number] { flex: 1; }
.threshold-color-dot {
  width: 24px; height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Connection Panel ───────────────────────────────────── */
.connection-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}
.connection-panel h4 { margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.connection-status { font-size: 12px; padding: 3px 10px; border-radius: 10px; }
.connection-status.connected  { background: var(--green-dim); color: var(--green); }
.connection-status.disconnected { background: var(--red-dim); color: var(--red); }

/* ── Footer ─────────────────────────────────────────────── */
footer {
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border);
  padding: 24px 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-dim);
}
footer a { color: var(--text-muted); }
footer a:hover { color: var(--orange); text-decoration: none; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .section { padding: 40px 20px; }
  .hero { padding: 48px 20px; }
  .hero h1 { font-size: 32px; }
  .hero-stats { gap: 24px; flex-wrap: wrap; }
  .template-grid { grid-template-columns: 1fr; }
  .feature-grid { grid-template-columns: 1fr; }
  footer { flex-direction: column; gap: 12px; text-align: center; }
  .topbar-nav { display: none; }
}
