/* =========================================================================
 * CMS Core — Admin UI theme (Payload-inspired, light & minimal)
 * ========================================================================= */
:root {
  --bg: #f6f6f8;
  --panel: #ffffff;
  --line: #e6e6ec;
  --line-strong: #d6d6df;
  --text: #1c1c24;
  --muted: #75757f;
  --muted-2: #9a9aa4;
  --accent: #18181b;            /* monochrome — black, not blue */
  --accent-soft: #f1f1f3;       /* subtle active background */
  --accent-d: #111114;
  --ink: #18181b;               /* near-black primary button (Payload-style) */
  --ink-h: #000000;
  --danger: #e02424;
  --danger-soft: #fde8e8;
  --success: #057a55;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 16, 24, 0.06);
  --shadow: 0 1px 3px rgba(16, 16, 24, 0.06), 0 8px 24px rgba(16, 16, 24, 0.05);
  --sidebar-w: 256px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text); background: var(--bg);
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--text); }
a { color: var(--accent); }
.hidden { display: none !important; }

/* ---------------- Login ---------------- */
#login-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(900px 500px at 50% -20%, #e9e9ff, transparent),
    var(--bg);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 36px 32px;
  box-shadow: var(--shadow);
}
.login-card .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.login-card .brand .logo, .sidebar .brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--ink);
  display: grid; place-items: center; color: #fff; font-weight: 800; flex-shrink: 0;
}
.login-card h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.login-card p.sub { color: var(--muted); margin: 6px 0 22px; font-size: 13px; }
.login-card label { display: block; font-weight: 600; margin: 14px 0 6px; font-size: 13px; }
.login-card input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line-strong);
  border-radius: 9px; outline: none; transition: border-color .12s, box-shadow .12s;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card .hint { font-size: 12px; color: var(--muted-2); margin-top: 18px; text-align: center; }
.demo-creds { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.cred-chip {
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #fafafb; cursor: pointer; transition: border-color .15s, background .15s;
}
.cred-chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.cred-chip b { font-size: 12.5px; color: var(--ink, #1a1a1f); }
.cred-chip span { font-size: 11.5px; color: var(--muted-2); }

/* ---------------- App layout ---------------- */
#app-view { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; flex-shrink: 0; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 16px 18px; height: 61px;
  border-bottom: 1px solid var(--line);
}
.sidebar .brand b { font-size: 15px; letter-spacing: -0.01em; }
.nav { flex: 1; overflow-y: auto; padding: 12px 8px; }

/* solo top-level link (Dashboard) */
.nav a.solo { margin-bottom: 8px; }

/* collapsible groups */
.group { margin-top: 4px; }
.group-toggle {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  background: none; border: none; padding: 9px 12px 7px; margin-top: 6px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted-2); font-weight: 700; border-radius: 7px;
}
.group-toggle:hover { color: var(--muted); }
.group-toggle .chev { display: inline-flex; transition: transform .18s ease; color: var(--muted-2); }
.group.collapsed .chev { transform: rotate(-90deg); }
.group-items { overflow: hidden; }
.group.collapsed .group-items { display: none; }

.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; margin: 1px 2px;
  border-radius: 8px; color: #3c3c47; text-decoration: none; font-weight: 500; font-size: 13.5px;
}
.nav a .ic { width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted-2); flex-shrink: 0; }
.nav a .ic svg { width: 18px; height: 18px; }
.nav a:hover { background: #f3f3f6; color: var(--text); }
.nav a:hover .ic { color: var(--muted); }
.nav a.active { background: var(--accent-soft); color: var(--accent-d); font-weight: 600; }
.nav a.active .ic { color: var(--accent-d); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 61px; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 5;
}
.topbar h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.crumb { color: var(--muted-2); font-weight: 500; font-size: 13px; }
.user-chip { display: flex; align-items: center; gap: 12px; }
.user-chip .who { text-align: right; line-height: 1.2; }
.user-chip .who .name { font-weight: 600; font-size: 13px; }
.user-chip .who .role { font-size: 11.5px; color: var(--muted); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--ink);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.content { padding: 24px; flex: 1; }
.hamburger { display: none; background: none; border: none; font-size: 20px; }

/* ---------------- Toolbar ---------------- */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar .search {
  flex: 1; min-width: 220px; max-width: 380px; padding: 9px 13px;
  border: 1px solid var(--line-strong); border-radius: 9px; background: var(--panel); outline: none;
}
.toolbar .search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.toolbar .spacer { flex: 1; }

/* ---------------- Buttons ---------------- */
.btn {
  border: 1px solid transparent; border-radius: 9px; padding: 9px 15px;
  font-weight: 600; font-size: 13.5px; display: inline-flex; align-items: center; gap: 6px;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-h); }
.btn-light { background: var(--panel); border-color: var(--line-strong); color: var(--text); }
.btn-light:hover { background: #f6f6f8; }
.btn-ghost { background: transparent; color: var(--muted); padding: 6px 9px; }
.btn-ghost:hover { color: var(--text); background: #f1f1f4; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; }
.btn-trash { color: var(--muted); }
.btn-trash:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------------- Cards / dashboard ---------------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; }
.stat-card { padding: 18px 18px 16px; cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .08s; }
.stat-card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-card .ic { color: var(--muted); height: 22px; }
.stat-card .ic svg { width: 22px; height: 22px; }
.stat-card .num { font-size: 30px; font-weight: 800; margin-top: 8px; letter-spacing: -0.02em; }
.stat-card .lbl { color: var(--muted); font-size: 13px; margin-top: 2px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted-2); font-weight: 700; margin: 4px 2px 12px; }

/* ---------------- Table ---------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: 11px 16px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); background: #fafafb; border-bottom: 1px solid var(--line); white-space: nowrap; font-weight: 700;
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafafb; }
.cell-muted { color: var(--muted-2); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.empty { padding: 52px; text-align: center; color: var(--muted); }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent-d); margin: 1px 2px;
}
.badge.gray { background: #f0f0f3; color: var(--muted); }
.badge.warn { background: #fef3c7; color: #92600a; }
.badge.success { background: #dcfce7; color: #166534; }
.badge.danger { background: #fee2e2; color: #991b1b; }

/* ---------------- Pagination ---------------- */
.pager { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--line); }
.pager .info { color: var(--muted); font-size: 13px; }
.pager .controls { display: flex; gap: 6px; align-items: center; }

/* ---------------- Modal ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,20,30,.45); backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; z-index: 50; overflow-y: auto;
}
.modal { background: var(--panel); width: 100%; max-width: 580px; border-radius: 14px; box-shadow: 0 24px 64px rgba(0,0,0,.28); animation: pop .15s ease; }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal header { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal header h3 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }
.modal .body { padding: 22px; }
.modal footer { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.field { display: flex; flex-direction: column; }
.field.full { grid-column: 1 / -1; }
.field label { font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.field label .req { color: var(--danger); }
.field input, .field select, .field textarea {
  padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 8px; outline: none; background: var(--panel);
  transition: border-color .12s, box-shadow .12s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field textarea { resize: vertical; min-height: 66px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; max-height: 220px; overflow-y: auto; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: #fafafb; }
.chk { display: flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--line-strong); border-radius: 7px; cursor: pointer; font-size: 12.5px; background: var(--panel); }
.chk input { width: auto; }
.chk:hover { border-color: var(--accent); }

/* ---------------- Toast / misc ---------------- */
.error-text { color: #9b1c1c; background: var(--danger-soft); padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-top: 12px; white-space: pre-line; }
#toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.22); font-size: 13.5px; min-width: 220px; animation: pop .15s ease; }
.toast.ok { background: var(--success); }
.toast.err { background: #b91c1c; }
.loading { padding: 52px; text-align: center; color: var(--muted); }
.spin { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: rot .7s linear infinite; vertical-align: middle; }
@keyframes rot { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
  .sidebar { position: fixed; left: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .hamburger { display: inline-block; }
  .form-grid { grid-template-columns: 1fr; }
}
