:root {
  --navy: #1C2B3A;
  --navy-mid: #24384B;
  --blue: #2E6DB8;
  --blue-dark: #1D4E8C;
  --blue-light: #6FA3DE;
  --blue-pale: #EBF2FA;
  --border: #DCE6F2;
  --surface: #F4F7FB;
  --text: #1C2B3A;
  --text-mid: #4C5F78;
  --text-muted: #8091A8;
  --success-bg: #E6F4EA;
  --success-border: #A8D5B5;
  --success-text: #1E5631;
  --danger: #C0392B;
  --danger-bg: #FBEAE8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28,43,58,0.04), 0 4px 16px rgba(28,43,58,0.06);
  --font-display: 'Nunito Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Roboto Mono', monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-display);
  color: var(--text);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); }
.icon { display: block; flex-shrink: 0; }

/* ── Auth page ───────────────────────────────────────────── */
.auth-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-mid) 45%, #2B4A6B 100%);
  padding: 1.5rem;
}
.auth-box {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  padding: 2.75rem 2.5rem;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.auth-logo { height: 34px; width: auto; margin-bottom: 0.25rem; }
.auth-box h1 { font-size: 1.25rem; margin: 0; color: var(--navy); }
.auth-subtitle { margin: -0.4rem 0 0.5rem; color: var(--text-muted); font-size: 0.85rem; }
.auth-box label { font-size: 0.8rem; font-weight: 700; color: var(--text-mid); text-transform: uppercase; letter-spacing: 0.04em; }
.auth-box input {
  padding: 0.65rem 0.75rem; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 0.95rem; font-family: inherit; transition: border-color 0.15s ease;
}
.auth-box input:focus { outline: none; border-color: var(--blue); }
.auth-box .error {
  background: var(--danger-bg); color: var(--danger);
  padding: 0.6rem 0.8rem; border-radius: 6px; font-size: 0.85rem; margin: 0;
}

/* ── App shell ───────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--navy);
  color: rgba(255,255,255,0.85);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand-logo {
  height: 28px; width: auto; flex-shrink: 0;
  filter: brightness(0) invert(1);
}
.sidebar-brand-tag {
  font-family: var(--font-mono); font-weight: 400; font-size: 0.68rem;
  color: rgba(255,255,255,0.5); text-transform: uppercase; letter-spacing: 0.1em;
  border-left: 1px solid rgba(255,255,255,0.2); padding-left: 0.6rem;
}

.sidebar-nav { flex: 1; padding: 1rem 0.75rem; display: flex; flex-direction: column; gap: 0.15rem; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  color: rgba(255,255,255,0.65);
  text-decoration: none;
  font-size: 0.87rem;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav a.active { background: var(--blue); color: #fff; }
.nav-label-short { display: none; }

.sidebar-footer { padding: 1rem 1.25rem 1.35rem; border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar-user { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.9rem; }
.sidebar-user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--blue-light); color: var(--navy);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 0.8rem; flex-shrink: 0;
}
.sidebar-user-name { font-size: 0.85rem; font-weight: 600; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-logout {
  display: flex; align-items: center; gap: 0.6rem;
  color: rgba(255,255,255,0.55);
  text-decoration: none; font-size: 0.83rem; font-weight: 600;
  transition: color 0.15s ease;
}
.sidebar-logout:hover { color: #fff; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  padding: 1.5rem 2.5rem;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 1.25rem; color: var(--navy); }
.content { padding: 2rem 2.5rem 4rem; max-width: 1080px; width: 100%; }

.flash {
  background: var(--success-bg); border: 1px solid var(--success-border); color: var(--success-text);
  padding: 0.7rem 1rem; border-radius: 8px; font-size: 0.88rem; margin-bottom: 1.5rem;
}
.hint { color: var(--text-muted); font-size: 0.87rem; max-width: 720px; line-height: 1.6; margin-top: 0; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem; margin-bottom: 1.75rem;
}
.card-title { font-size: 1rem; margin: 0 0 1.1rem; color: var(--navy); }

/* ── Dashboard ───────────────────────────────────────────── */
.stat-grid { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-bottom: 1.75rem; }
.stat-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem 1.75rem; text-decoration: none; color: inherit;
  flex: 1; min-width: 240px;
  display: flex; flex-direction: column; gap: 0.3rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(28,43,58,0.06), 0 12px 28px rgba(28,43,58,0.1); }
.stat-card-icon {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--blue-pale); color: var(--blue);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 0.4rem;
}
.stat-card-count { font-size: 2.1rem; font-weight: 800; color: var(--navy); line-height: 1; }
.stat-card-label { color: var(--text-mid); font-size: 0.85rem; font-weight: 600; }
.stat-card-next { color: var(--text-muted); font-size: 0.78rem; margin-top: 0.3rem; }
.quick-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* ── Forms ───────────────────────────────────────────────── */
.form-row { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.form-row label { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.82rem; font-weight: 700; color: var(--text-mid); flex: 1; min-width: 180px; }
.form-row label small { font-weight: 400; color: var(--text-muted); text-transform: none; letter-spacing: 0; }
.form-row input[type=text], .form-row input[type=date], .form-row input[type=time], .form-row input[type=number] {
  padding: 0.6rem 0.7rem; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 0.9rem; font-weight: 400; font-family: inherit; color: var(--text);
  background: #fff;
  transition: border-color 0.15s ease;
}
.form-row input[type=text]:focus, .form-row input[type=date]:focus, .form-row input[type=time]:focus, .form-row input[type=number]:focus {
  outline: none; border-color: var(--blue);
}
.form-row input[type=number] { -moz-appearance: textfield; }
.form-row code { background: var(--blue-pale); padding: 0.1rem 0.35rem; border-radius: 4px; font-family: var(--font-mono); font-size: 0.85em; }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 0.5rem !important; align-self: flex-end; padding-bottom: 0.6rem; }
.checkbox-label input { width: 16px; height: 16px; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 0.5rem; }

.btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  border: 1.5px solid transparent;
  padding: 0.6rem 1.35rem;
  border-radius: 8px;
  font-size: 0.87rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); color: #fff; text-decoration: none; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text-mid); }
.btn-outline:hover { border-color: var(--text-muted); text-decoration: none; }
.btn-block { width: 100%; justify-content: center; margin-top: 0.5rem; }

/* ── Tables ──────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.87rem; min-width: 640px; }
.admin-table th, .admin-table td {
  padding: 0.7rem 0.85rem; border-bottom: 1px solid var(--border); text-align: left;
  white-space: nowrap;
}
.admin-table td:nth-child(3) { white-space: normal; min-width: 180px; } /* title/category column stays readable, not squeezed to one line */
.admin-table th {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); font-weight: 700;
}
.admin-table tbody tr:hover { background: var(--surface); }
.admin-table tbody tr:last-child td { border-bottom: none; }
.empty-row { text-align: center; color: var(--text-muted); padding: 2rem !important; }

.pill {
  display: inline-block; padding: 0.2rem 0.65rem; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
}
.pill-published { background: var(--success-bg); color: var(--success-text); }
.pill-hidden { background: var(--surface); color: var(--text-muted); border: 1px solid var(--border); }

.admin-table-actions { display: flex; gap: 0.4rem; align-items: center; }
.admin-table-actions form { margin: 0; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 7px;
  background: transparent; border: none; color: var(--text-muted);
  cursor: pointer; transition: all 0.15s ease;
}
.icon-btn:hover { background: var(--blue-pale); color: var(--blue); }
.icon-btn-danger:hover { background: var(--danger-bg); color: var(--danger); }

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

/* Tablet / narrow desktop — trim the outer spacing a bit before anything reflows */
@media (max-width: 1000px) {
  .sidebar { width: 200px; }
  .content { padding: 1.5rem 1.75rem 3rem; }
  .topbar { padding: 1.25rem 1.75rem; }
}

/* Phones and small tablets — sidebar becomes a horizontal top bar */
@media (max-width: 760px) {
  body { overflow-x: hidden; }
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 10;
    flex-direction: row; align-items: center; padding: 0.4rem 0.6rem; gap: 0.5rem;
  }
  .sidebar-brand { border: none; padding: 0.4rem 0.5rem; flex-shrink: 0; }
  .sidebar-brand-logo { height: 22px; }
  .sidebar-brand-tag { display: none; }
  .sidebar-nav {
    flex-direction: row; padding: 0; margin: 0; gap: 0.25rem;
    flex: 1; min-width: 0; overflow-x: auto; -webkit-overflow-scrolling: touch;
    /* Soft fade at the trailing edge so a clipped item reads as "more to
       scroll", not a rendering bug, on widths where it still doesn't fit. */
    mask-image: linear-gradient(to right, black calc(100% - 20px), transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black calc(100% - 20px), transparent 100%);
  }
  .sidebar-nav a { padding: 0.5rem 0.65rem; white-space: nowrap; font-size: 0.8rem; }
  .nav-label-full { display: none; }
  .nav-label-short { display: inline; }
  .sidebar-footer {
    border: none; padding: 0.4rem 0.5rem; display: flex; align-items: center;
    gap: 0.5rem; flex-shrink: 0;
  }
  .sidebar-user { margin-bottom: 0; }
  .sidebar-user-name { display: none; }
  .sidebar-logout span { display: none; }

  .topbar { padding: 1rem 1.25rem; }
  .topbar h1 { font-size: 1.1rem; }
  .content { padding: 1.25rem 1.25rem 3rem; }

  /* The table (min-width: 640px) reliably overflows below this breakpoint —
     fade the trailing edge so "scroll for more" reads as intentional. */
  .table-scroll {
    mask-image: linear-gradient(to right, black calc(100% - 24px), transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black calc(100% - 24px), transparent 100%);
  }

  .form-row { flex-direction: column; gap: 0.9rem; }
  .form-row label { min-width: 0; }
  .checkbox-label { align-self: flex-start; padding-bottom: 0; }
  .stat-grid { gap: 1rem; }
  .stat-card { min-width: 0; padding: 1.25rem 1.5rem; }
  .card { padding: 1.1rem; }
  .quick-actions .btn { flex: 1; justify-content: center; }
}

/* Small phones — icon-only nav so all 3 items fit with no scrolling needed */
@media (max-width: 480px) {
  .sidebar-nav a { padding: 0.55rem; }
  .nav-label { display: none; }
  .sidebar-nav { mask-image: none; -webkit-mask-image: none; }
}

/* Small phones — tighten further */
@media (max-width: 420px) {
  .topbar { padding: 0.85rem 1rem; }
  .content { padding: 1rem 1rem 2.5rem; }
  .card { padding: 0.9rem; }
  .card-title { font-size: 0.92rem; }
  .stat-card { padding: 1.1rem 1.25rem; }
  .stat-card-count { font-size: 1.7rem; }
  .btn { padding: 0.55rem 1rem; font-size: 0.83rem; }
  .auth-page { padding: 1rem; }
  .auth-box { padding: 2rem 1.5rem; }
  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .btn { justify-content: center; }
}
