/* White-label portal styles. Self-contained, no external fonts or CDNs. */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8f0;
  --border-strong: #cbd5e1;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-soft: #eff4ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }

button {
  font-family: inherit;
  cursor: pointer;
}

.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  background: var(--brand);
  color: #fff;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.btn:hover { background: var(--brand-hover); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border-strong);
}
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
label.field {
  display: block;
  margin-bottom: 16px;
}
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
}
input, textarea, select {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
textarea { resize: vertical; min-height: 84px; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}
.login-brand {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
}
.login-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}
.login-footer {
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
  margin-top: 20px;
}

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  padding: 4px 8px 20px;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  flex-shrink: 0;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-foot { margin-top: auto; padding-top: 16px; }
.powered-by {
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
  padding: 12px 8px 4px;
}

/* ---------- Main ---------- */
.main {
  padding: 28px 32px 48px;
  max-width: 920px;
  width: 100%;
}
.page-head {
  margin-bottom: 24px;
}
.page-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.page-desc { color: var(--text-muted); font-size: 14px; margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px;
  margin-bottom: 18px;
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 16px;
}

/* ---------- Stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stat-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}
.stat-value { font-size: 28px; font-weight: 700; margin-top: 6px; }

/* Bar chart (CSS bars) */
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 56px; align-items: center; gap: 12px; }
.bar-name { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: var(--surface-2); border-radius: 6px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--brand); height: 100%; border-radius: 6px; transition: width 0.4s ease; }
.bar-val { font-size: 13px; font-weight: 600; text-align: right; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  background: var(--surface);
}
.list-item-body { min-width: 0; }
.list-item-title { font-weight: 600; font-size: 14px; }
.list-item-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; word-break: break-word; }
.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--brand);
  background: var(--brand-soft);
  border-radius: 5px;
  padding: 2px 7px;
  margin-bottom: 6px;
}

/* ---------- Snippet ---------- */
.snippet {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-x: auto;
}

/* ---------- States ---------- */
.state {
  text-align: center;
  color: var(--text-muted);
  padding: 36px 20px;
  font-size: 14px;
}
.state-error {
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  margin-bottom: 16px;
}
.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  margin: 0 auto 10px;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Inline form feedback */
.form-msg { font-size: 13px; margin-top: 12px; }
.form-msg.ok { color: var(--success); }
.form-msg.err { color: var(--danger); }

.row-actions { display: flex; gap: 8px; flex-shrink: 0; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
}
.status-pill.on { background: var(--success-soft); color: var(--success); }
.status-pill.off { background: var(--surface-2); color: var(--text-muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #0f172a;
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 50;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

.topbar {
  display: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 14px;
    gap: 6px;
  }
  .sidebar-brand { padding: 4px 8px; width: auto; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 4px; flex: 1; }
  .nav-item { padding: 8px 10px; }
  .nav-item span { display: none; }
  .sidebar-foot { margin: 0; padding: 0; }
  .powered-by { display: none; }
  .main { padding: 20px 16px 40px; }
  .field-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 96px 1fr 44px; }
}

/* ---------- Dark mode (optional, respects OS) ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #151c2c;
    --surface-2: #1c2536;
    --border: #26314a;
    --border-strong: #364157;
    --text: #e6eaf2;
    --text-muted: #9aa6bd;
    --text-faint: #6b7793;
    --brand-soft: #1c2942;
    --danger-soft: #2a1518;
    --success-soft: #14251a;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  }
  .snippet { background: #060a14; }
}
