/* PPSC Prep Admin Dashboard — app-branded green theme
   Palette (matches the Flutter app): primary #0E7A4C, dark green #0B3D2E,
   pale green #E7F6EC, background #F4F7F4, white cards. */
:root {
  --primary: #0E7A4C;
  --primary-dark: #0B3D2E;
  --primary-mid: #0A5C39;
  --primary-light: #E7F6EC;
  --bg: #F4F7F4;
  --card: #FFFFFF;
  --text: #1A2B22;
  --muted: #6B7D72;
  --border: #DCE7E0;
  --danger: #D64545;
  --warning: #E8930C;
  --sidebar-bg: #0B3D2E;
  --radius: 14px;
  --shadow-sm: 0 1px 3px rgba(11, 61, 46, .06), 0 4px 14px rgba(11, 61, 46, .05);
  --shadow-md: 0 4px 10px rgba(11, 61, 46, .08), 0 12px 28px rgba(11, 61, 46, .10);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error-text { color: var(--danger); font-size: 13px; margin-top: 8px; }
.success-text { color: var(--primary); font-size: 13px; font-weight: 600; margin-top: 8px; }
.page-intro { margin: -10px 0 18px; font-size: 13px; max-width: 720px; }
.page-intro code, .panel code { background: var(--primary-light); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, var(--sidebar-bg) 0%, var(--primary-mid) 55%, var(--primary) 130%);
  padding: 20px;
}
.login-card {
  background: var(--card); border-radius: 20px; padding: 42px 40px;
  max-width: 390px; width: 100%; text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.28);
  border: 1px solid rgba(255,255,255,.6);
}
.login-logo { font-size: 48px; margin-bottom: 10px; }
.login-card h1 { font-size: 24px; margin-bottom: 4px; letter-spacing: -.02em; color: var(--primary-dark); }
.login-sub { color: var(--muted); margin-bottom: 24px; }
.login-input {
  display: block; width: 100%; box-sizing: border-box;
  padding: 12px 14px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); font-size: 16px;
  transition: border-color .15s, box-shadow .15s;
}
.login-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,122,76,.16); background: #fff; }
#admin-login-btn { width: 100%; padding: 12px; margin-top: 4px; }

/* ---------- Buttons & inputs ---------- */
.btn {
  border: none; border-radius: 10px; padding: 10px 18px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s, box-shadow .15s, transform .1s;
  white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: scale(.98); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(14,122,76,.25); }
.btn-primary:hover:not(:disabled) { background: var(--primary-mid); box-shadow: 0 6px 16px rgba(14,122,76,.30); }
.btn-ghost { background: #fff; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--primary-dark); border-color: var(--primary); background: var(--primary-light); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-outline { color: var(--danger); }
.btn-danger-outline:hover { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }

.input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 14px; font-family: inherit;
  background: #fff; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,122,76,.16); }
.input:disabled, .input[readonly] { background: var(--bg); color: var(--muted); }
textarea.input { resize: vertical; }
.file-input { padding: 8px 12px; background: var(--bg); cursor: pointer; }
.file-input::file-selector-button {
  border: 1px solid var(--border); background: #fff; color: var(--primary-dark);
  border-radius: 8px; padding: 6px 12px; margin-right: 10px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.file-input::file-selector-button:hover { background: var(--primary-light); border-color: var(--primary); }
label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 13px; color: var(--primary-dark); }
label .input { margin-top: 6px; font-weight: 400; }
.form-actions { display: flex; justify-content: flex-end; margin-top: 6px; }

/* ---------- Upload progress ---------- */
.progress-wrap { display: flex; align-items: center; gap: 12px; margin: 4px 0 12px; }
.progress-track { flex: 1; background: var(--border); border-radius: 999px; height: 10px; overflow: hidden; }
.progress-fill { background: linear-gradient(90deg, var(--primary-mid), var(--primary)); height: 100%; border-radius: 999px; transition: width .25s ease; }
.progress-text { font-size: 13px; font-weight: 700; min-width: 42px; text-align: right; color: var(--primary-dark); }

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

.sidebar {
  width: 236px; color: #DCEFE4;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, #093325 100%);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  flex-shrink: 0; box-shadow: 2px 0 18px rgba(11,61,46,.12);
}
.sidebar-brand {
  padding: 22px 18px; font-size: 18px; font-weight: 800; letter-spacing: -.01em;
  border-bottom: 1px solid rgba(255,255,255,.10);
  display: flex; align-items: center; gap: 10px; color: #fff;
}
.sidebar-brand small { font-weight: 500; opacity: .65; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; display: block; }
.brand-icon { font-size: 26px; background: rgba(255,255,255,.10); border-radius: 10px; padding: 6px 8px; line-height: 1; }
.sidebar-nav { flex: 1; padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav-item {
  background: transparent; border: none; color: #BFD9CB; text-align: left;
  padding: 11px 14px; border-radius: 10px; font-size: 14px; font-weight: 500;
  cursor: pointer; display: flex; align-items: center; gap: 10px;
  transition: background .15s, color .15s; width: 100%;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.22); font-weight: 700; }
.nav-item:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.nav-label { white-space: nowrap; }
.badge {
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 1px 8px; margin-left: auto;
}
.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,.10); }
.sidebar-footer .btn-ghost { background: transparent; color: #BFD9CB; border-color: rgba(255,255,255,.22); width: 100%; }
.sidebar-footer .btn-ghost:hover { color: #fff; border-color: rgba(255,255,255,.5); background: rgba(255,255,255,.08); }
.admin-email { font-size: 12px; color: #9DC4AE; margin-bottom: 10px; word-break: break-all; }

.main { flex: 1; padding: 32px; max-width: 1220px; min-width: 0; margin: 0 auto; width: 100%; }
.page-title { font-size: 26px; margin-bottom: 20px; letter-spacing: -.02em; color: var(--primary-dark); font-weight: 800; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 12px; }
.page-header .page-title { margin-bottom: 0; }
.page.hidden { display: none; }

/* ---------- Back buttons & detail headers ---------- */
.back-btn { margin-bottom: 14px; align-self: flex-start; }
.detail-sub { margin-top: -14px; margin-bottom: 20px; font-size: 13px; }
.context-note { margin-bottom: 16px; font-size: 13px; }
.empty-state {
  text-align: center; padding: 40px 20px; color: var(--muted);
  background: var(--card); border-radius: var(--radius); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm); line-height: 1.8;
  grid-column: 1 / -1;
}

/* ---------- Stat cards ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 22px 20px;
  box-shadow: var(--shadow-sm); border: 1px solid var(--border);
  border-top: 4px solid var(--primary);
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-num { font-size: 34px; font-weight: 800; color: var(--primary-dark); letter-spacing: -.02em; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 4px; font-weight: 600; }

/* ---------- Panels & tables ---------- */
.panel {
  background: var(--card); border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow-sm); border: 1px solid var(--border); margin-bottom: 20px;
}
.panel h3 { margin-bottom: 16px; font-size: 16px; color: var(--primary-dark); letter-spacing: -.01em; }
.table-wrap { overflow-x: auto; padding: 0; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table thead th { background: var(--primary-light); color: var(--primary-dark); font-weight: 700; white-space: nowrap; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table tbody tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #F8FBF9; }
.table .actions { white-space: nowrap; }
.table .actions .btn { margin-right: 6px; }

/* ---------- Filters ---------- */
.filters { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.filters .input { width: auto; flex: 1; min-width: 160px; background: #fff; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 8px; }

/* ---------- Subject bars (overview) ---------- */
.subject-bars { display: flex; flex-direction: column; gap: 10px; }
.subject-bar-row { display: flex; align-items: center; gap: 12px; }
.subject-bar-name { width: 180px; flex-shrink: 0; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subject-bar-track { flex: 1; background: var(--border); border-radius: 999px; height: 16px; overflow: hidden; min-width: 60px; }
.subject-bar-fill { background: linear-gradient(90deg, var(--primary-mid), var(--primary)); height: 100%; border-radius: 999px; transition: width .4s; }
.subject-bar-count { width: 60px; flex-shrink: 0; text-align: right; color: var(--muted); font-size: 13px; font-weight: 600; }

/* ---------- Subjects grid ---------- */
.subjects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.subject-card {
  background: var(--card); border-radius: var(--radius); padding: 22px 20px;
  box-shadow: var(--shadow-sm); border: 1px solid var(--border); text-align: center; cursor: pointer;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.subject-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--primary); }
.subject-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.subject-card .icon { font-size: 36px; margin-bottom: 8px; }
.subject-card h4 { margin-bottom: 4px; color: var(--primary-dark); }
.subject-card .count { color: var(--muted); font-size: 13px; }
.card-hint { margin-top: 10px; font-size: 12px; color: var(--primary); font-weight: 700; opacity: 0; transition: opacity .15s; }
.subject-card:hover .card-hint, .subject-card:focus-visible .card-hint { opacity: 1; }

/* ---------- Topic cards ---------- */
.topics-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.topic-card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow-sm); border: 1px solid var(--border); cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.topic-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--primary); }
.topic-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.topic-card-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topic-icon { font-size: 30px; flex-shrink: 0; }
.topic-card-text { min-width: 0; }
.topic-card h4 { margin-bottom: 2px; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--primary-dark); }
.topic-card .count { color: var(--muted); font-size: 12px; }
.card-arrow { color: var(--primary); font-weight: 800; font-size: 18px; flex-shrink: 0; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(11,61,46,.55); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100;
}
.modal-card {
  background: var(--card); border-radius: 18px; padding: 28px;
  width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-md); border: 1px solid var(--border);
}
.modal-card h3 { margin-bottom: 20px; color: var(--primary-dark); letter-spacing: -.01em; }
.modal-sm { max-width: 420px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

/* ---------- Toast ---------- */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--primary-dark); color: #fff; padding: 12px 18px; border-radius: 10px;
  font-size: 13px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.22);
  animation: slideIn .2s ease-out;
}
.toast.success { background: var(--primary); }
.toast.error { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Status pills ---------- */
.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; white-space: nowrap; letter-spacing: .02em;
}
.pill-easy { background: var(--primary-light); color: var(--primary-dark); }
.pill-medium { background: #FFF4E0; color: #B26A00; }
.pill-hard { background: #FDE8E8; color: #B02020; }
.pill-active { background: var(--primary-light); color: var(--primary-dark); }
.pill-blocked { background: #FDE8E8; color: #B02020; }
.pill-pending { background: #FFF4E0; color: #B26A00; }
.pill-yes { background: var(--primary-light); color: var(--primary-dark); }
.pill-no { background: #F0F0F0; color: var(--muted); }

/* ---------- Responsive: tablets & phones ---------- */
@media (max-width: 800px) {
  /* Sidebar becomes a sticky top bar with icon navigation */
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; min-height: 0;
    position: sticky; top: 0; z-index: 60;
    flex-direction: row; align-items: center;
  }
  .sidebar-brand { padding: 10px 12px; border-bottom: none; font-size: 16px; }
  .sidebar-brand .brand-text { display: none; }
  .sidebar-nav {
    flex: 1; flex-direction: row; padding: 6px 8px; gap: 2px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  .nav-item { padding: 10px 12px; font-size: 18px; white-space: nowrap; flex-shrink: 0; width: auto; }
  .nav-item .nav-label { display: none; }
  .nav-item .badge { margin-left: 2px; }
  .sidebar-footer {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px; border-top: none;
    border-left: 1px solid rgba(255,255,255,.12); margin-left: auto; flex-shrink: 0;
  }
  .sidebar-footer .btn-ghost { width: auto; }
  .admin-email { display: none; }

  .main { padding: 18px 16px; max-width: none; }
  .page-title { font-size: 21px; margin-bottom: 16px; }
  .page-header { flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
  .page-header .btn-primary { flex: 1; min-width: 160px; }

  .stat-cards { grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 20px; }
  .stat-card { padding: 16px; }
  .stat-num { font-size: 26px; }

  .subjects-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .subject-card { padding: 16px 10px; }
  .subject-card .icon { font-size: 30px; }
  .card-hint { opacity: 1; } /* always visible on touch devices */

  .topics-grid { grid-template-columns: 1fr; gap: 12px; }

  .filters { flex-direction: column; }
  .filters .input { width: 100%; min-width: 0; }
  .form-actions .btn { width: 100%; }

  .btn { min-height: 42px; }
  .btn-sm { min-height: 36px; }
  .back-btn { min-height: 36px; }

  /* Modals become bottom sheets on phones */
  .modal { padding: 0; align-items: flex-end; }
  .modal-card {
    padding: 24px 18px calc(24px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0; max-height: 94vh; max-width: none;
  }

  .options-grid, .form-row { grid-template-columns: 1fr; }

  .login-card { padding: 28px 22px; }
  .login-card h1 { font-size: 22px; }

  .subject-bar-name { width: 104px; }
  .subject-bar-count { width: 44px; }

  .table th, .table td { padding: 10px; }
  .toast-container { left: 12px; right: 12px; top: 12px; }
  .toast { text-align: center; }
}

/* ---------- Small phones ---------- */
@media (max-width: 400px) {
  .stat-cards { gap: 10px; }
  .stat-card { padding: 14px 12px; }
  .stat-num { font-size: 22px; }
  .stat-label { font-size: 12px; }
  .subjects-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .subject-card h4 { font-size: 13px; }
}
