/* =========================================================
   Minoan Media · GAM Panel · Glass theme (light + dark)
   ========================================================= */

:root[data-theme="dark"] {
  --bg-base:         #0a0d18;
  --bg-grad-1:       #18103a;
  --bg-grad-2:       #062a3b;
  --blob-1:          #6b3bff;
  --blob-2:          #18d4cd;
  --blob-3:          #ff6bb5;

  --glass-bg:        rgba(20, 24, 40, .55);
  --glass-bg-strong: rgba(28, 32, 50, .72);
  --glass-border:    rgba(255, 255, 255, .08);
  --glass-shine:     rgba(255, 255, 255, .04);

  --text:            #e9ecf6;
  --text-dim:        #99a3c1;
  --text-faint:      rgba(255, 255, 255, .55);

  --accent:          #a4f0c0;
  --accent-2:        #7ad3ff;
  --accent-grad:     linear-gradient(135deg, #a4f0c0, #7ad3ff);
  --warn:            #ffd07a;
  --bad:             #ff8b8b;

  --shadow-sm:       0 2px 10px rgba(0,0,0,.25);
  --shadow:          0 14px 40px rgba(0,0,0,.45);
  --shadow-glow:     0 0 0 1px rgba(255,255,255,.05) inset, 0 14px 40px rgba(0,0,0,.45);

  --line-soft:       rgba(255,255,255,.06);
  --row-hover:       rgba(255,255,255,.04);

  --code-bg:         rgba(255,255,255,.07);
  --pre-bg:          rgba(8, 12, 24, .6);
}

:root[data-theme="light"] {
  --bg-base:         #f3f1ff;
  --bg-grad-1:       #ffe6f6;
  --bg-grad-2:       #d4f1ff;
  --blob-1:          #b39bff;
  --blob-2:          #74e8d9;
  --blob-3:          #ffb1d9;

  --glass-bg:        rgba(255, 255, 255, .55);
  --glass-bg-strong: rgba(255, 255, 255, .8);
  --glass-border:    rgba(255, 255, 255, .55);
  --glass-shine:     rgba(255, 255, 255, .35);

  --text:            #1a1d2e;
  --text-dim:        #5d6584;
  --text-faint:      rgba(20, 24, 40, .55);

  --accent:          #2a8855;
  --accent-2:        #1f7ab0;
  --accent-grad:     linear-gradient(135deg, #5acd9c, #5cb5e8);
  --warn:            #c97a00;
  --bad:             #d23a3a;

  --shadow-sm:       0 2px 14px rgba(80, 60, 130, .12);
  --shadow:          0 18px 50px rgba(80, 60, 130, .18);
  --shadow-glow:     0 0 0 1px rgba(255,255,255,.6) inset, 0 18px 50px rgba(80, 60, 130, .18);

  --line-soft:       rgba(20, 24, 40, .07);
  --row-hover:       rgba(255, 255, 255, .35);

  --code-bg:         rgba(20, 24, 40, .06);
  --pre-bg:          rgba(255, 255, 255, .65);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg-base);
  color: var(--text);
  font: 14px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body { display: grid; grid-template-columns: 250px 1fr; }
a { color: inherit; text-decoration: none; }
code { background: var(--code-bg); padding: 1px 6px; border-radius: 6px; font-size: .9em; }

/* ---------- Animated mesh background ---------- */
.mesh {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background: radial-gradient(120% 80% at 0% 0%, var(--bg-grad-1), transparent 60%),
              radial-gradient(120% 80% at 100% 100%, var(--bg-grad-2), transparent 60%),
              var(--bg-base);
}
.blob {
  position: absolute; border-radius: 50%;
  filter: blur(80px); opacity: .55;
  animation: float 22s ease-in-out infinite alternate;
}
.blob.b1 { width: 540px; height: 540px; background: var(--blob-1); top: -10%; left: -10%; }
.blob.b2 { width: 600px; height: 600px; background: var(--blob-2); bottom: -20%; right: -15%; animation-duration: 28s; }
.blob.b3 { width: 380px; height: 380px; background: var(--blob-3); top: 35%; right: 10%; animation-duration: 34s; opacity: .35; }
@keyframes float {
  0%   { transform: translate(0,0) scale(1); }
  50%  { transform: translate(40px, -30px) scale(1.06); }
  100% { transform: translate(-30px, 40px) scale(.94); }
}

/* ---------- Glass primitive ---------- */
.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  border-radius: 20px;
  box-shadow: var(--shadow-glow);
  position: relative;
}
.glass::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(135deg, var(--glass-shine), transparent 40%);
  opacity: .9;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky; top: 12px; align-self: start;
  height: calc(100vh - 24px);
  margin: 12px 0 12px 12px;
  padding: 22px 16px 16px;
  display: flex; flex-direction: column; gap: 18px;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 4px 14px; border-bottom: 1px solid var(--line-soft); position: relative; }
.logo {
  width: 44px; height: 44px; border-radius: 14px;
  background: var(--accent-grad);
  color: #0b0f1d; display: grid; place-items: center;
  font-weight: 800; letter-spacing: 1px;
  box-shadow: 0 6px 18px rgba(122, 211, 255, .3);
}
.brand-title { font-weight: 700; }
.brand-sub { color: var(--text-dim); font-size: 12px; }

nav { display: flex; flex-direction: column; gap: 3px; position: relative; }
.nav-item {
  padding: 10px 12px; border-radius: 12px;
  color: var(--text-dim);
  display: flex; align-items: center; gap: 12px;
  font-weight: 500;
  transition: background .2s ease, color .2s ease, transform .2s ease;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .9; }
.nav-item:hover { background: var(--glass-shine); color: var(--text); transform: translateX(2px); }
.nav-item.active {
  background: var(--glass-bg-strong); color: var(--text);
  box-shadow: 0 4px 12px rgba(0,0,0,.1), inset 0 0 0 1px var(--glass-border);
}

.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line-soft); position: relative; }
.sidebar-foot code { font-size: 11px; word-break: break-all; }

/* ---------- Main / topbar ---------- */
main { padding: 12px 18px 60px 18px; max-width: 100%; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 18px;
  padding: 14px 20px; margin-bottom: 18px;
}
.topbar-left h1 { margin: 0 0 2px; font-size: 22px; letter-spacing: -.2px; }
.topbar-right { display: flex; gap: 8px; align-items: center; }

.muted { color: var(--text-dim); }
.small { font-size: 12px; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

select, input[type=text], input:not([type]), textarea {
  background: var(--glass-bg);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 9px 14px;
  font: inherit;
  outline: none;
  backdrop-filter: blur(8px);
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}
select.ghost, input.ghost { background: transparent; }
select:focus, input:focus, textarea:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-2) 22%, transparent);
}

.btn {
  background: var(--glass-bg);
  color: var(--text);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 9px 16px;
  cursor: pointer;
  font: inherit; font-weight: 500;
  display: inline-flex; align-items: center; gap: 8px;
  transition: transform .15s ease, background .2s ease, box-shadow .2s ease;
  backdrop-filter: blur(8px);
}
.btn:hover { background: var(--glass-bg-strong); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary {
  background: var(--accent-grad);
  color: #0b0f1d; border: none; font-weight: 600;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent-2) 35%, transparent);
}
.btn.primary:hover { box-shadow: 0 10px 24px color-mix(in srgb, var(--accent-2) 45%, transparent); }
.btn.ghost { background: transparent; }
.icon-btn { padding: 9px; }

/* Theme toggle: show only the right icon per theme */
:root[data-theme="dark"]  #theme-toggle .icon-sun  { display: none; }
:root[data-theme="light"] #theme-toggle .icon-moon { display: none; }

/* ---------- Cards / KPI ---------- */
.card { padding: 22px; margin-bottom: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 16px; letter-spacing: -.1px; }

.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  padding: 18px 20px;
  display: flex; align-items: center; gap: 14px;
  position: relative;
  transition: transform .25s ease, box-shadow .25s ease;
}
.kpi:hover { transform: translateY(-3px); }
.kpi-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--glass-bg-strong);
  display: grid; place-items: center;
  color: var(--accent-2);
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px var(--glass-border);
}
.kpi-icon svg { width: 22px; height: 22px; }
.kpi-meta { min-width: 0; }
.kpi-label { color: var(--text-dim); text-transform: uppercase; font-size: 10.5px; letter-spacing: 1.4px; font-weight: 600; }
.kpi-value { font-size: 24px; font-weight: 700; margin-top: 2px; line-height: 1.2; letter-spacing: -.3px; }
.kpi-value span { font-variant-numeric: tabular-nums; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

@media (max-width: 1280px) { .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: column; margin: 12px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- Tables ---------- */
.table-scroll { overflow: auto; max-height: 580px; border-radius: 14px; }
.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data th, .data td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
.data th {
  text-align: left; color: var(--text-dim); font-weight: 600;
  position: sticky; top: 0; background: var(--glass-bg-strong);
  backdrop-filter: blur(12px); z-index: 1;
}
.data tbody tr { transition: background .15s ease; }
.data tbody tr:hover { background: var(--row-hover); }
.data .badge {
  padding: 2px 10px; border-radius: 999px;
  background: var(--glass-bg-strong); font-size: 12px; color: var(--text-dim);
  border: 1px solid var(--glass-border);
}
.data .badge.ok   { color: var(--accent); }
.data .badge.warn { color: var(--warn); }
.data .badge.bad  { color: var(--bad); }

/* ---------- Charts ---------- */
.chart-wrap { position: relative; height: 320px; }

/* ---------- Builder / Explorer ---------- */
.builder { display: grid; grid-template-columns: 1fr 1fr 200px; gap: 18px; align-items: start; }
.builder label { display: block; color: var(--text-dim); margin-bottom: 6px; font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.builder select[multiple] { width: 100%; min-height: 230px; padding: 8px 10px; }
.builder-actions { display: flex; flex-direction: column; gap: 10px; }

.explorer { display: grid; grid-template-columns: 130px 1fr 130px; gap: 10px; margin-bottom: 12px; }
#ex-body { width: 100%; font: 13px ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
#ex-response {
  background: var(--pre-bg);
  border: 1px solid var(--glass-border); border-radius: 12px; padding: 14px;
  color: var(--text); white-space: pre-wrap; word-break: break-word;
  max-height: 540px; overflow: auto;
  font: 12.5px ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  backdrop-filter: blur(8px);
}

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  padding: 12px 18px;
  opacity: 0; transform: translateY(10px) scale(.96);
  transition: all .25s cubic-bezier(.4, 0, .2, 1);
  pointer-events: none;
  max-width: 360px;
  font-weight: 500;
}
#toast.show { opacity: 1; transform: translateY(0) scale(1); }
#toast.err  { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
#toast.ok   { color: var(--accent); }

.hidden { display: none !important; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 100; display: grid; place-items: center; padding: 20px; backdrop-filter: blur(8px); animation: fadein .2s ease; }
.modal-card { width: 100%; max-width: 520px; padding: 24px 26px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form .field { display: flex; flex-direction: column; gap: 6px; }
.login-form label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; font-weight: 600; }
.net-checks { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow: auto; padding: 8px 12px; border: 1px solid var(--glass-border); border-radius: 12px; background: var(--glass-bg); }
.net-checks label { display: flex; align-items: center; gap: 10px; padding: 4px 0; cursor: pointer; text-transform: none; letter-spacing: 0; font-size: 13.5px; color: var(--text); font-weight: 400; }
.net-checks input[type=checkbox] { accent-color: var(--accent-2); }
.role-pill { padding: 2px 10px; border-radius: 999px; font-size: 12px; background: var(--glass-bg-strong); border: 1px solid var(--glass-border); }
.role-pill.admin { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions button { padding: 5px 10px; font-size: 12px; }

/* ---------- Section transition ---------- */
.view { animation: fadein .35s ease both; }
@keyframes fadein {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Scrollbar styling ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--glass-bg-strong); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--accent-2) 50%, transparent); background-clip: padding-box; }
