/* KMA Education Board — admin panel styles. Dark sidebar dashboard. */
:root {
  --blue-900: #141f4d;
  --blue-800: #1e3a8a;
  --orange: #e8632a;
  --orange-dark: #c94f1e;
  --bg: #eef1f7;
  --card: #ffffff;
  --ink: #232838;
  --muted: #6b7280;
  --border: #e2e6ef;
  --danger: #c0392b;
  --radius: 10px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.5;
}

/* ---------- login page ---------- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--blue-900), var(--blue-800)); padding: 20px; }
.login-card { background: #fff; border-radius: 14px; padding: 36px; width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand .logo-mark { width: 60px; height: 60px; border-radius: 50%; margin: 0 auto 12px;
  background: radial-gradient(circle at 35% 30%, #ffd9a8, var(--orange) 55%, #8a3a12);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #fff; font-size: 1.3rem; }
.login-brand h1 { font-size: 1.25rem; color: var(--blue-900); }
.login-brand p { color: var(--muted); font-size: .9rem; }
.login-card label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 12px; color: var(--blue-900); }
.login-card input { width: 100%; margin-top: 6px; padding: 11px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 1rem; }
.login-card input:focus { outline: 2px solid var(--blue-800); border-color: var(--blue-800); }
.form-error { background: #fdecea; color: var(--danger); border: 1px solid #f5c6c0;
  padding: 10px 12px; border-radius: 8px; font-size: .85rem; margin-bottom: 12px; }
.login-hint { margin-top: 16px; font-size: .8rem; color: var(--muted); text-align: center; }
.back-link { text-align: center; margin-top: 8px; font-size: .85rem; }

/* ---------- dashboard layout ---------- */
.admin-shell { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex: 0 0 240px; background: var(--blue-900); color: #dfe5fa;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .side-brand { padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.12); }
.sidebar .side-brand h2 { font-size: 1.05rem; color: #fff; }
.sidebar .side-brand small { color: #9aa6d4; }
.side-nav { flex: 1; padding: 12px; overflow-y: auto; }
.side-nav button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 11px 12px;
  background: none; border: 0; color: #dfe5fa; font-size: .92rem; border-radius: 8px; cursor: pointer; text-align: left; }
.side-nav button:hover { background: rgba(255,255,255,.08); }
.side-nav button.active { background: var(--orange); color: #fff; font-weight: 700; }
.side-user { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.12); font-size: .82rem; color: #9aa6d4; }
.side-user strong { color: #fff; display: block; font-size: .9rem; }
.role-badge { display: inline-block; margin-top: 4px; padding: 2px 10px; border-radius: 999px;
  background: rgba(255,255,255,.15); font-size: .72rem; text-transform: uppercase; }

.main { flex: 1; padding: 26px; max-width: 1100px; }
.main h1 { font-size: 1.5rem; color: var(--blue-900); margin-bottom: 4px; }
.main .subtitle { color: var(--muted); font-size: .9rem; margin-bottom: 20px; }

/* stat cards */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: 0 3px 10px rgba(20,35,90,.07); border-left: 4px solid var(--blue-800); }
.stat.orange { border-left-color: var(--orange); }
.stat .num { font-size: 1.8rem; font-weight: 800; color: var(--blue-900); }
.stat .lbl { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }

/* toolbar + table */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.btn-primary { background: var(--orange); color: #fff; border: 0; padding: 10px 20px; border-radius: 8px;
  font-weight: 700; cursor: pointer; font-size: .9rem; }
.btn-primary:hover { background: var(--orange-dark); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-sm { padding: 6px 12px; font-size: .8rem; border-radius: 6px; border: 1px solid var(--border);
  background: #fff; cursor: pointer; margin-right: 6px; }
.btn-sm:hover { border-color: var(--blue-800); color: var(--blue-800); }
.btn-sm.danger { color: var(--danger); border-color: #f0c4c0; }
.btn-sm.danger:hover { background: #fdecea; }
.table-card { background: var(--card); border-radius: var(--radius); overflow-x: auto;
  box-shadow: 0 3px 10px rgba(20,35,90,.07); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #f7f9fd; color: var(--blue-900); font-size: .78rem; text-transform: uppercase; letter-spacing: .5px; }
tr:last-child td { border-bottom: 0; }
td .muted { color: var(--muted); font-size: .8rem; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.pill.on { background: #e6f7ee; color: #157347; }
.pill.off { background: #f1f2f6; color: var(--muted); }
.pill.admin { background: #e3e9fb; color: var(--blue-800); }
.pill.editor { background: #fff3e6; color: var(--orange-dark); }
.pill.viewer { background: #f1f2f6; color: var(--muted); }
.thumb-mini { width: 56px; height: 40px; object-fit: cover; border-radius: 6px; background: var(--blue-100); }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,16,35,.55); display: none;
  align-items: flex-start; justify-content: center; z-index: 100; padding: 40px 16px; overflow-y: auto; }
.modal-backdrop.open { display: flex; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 640px; padding: 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h2 { color: var(--blue-900); margin-bottom: 16px; font-size: 1.2rem; }
.modal label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 12px; color: var(--blue-900); }
.modal input[type=text], .modal input[type=password], .modal input[type=date],
.modal input[type=number], .modal select, .modal textarea {
  width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: .92rem; font-family: inherit; }
.modal textarea { min-height: 140px; resize: vertical; }
.modal .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check-row { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check-row input { width: auto; margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.btn-secondary { background: #eef1f7; border: 0; padding: 10px 20px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--blue-900); color: #fff;
  padding: 12px 20px; border-radius: 10px; font-size: .9rem; display: none; z-index: 200;
  box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.toast.show { display: block; }
.toast.error { background: var(--danger); }

/* media library */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.media-card { background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 4px 14px rgba(20,35,90,.08); }
.media-thumb { aspect-ratio: 4/3; overflow: hidden; background: #eef1f7; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-info { padding: 10px 12px 14px; }
.media-name { font-size: .78rem; font-weight: 600; word-break: break-all; margin-bottom: 2px; }

@media (max-width: 760px) {
  .admin-shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .side-nav { display: flex; flex-wrap: wrap; }
  .side-nav button { width: auto; }
  .main { padding: 18px 14px; }
  .modal .row { grid-template-columns: 1fr; }
}

/* columns nested editor */
.cols-editor { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: #fbfcff; }
.col-pane { border: 1px dashed var(--border); border-radius: 8px; padding: 10px; margin-bottom: 10px; background: #fff; }
.col-pane h4 { margin: 0 0 8px; font-size: .85rem; color: var(--blue-900); }
.col-blk { display: flex; align-items: center; gap: 8px; padding: 7px 9px; background: #f4f6fb; border-radius: 7px; margin-bottom: 6px; flex-wrap: wrap; }
.col-blk-label { font-weight: 700; font-size: .8rem; white-space: nowrap; }
.col-blk-summary { flex: 1; min-width: 120px; font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-blk-actions { display: flex; gap: 4px; }
.col-blk-actions .btn-sm { padding: 3px 8px; font-size: .75rem; }
.col-blk-editor { flex-basis: 100%; margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.col-blk-editor .bf { margin-bottom: 10px; }
.col-addrow { display: flex; gap: 6px; margin-top: 4px; }
.col-addrow select { flex: 1; padding: 7px 10px; border: 1px solid var(--border); border-radius: 7px; }

/* ---- Media Library picker ---- */
.media-pick-btn { margin-left: 8px; }
.media-pick-preview { max-height: 60px; border-radius: 8px; margin-left: 8px; vertical-align: middle; border: 1px solid var(--border); }
.kma-modal { display: none; position: fixed; inset: 0; background: rgba(15,25,60,.55); z-index: 200; align-items: center; justify-content: center; padding: 20px; }
.kma-modal.open { display: flex; }
.kma-modal-box { background: #fff; border-radius: 14px; width: 860px; max-width: 100%; max-height: 84vh; display: flex; flex-direction: column; overflow: hidden; }
.kma-modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.kma-modal-head strong { flex: 1; }
.kma-modal-head input[type="search"] { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; width: 220px; }
.kma-modal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; padding: 16px; overflow-y: auto; }
.kma-media-item { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; cursor: pointer; background: #f7f9fd; }
.kma-media-item:hover { border-color: var(--orange); box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.kma-media-item img { width: 100%; height: 90px; object-fit: cover; display: block; }
.kma-media-item span { display: block; font-size: .7rem; padding: 6px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
