/* ===================================================================
   HaiMMO.me Smart Ads — Dark Admin Dashboard
   Self-contained. CSS variables. No framework.
   =================================================================== */

:root {
  --bg:            #0b0f17;
  --bg-elev:       #111726;
  --bg-elev-2:     #161e30;
  --bg-hover:      #1b2538;
  --line:          #233045;
  --line-soft:     #1a2436;

  --text:          #e6edf6;
  --text-dim:      #9fb0c6;
  --text-mute:     #6b7c95;

  --brand:         #5b8cff;
  --brand-2:       #7c4dff;
  --brand-glow:    rgba(91,140,255,.35);

  --good:          #2fd07a;
  --good-soft:     rgba(47,208,122,.14);
  --warn:          #ffb23e;
  --warn-soft:     rgba(255,178,62,.14);
  --bad:           #ff5d6c;
  --bad-soft:      rgba(255,93,108,.14);
  --info:          #41c7e8;
  --info-soft:     rgba(65,199,232,.14);

  --radius:        14px;
  --radius-sm:     9px;
  --shadow:        0 8px 30px rgba(0,0,0,.40);
  --shadow-sm:     0 2px 10px rgba(0,0,0,.30);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --topbar-h: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1100px 500px at 80% -10%, rgba(124,77,255,.10), transparent 60%),
    radial-gradient(900px 400px at -5% 0%, rgba(91,140,255,.10), transparent 55%),
    var(--bg);
  min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
b, strong { font-weight: 650; }
.muted { color: var(--text-mute); font-weight: 500; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ===================== TOPBAR ===================== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 0 18px;
  background: rgba(13,18,28,.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 13px; letter-spacing: .5px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 0 18px var(--brand-glow);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text strong { font-size: 15px; }
.brand-text small { color: var(--text-mute); font-size: 11px; letter-spacing: .6px; text-transform: uppercase; }

.env-pill {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  color: var(--text-dim);
}

.topbar-divider { width: 1px; height: 26px; background: var(--line); }

.quick-actions { display: flex; gap: 6px; }

.user-chip {
  display: flex; align-items: center; gap: 9px;
  padding: 5px 10px 5px 5px; border-radius: 999px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #fff;
  background: linear-gradient(135deg, var(--brand-2), var(--brand));
}
.user-meta { display: flex; flex-direction: column; line-height: 1.1; }
.user-email { font-size: 12.5px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 10.5px; color: var(--text-mute); text-transform: uppercase; letter-spacing: .5px; }

/* ===================== BUTTONS ===================== */
.btn {
  font-family: inherit; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 7px 12px; cursor: pointer; color: var(--text);
  background: var(--bg-elev-2);
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, border-color .15s, transform .05s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: #2c3c57; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn .ico { font-size: 14px; line-height: 1; }

.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-color: transparent; color: #fff;
  box-shadow: 0 0 16px var(--brand-glow);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--bad); border-color: transparent; color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-icon { padding: 7px 9px; }
.btn-xs { padding: 4px 8px; font-size: 11.5px; border-radius: 7px; }

.btn:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
  box-shadow: 0 0 0 3px var(--brand-glow);
}
.btn.busy { position: relative; color: transparent !important; pointer-events: none; }
.btn.busy::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== TABS ===================== */
.tabs {
  display: flex; align-items: center; gap: 4px;
  padding: 10px 18px 0; border-bottom: 1px solid var(--line);
  position: sticky; top: var(--topbar-h); z-index: 40;
  background: rgba(11,15,23,.9); backdrop-filter: blur(8px);
}
.tab {
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  color: var(--text-dim); background: transparent; border: 0;
  padding: 9px 14px; cursor: pointer; border-radius: 9px 9px 0 0;
  border-bottom: 2px solid transparent; position: relative; top: 1px;
}
.tab:hover { color: var(--text); background: var(--bg-elev); }
.tab:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; border-radius: 9px; }
.tab.active { color: var(--text); border-bottom-color: var(--brand); }
.tab[aria-selected="true"] { color: var(--text); }
.tab[hidden] { display: none; }
.tabs-status {
  margin-left: auto; display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-mute); padding-bottom: 6px;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--good);
  box-shadow: 0 0 8px var(--good); animation: pulse 2s ease-in-out infinite;
}
.dot.paused { background: var(--warn); box-shadow: 0 0 8px var(--warn); animation: none; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

/* ===================== LAYOUT ===================== */
.content { padding: 18px; max-width: 1500px; margin: 0 auto; }
.panel { display: none; animation: fade .2s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 14px; flex-wrap: wrap;
}
.section-head h2 { margin: 0; font-size: 19px; }
.section-head h2 small { font-size: 13px; }

.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.window-info { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--text-dim);
}
.chip b { color: var(--text); }

/* ===================== CARDS ===================== */
.card {
  background: linear-gradient(180deg, var(--bg-elev), var(--bg-elev-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow-sm); margin-bottom: 16px;
}
.card.no-pad { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px; flex-wrap: wrap;
}
.card-head h3 { margin: 0; font-size: 15px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ===================== KPI ===================== */
.kpi-grid {
  display: grid; gap: 14px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}
.kpi {
  background: linear-gradient(180deg, var(--bg-elev), var(--bg-elev-2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 15px; position: relative; overflow: hidden;
}
.kpi::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--brand);
}
.kpi.good::before { background: var(--good); }
.kpi.bad::before  { background: var(--bad); }
.kpi.warn::before { background: var(--warn); }
.kpi-label { font-size: 11.5px; color: var(--text-mute); text-transform: uppercase; letter-spacing: .5px; }
.kpi-value { font-size: 23px; font-weight: 750; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.kpi-delta { font-weight: 650; }
.kpi-delta.up { color: var(--good); }
.kpi-delta.down { color: var(--bad); }

/* ===================== CHART ===================== */
.chart-wrap { position: relative; min-height: 220px; }
.chart-wrap-tall { min-height: 300px; }

/* trend card range selector */
.trend-controls { display: flex; align-items: center; gap: 8px; }
.trend-controls label { font-size: 12px; }
.trend-controls .input { min-width: 110px; padding: 5px 9px; }

/* maintenance action buttons (Schedule tab) */
.maint-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }

/* ===================== TABLES ===================== */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
.data-table thead th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--text-mute); font-weight: 650; background: var(--bg-elev);
  position: sticky; top: 0;
}
.data-table.sticky thead th { z-index: 2; }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.controls-col { width: 1%; }

.cell-strong { color: var(--text); font-weight: 600; }
.cell-sub { color: var(--text-mute); font-size: 11.5px; }

.confidence { font-family: var(--mono); font-size: 11.5px; color: var(--text-dim); }

/* editable rules grid */
.data-table.editable td { padding: 0; }
.data-table.editable td input {
  width: 100%; min-width: 110px; border: 0; background: transparent;
  color: var(--text); font-family: inherit; font-size: 12.5px; padding: 8px 12px;
}
.data-table.editable td input:focus {
  outline: 2px solid var(--brand); outline-offset: -2px; background: var(--bg-hover);
}
.data-table.editable td.row-tools { padding: 4px 8px; }

/* ===================== BADGES ===================== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 650; padding: 3px 8px; border-radius: 999px;
  border: 1px solid transparent; line-height: 1.4; white-space: nowrap;
}
.badge.good    { background: var(--good-soft); color: var(--good); border-color: rgba(47,208,122,.3); }
.badge.bad     { background: var(--bad-soft);  color: var(--bad);  border-color: rgba(255,93,108,.3); }
.badge.warn    { background: var(--warn-soft); color: var(--warn); border-color: rgba(255,178,62,.3); }
.badge.info    { background: var(--info-soft); color: var(--info); border-color: rgba(65,199,232,.3); }
.badge.neutral { background: var(--bg-elev-2); color: var(--text-dim); border-color: var(--line); }

.flag {
  font-size: 10.5px; padding: 2px 6px; border-radius: 6px; margin: 1px;
  display: inline-block; background: var(--warn-soft); color: var(--warn);
  border: 1px solid rgba(255,178,62,.25);
}

.mar-good { color: var(--good); font-weight: 650; }
.mar-bad  { color: var(--bad);  font-weight: 650; }
.mar-mid  { color: var(--warn); font-weight: 650; }

/* row controls */
.row-ctrls { display: inline-flex; gap: 4px; }

/* ===================== ALERTS ===================== */
.alert-counts { display: flex; gap: 6px; }
.alerts-list { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; }
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg-elev-2);
}
.alert .alert-ico { font-size: 14px; line-height: 1.3; }
.alert.critical { border-left: 3px solid var(--bad); }
.alert.critical .alert-ico { color: var(--bad); }
.alert.warning  { border-left: 3px solid var(--warn); }
.alert.warning .alert-ico { color: var(--warn); }
.alert.info     { border-left: 3px solid var(--info); }
.alert.info .alert-ico { color: var(--info); }
.alert-msg { font-size: 12.5px; }
.alert-cid { font-size: 11px; color: var(--text-mute); font-family: var(--mono); }

.empty { padding: 26px; text-align: center; color: var(--text-mute); font-size: 13px; }

/* ===================== INPUTS ===================== */
.input {
  font-family: inherit; font-size: 13px; color: var(--text);
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 7px 11px; min-width: 120px;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-glow); }
select.input { cursor: pointer; }

/* ===================== SCHEDULE ===================== */
.schedule-card { max-width: 520px; }
.sched-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.sched-row:last-child { border-bottom: 0; }
.sched-text { display: flex; flex-direction: column; }
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer; border-radius: 999px;
  background: var(--bg-hover); border: 1px solid var(--line); transition: .2s;
}
.slider::before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px;
  border-radius: 50%; background: var(--text-dim); transition: .2s;
}
.switch input:checked + .slider { background: var(--good-soft); border-color: var(--good); }
.switch input:checked + .slider::before { transform: translateX(20px); background: var(--good); }

/* ===================== TOASTS ===================== */
.toast-stack {
  position: fixed; right: 16px; bottom: 16px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px; max-width: 380px;
}
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-left: 4px solid var(--brand); border-radius: var(--radius-sm);
  padding: 11px 13px; box-shadow: var(--shadow); animation: toastIn .25s ease;
}
.toast.error   { border-left-color: var(--bad); }
.toast.success { border-left-color: var(--good); }
.toast.info    { border-left-color: var(--info); }
.toast-ico { font-size: 15px; }
.toast-body { font-size: 13px; }
.toast-title { font-weight: 650; margin-bottom: 1px; }
.toast-msg { color: var(--text-dim); font-size: 12.5px; word-break: break-word; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ===================== MODAL ===================== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(4,7,12,.65); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: 100%; max-width: 440px;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal p { margin: 0 0 14px; color: var(--text-dim); }
.modal-extra {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; font-family: var(--mono); font-size: 12px; margin-bottom: 14px;
  color: var(--text-dim); white-space: pre-wrap;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ===================== LOAD BAR ===================== */
.loadbar {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  z-index: 300; opacity: 0; transition: opacity .2s;
  box-shadow: 0 0 8px var(--brand-glow);
}
.loadbar.active { opacity: 1; animation: load 1.4s ease-in-out infinite; }
@keyframes load {
  0% { width: 0; left: 0; }
  50% { width: 70%; left: 10%; }
  100% { width: 0; left: 100%; }
}

/* skeleton dim while loading */
.is-loading { opacity: .6; transition: opacity .2s; }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 1100px) {
  .quick-actions .btn span:not(.ico) { display: none; }
  .quick-actions .btn { padding: 7px 9px; }
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 12px; gap: 10px; }
  .topbar-divider { display: none; }
  .user-meta { display: none; }
  .tabs { top: 0; position: static; }
  .content { padding: 12px; }
  .kpi-value { font-size: 20px; }
}
