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

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
}

body { background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, sans-serif; font-size: 15px; line-height: 1.5; min-height: 100vh; }

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

button { cursor: pointer; font: inherit; border: none; border-radius: var(--radius); transition: background .15s, opacity .15s; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  padding: 10px 14px;
  width: 100%;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

/* ── Login ── */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.login-logo svg { flex-shrink: 0; }

.login-logo-text h1 { font-size: 22px; font-weight: 700; line-height: 1.1; }
.login-logo-text span { font-size: 13px; color: var(--text-muted); }

.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 12px 24px;
  width: 100%;
  font-size: 15px;
  font-weight: 600;
  margin-top: 8px;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.alert {
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 14px;
  margin-bottom: 18px;
  display: none;
}
.alert.show { display: block; }
.alert-error { background: rgba(220,38,38,.08); border: 1px solid rgba(220,38,38,.25); color: #b91c1c; }
.alert-success { background: rgba(22,163,74,.08); border: 1px solid rgba(22,163,74,.25); color: #15803d; }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 10;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 17px;
  font-weight: 700;
}

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .1s, color .1s;
  border-radius: 0;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(37,99,235,.1); color: var(--accent); }
.nav-item svg { flex-shrink: 0; opacity: .7; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.user-avatar {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: #fff; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; }
.user-email { font-size: 12px; color: var(--text-muted); }

.btn-logout {
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 10px;
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius);
}
.btn-logout:hover { background: var(--surface2); color: var(--danger); }

.main { flex: 1; margin-left: 240px; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h2 { font-size: 20px; font-weight: 700; }
.topbar-actions { display: flex; gap: 10px; }

.content { padding: 28px 32px; flex: 1; }

/* ── Cards ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 28px; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }

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

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state svg { margin-bottom: 12px; opacity: .3; }
.empty-state p { font-size: 14px; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-published { background: rgba(22,163,74,.12); color: #15803d; }
.badge-scheduled { background: rgba(37,99,235,.1); color: #1d4ed8; }
.badge-draft { background: rgba(100,116,139,.1); color: #475569; }
.badge-failed { background: rgba(220,38,38,.1); color: #b91c1c; }
.badge-active { background: rgba(22,163,74,.12); color: #15803d; }
.badge-inactive { background: rgba(100,116,139,.1); color: #475569; }

/* ── Buttons ── */
.btn { padding: 8px 16px; border-radius: var(--radius); font-size: 14px; font-weight: 500; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(220,38,38,.3); }
.btn-danger:hover { background: rgba(220,38,38,.07); }

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(37,99,235,.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-primary .spinner, .btn-accent .spinner { border-color: rgba(255,255,255,.35); border-top-color: #fff; }

/* ── Loading overlay ── */
.loading { display: flex; align-items: center; justify-content: center; padding: 60px; }
.loading .spinner { width: 32px; height: 32px; border-color: rgba(37,99,235,.2); border-top-color: var(--accent); }

/* ── Tabs (pages) ── */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Page item ── */
.page-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.page-item:last-child { border-bottom: none; }
.page-avatar {
  width: 44px; height: 44px;
  background: var(--surface2);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 20px;
}
.page-info { flex: 1; }
.page-name { font-weight: 600; font-size: 15px; }
.page-meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 14px;
  box-shadow: var(--shadow);
  transform: translateY(80px);
  opacity: 0;
  transition: transform .25s, opacity .25s;
  z-index: 100;
  max-width: 320px;
}
#toast.show { transform: translateY(0); opacity: 1; }
#toast.toast-success { border-color: rgba(22,163,74,.4); color: #15803d; background: #f0fdf4; }
#toast.toast-error { border-color: rgba(220,38,38,.4); color: #b91c1c; background: #fef2f2; }

/* ── Period selector ── */
.period-selector {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.period-btn {
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.period-btn:hover { background: var(--surface2); color: var(--text); }
.period-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Token forms ── */
.token-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.token-input-row input { flex: 1; min-width: 0; }
.token-input-row .btn { flex-shrink: 0; white-space: nowrap; }

.token-hint { font-size: 12px; color: var(--text-muted); margin-top: 10px; }

.token-meta { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; line-height: 1.8; }

.page-token-row { padding: 16px 20px; }

.page-token-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.token-inline-result {
  display: block;
  font-size: 13px;
  margin-top: 6px;
  min-height: 18px;
}
.token-inline-result.ok { color: var(--success); }
.token-inline-result.error { color: var(--danger); }

/* ── Hamburger ── */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px; height: 36px;
  background: none;
  border-radius: var(--radius);
  padding: 6px;
  flex-shrink: 0;
}
.hamburger:hover { background: var(--surface2); }
.hamburger span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform .2s, opacity .2s;
}
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.topbar-left { display: flex; align-items: center; gap: 12px; }

/* ── Sidebar overlay ── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.4);
  z-index: 9;
  backdrop-filter: blur(2px);
}
#sidebar-overlay.show { display: block; }

/* ── RWD ── */
@media (max-width: 768px) {
  .hamburger { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 10;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.12);
  }

  .main { margin-left: 0; }

  .topbar { padding: 14px 16px; }
  .topbar h2 { font-size: 17px; }

  .content { padding: 16px; }

  .login-card { padding: 32px 24px; }

  #toast { bottom: 16px; right: 16px; left: 16px; max-width: none; }
}

@media (max-width: 480px) {
  .card-header { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
  .card-body { padding: 12px 14px; }
  th, td { padding: 10px 10px; }
  .content { padding: 12px; }
  .topbar { padding: 12px 14px; }
  .stat-value { font-size: 22px; }
}
