/* ─── Theme variables ─────────────────────────────────────────────────────── */

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --accent: #4f8ef7;
  --accent-dim: #1e3a6e;
  --green: #2eb872;
  --yellow: #f5a623;
  --red: #e05252;
  --text: #e2e4f0;
  --muted: #6b7280;
  --ghost-bg: rgba(255,255,255,.07);
  --hover-bg: rgba(255,255,255,.04);
  --stripe-bg: rgba(255,255,255,.02);
  --shadow: 0 8px 32px rgba(0,0,0,.4);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius: 8px;
}

/* System preference — light */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --border: #e1e5ef;
    --accent: #2563eb;
    --accent-dim: #dbeafe;
    --green: #16a34a;
    --yellow: #d97706;
    --red: #dc2626;
    --text: #111827;
    --muted: #6b7280;
    --ghost-bg: rgba(0,0,0,.06);
    --hover-bg: rgba(0,0,0,.04);
    --stripe-bg: rgba(0,0,0,.02);
    --shadow: 0 8px 32px rgba(0,0,0,.12);
  }
}

/* Explicit light theme */
[data-theme="light"] {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #e1e5ef;
  --accent: #2563eb;
  --accent-dim: #dbeafe;
  --green: #16a34a;
  --yellow: #d97706;
  --red: #dc2626;
  --text: #111827;
  --muted: #6b7280;
  --ghost-bg: rgba(0,0,0,.06);
  --hover-bg: rgba(0,0,0,.04);
  --stripe-bg: rgba(0,0,0,.02);
  --shadow: 0 8px 32px rgba(0,0,0,.12);
}

/* Explicit dark theme */
[data-theme="dark"] {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --accent: #4f8ef7;
  --accent-dim: #1e3a6e;
  --green: #2eb872;
  --yellow: #f5a623;
  --red: #e05252;
  --text: #e2e4f0;
  --muted: #6b7280;
  --ghost-bg: rgba(255,255,255,.07);
  --hover-bg: rgba(255,255,255,.04);
  --stripe-bg: rgba(255,255,255,.02);
  --shadow: 0 8px 32px rgba(0,0,0,.4);
}

/* ─── Reset ───────────────────────────────────────────────────────────────── */

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  transition: background .2s, color .2s;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout ──────────────────────────────────────────────────────────────── */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 0 80px; /* bottom room for theme toggle */
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 90;
  transition: background .2s, border-color .2s, transform .25s ease;
}

.sidebar-logo {
  padding: 0 20px 24px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.3px;
  color: var(--text);
}
.sidebar-logo span { color: var(--accent); }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  transition: color .15s, background .15s;
}
.sidebar nav a:hover, .sidebar nav a.active {
  color: var(--text);
  background: rgba(79,142,247,.08);
  text-decoration: none;
}
.sidebar nav a.active { color: var(--accent); }
.sidebar nav .icon { font-size: 15px; width: 20px; text-align: center; }

.main { margin-left: 200px; padding: 32px; flex: 1; max-width: 1200px; }

/* ─── Page header ─────────────────────────────────────────────────────────── */

.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.4px; }
.page-header p { color: var(--muted); margin-top: 4px; font-size: 13px; }

/* ─── Cards ───────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  transition: background .2s, border-color .2s;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h2 { font-size: 14px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }

/* ─── Stat grid ───────────────────────────────────────────────────────────── */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: background .2s, border-color .2s;
}
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; letter-spacing: -1px; }

/* ─── Badges ──────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.badge-pending  { background: rgba(245,166,35,.15); color: var(--yellow); }
.badge-queued   { background: rgba(79,142,247,.15); color: var(--accent); }
.badge-draft    { background: rgba(107,114,128,.15); color: var(--muted); }
.badge-published { background: rgba(46,184,114,.15); color: var(--green); }
.badge-approved  { background: rgba(46,184,114,.15); color: var(--green); }
.badge-rejected  { background: rgba(224,82,82,.15); color: var(--red); }
.badge-planned   { background: rgba(107,114,128,.15); color: var(--muted); }
.badge-ok        { background: rgba(46,184,114,.15); color: var(--green); }
.badge-error     { background: rgba(224,82,82,.15); color: var(--red); }

/* ─── Approval items ──────────────────────────────────────────────────────── */

.approval-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.approval-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--stripe-bg);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.approval-header:hover { background: var(--hover-bg); }
.approval-title { flex: 1; font-weight: 500; font-size: 13px; }
.approval-meta  { color: var(--muted); font-size: 12px; }
.approval-body  { padding: 16px; display: none; }
.approval-body.open { display: block; }
.approval-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: 14px;
  color: var(--muted);
}
.approval-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-danger   { background: var(--red); color: #fff; }
.btn-ghost    { background: var(--ghost-bg); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ─── Calendar ────────────────────────────────────────────────────────────── */

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-width: 480px;
}
.cal-day-header {
  background: var(--surface);
  padding: 8px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.cal-day {
  background: var(--surface);
  min-height: 90px;
  padding: 8px;
  vertical-align: top;
}
.cal-day.other-month { opacity: .45; }
.cal-day.today { background: rgba(79,142,247,.06); }
.cal-day-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
}
.cal-day.today .cal-day-num { color: var(--accent); }
.cal-event {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 3px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: default;
}
.cal-event.queued    { background: var(--accent-dim); color: var(--accent); }
.cal-event.draft     { background: rgba(107,114,128,.2); color: var(--muted); }
.cal-event.published { background: rgba(46,184,114,.15); color: var(--green); }
.cal-event.planned   { background: rgba(107,114,128,.1); color: var(--muted); }

/* ─── Table ───────────────────────────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 10px 12px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border); }
td { padding: 12px; font-size: 13px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--stripe-bg); }

/* ─── Service dots ────────────────────────────────────────────────────────── */

.service-list { display: flex; flex-direction: column; gap: 10px; }
.service-row { display: flex; align-items: center; justify-content: space-between; }
.service-dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-ok    { background: var(--green); }
.dot-error { background: var(--red); }

/* ─── Month nav ───────────────────────────────────────────────────────────── */

.month-nav { display: flex; align-items: center; gap: 12px; }
.month-nav h2 { font-size: 16px; font-weight: 600; min-width: 120px; text-align: center; }

/* ─── Auth overlay ────────────────────────────────────────────────────────── */

.auth-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 340px;
  text-align: center;
}
.auth-box h2 { margin-bottom: 8px; font-size: 18px; }
.auth-box p  { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.auth-box input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  margin-bottom: 12px;
}
.auth-box input:focus { outline: 1px solid var(--accent); }

/* ─── Inputs / Textareas ──────────────────────────────────────────────────── */

textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  resize: vertical;
  min-height: 80px;
  margin-top: 10px;
}
textarea:focus { outline: 1px solid var(--accent); }

/* ─── Toast ───────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 200;
  animation: slideIn .2s ease;
}
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error   { border-color: var(--red); color: var(--red); }
@keyframes slideIn { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ─── Loading / empty ─────────────────────────────────────────────────────── */

.loading { color: var(--muted); padding: 32px; text-align: center; font-size: 13px; }
.empty   { color: var(--muted); padding: 24px; text-align: center; font-size: 13px; }

/* ─── Theme toggle (injected by app.js) ───────────────────────────────────── */

.theme-toggle {
  position: absolute;
  bottom: 16px; left: 12px; right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: color .15s, border-color .15s, background .2s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--accent); }
.theme-toggle .t-icon { font-size: 14px; line-height: 1; }

/* ─── Hamburger (mobile, injected by app.js) ──────────────────────────────── */

.hamburger {
  display: none;
  position: fixed;
  top: 14px; left: 14px;
  z-index: 95;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  cursor: pointer;
  color: var(--text);
  font-family: var(--font);
  transition: background .2s, border-color .2s;
}
.hamburger:hover { border-color: var(--accent); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 89;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

/* ─── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 720px) {
  .hamburger { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0,0,0,.3);
  }

  .main {
    margin-left: 0;
    padding: 16px;
    padding-top: 62px;
  }

  .page-header { margin-bottom: 20px; }
  .page-header h1 { font-size: 18px; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-value { font-size: 22px; }

  /* Calendar: horizontal scroll */
  #cal-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Tables: horizontal scroll */
  .card { overflow-x: auto; }
  table { min-width: 480px; }

  /* Month nav wraps */
  .page-header > div { flex-wrap: wrap; }
  .month-nav { margin-left: 0 !important; }

  /* Auth box */
  .auth-box { width: calc(100% - 32px); padding: 28px 20px; }

  /* Campaign cards */
  .card > div[style*="display:flex"] { flex-direction: column; gap: 12px; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .approval-actions { flex-direction: column; }
  .approval-actions .btn { width: 100%; justify-content: center; }
}
