/* ============ TOKENS ============ */
:root{
  --bg:#F6F3EA;
  --surface:#FFFFFF;
  --surface-alt:#EFEBDD;
  --ink:#1E2A22;
  --ink-soft:#5B6B60;
  --ink-faint:#8A968C;
  --primary:#1B4B43;
  --primary-light:#2E6E5F;
  --primary-dark:#0F332C;
  --accent:#C17817;
  --accent-light:#E7A94E;
  --border:#DFD9C6;
  --success:#2D7D5A;
  --success-bg:#E4F1E9;
  --danger:#B3452F;
  --danger-bg:#F9E7E1;
  --warning:#C17817;
  --warning-bg:#FBEFDD;
  --info:#2A5C88;
  --info-bg:#E5EEF6;
  --radius-s:6px;
  --radius-m:10px;
  --radius-l:16px;
  --shadow-s: 0 1px 2px rgba(15,51,44,.06);
  --shadow-m: 0 8px 24px rgba(15,51,44,.10);
  --shadow-l: 0 24px 60px rgba(15,51,44,.20);
  --font-display:'Lora', serif;
  --font-body:'Inter', sans-serif;
  --font-mono:'IBM Plex Mono', monospace;
}

*,*::before,*::after{box-sizing:border-box;}
html,body{height:100%;}
body{
  margin:0;
  background:var(--bg);
  color:var(--ink);
  font-family:var(--font-body);
  -webkit-font-smoothing:antialiased;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(27,75,67,.05) 1px, transparent 0);
  background-size:22px 22px;
}
h1,h2,h3,h4{font-family:var(--font-display); margin:0; color:var(--primary-dark); letter-spacing:-.01em;}
p{margin:0;}
button{font-family:inherit;}
::selection{background:var(--accent-light); color:var(--primary-dark);}

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible{
  outline:2px solid var(--accent); outline-offset:2px;
}

@media (prefers-reduced-motion: reduce){
  *{animation-duration:.001ms !important; transition-duration:.001ms !important;}
}

::-webkit-scrollbar{width:10px; height:10px;}
::-webkit-scrollbar-thumb{background:#D3CDB8; border-radius:10px;}
::-webkit-scrollbar-track{background:transparent;}

/* ============ LOGIN SCREEN ============ */
#login-screen{
  position:fixed; inset:0; display:flex; align-items:center; justify-content:center; flex-direction:column;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(46,110,95,.18), transparent 60%),
    radial-gradient(900px 500px at 100% 110%, rgba(193,120,23,.14), transparent 55%),
    var(--primary-dark);
  z-index:500; text-align:center; padding:24px;
}
#login-screen .rx-mark{ width:76px; height:76px; margin-bottom:22px; animation: rise .8s cubic-bezier(.2,.8,.2,1) both;}
#login-screen h1{ color:#F6F3EA; font-size:clamp(24px,4vw,34px); font-weight:600; max-width:820px; animation: rise .8s .06s cubic-bezier(.2,.8,.2,1) both;}
#login-screen .tag{
  color:#C9D9CE; font-family:var(--font-mono); letter-spacing:.14em; text-transform:uppercase; font-size:11.5px; margin-top:12px;
  animation: rise .8s .12s cubic-bezier(.2,.8,.2,1) both;
}
.login-card{
  margin-top:32px; width:100%; max-width:380px; background:rgba(255,255,255,.06); border:1px solid rgba(255,255,255,.14);
  border-radius:var(--radius-l); padding:26px; backdrop-filter:blur(6px);
  animation: rise .8s .2s cubic-bezier(.2,.8,.2,1) both; text-align:left;
}
.login-card .field label{ color:#C9D9CE; }
.login-card .field input, .login-card .field select{
  background:rgba(255,255,255,.94); border:1px solid transparent;
}
.login-card .error-msg{ color:#F3B49C; font-size:12.5px; margin:-4px 0 12px; min-height:16px; font-weight:600;}
.login-card .capsule-btn{ width:100%; justify-content:center;}
.login-card .capsule-btn span{ flex:1; text-align:center;}
.demo-creds{
  margin-top:18px; padding-top:16px; border-top:1px dashed rgba(255,255,255,.2);
  font-size:11.5px; color:#9FB3A6; line-height:1.7; text-align:left;
}
.demo-creds b{ color:#EDECE3; font-family:var(--font-mono); font-weight:600;}
.demo-creds button{
  background:none; border:none; color:var(--accent-light); cursor:pointer; font-size:11.5px; text-decoration:underline; padding:0;
  font-family:var(--font-mono);
}

@keyframes rise{ from{ opacity:0; transform:translateY(14px);} to{opacity:1; transform:translateY(0);} }

.capsule-btn{
  border:none; cursor:pointer; display:inline-flex; align-items:center; gap:10px;
  padding:0; border-radius:999px; overflow:hidden; box-shadow:var(--shadow-m);
  transition:transform .18s ease, box-shadow .18s ease;
}
.capsule-btn:hover{ transform:translateY(-2px); box-shadow:var(--shadow-l); }
.capsule-btn span{ padding:14px 26px; font-weight:600; font-size:15px;}
.capsule-btn .half-a{ background:var(--accent); color:var(--primary-dark);}
.capsule-btn .half-b{ background:#F6F3EA; color:var(--primary-dark);}

/* ============ APP SHELL ============ */
#app{ display:none; min-height:100vh; grid-template-columns:264px 1fr; }
#app.active{ display:grid; }

.sidebar{
  background:var(--primary-dark);
  color:#EDECE3;
  padding:26px 18px;
  display:flex; flex-direction:column; gap:26px;
  position:sticky; top:0; height:100vh;
}
.brand{ display:flex; align-items:center; gap:12px; padding:0 6px;}
.brand svg{ width:38px; height:38px; flex-shrink:0;}
.brand-text h2{ color:#F6F3EA; font-size:16px; line-height:1.25;}
.brand-text span{ display:block; font-family:var(--font-mono); font-size:10px; color:#9FB3A6; letter-spacing:.1em; text-transform:uppercase; margin-top:2px;}

.nav-capsule{
  display:flex; flex-direction:column; gap:4px;
  background:rgba(255,255,255,.05); border-radius:var(--radius-l); padding:6px;
}
.nav-item{
  display:flex; align-items:center; gap:12px; padding:11px 14px; border-radius:999px;
  color:#C9D9CE; text-decoration:none; font-size:13.5px; font-weight:500; cursor:pointer; border:none; background:transparent; width:100%; text-align:left;
  transition:background .15s ease, color .15s ease;
}
.nav-item svg{ width:17px; height:17px; flex-shrink:0; opacity:.85;}
.nav-item:hover{ background:rgba(255,255,255,.07); color:#fff;}
.nav-item.active{ background:linear-gradient(135deg, var(--accent), var(--accent-light)); color:var(--primary-dark); font-weight:600; }
.nav-item.active svg{ opacity:1;}
.nav-item[hidden]{ display:none;}

.sidebar-footer{ margin-top:auto; padding:14px; border-radius:var(--radius-m); background:rgba(255,255,255,.05);}
.sidebar-footer p{ font-size:12px; color:#9FB3A6; line-height:1.5;}
.sidebar-footer strong{ color:#EDECE3; display:block; font-family:var(--font-mono); font-size:11px; letter-spacing:.06em; text-transform:uppercase; margin-bottom:4px;}

main{ padding:28px 36px 60px; max-width:1320px; }
.topbar{ display:flex; align-items:flex-end; justify-content:space-between; margin-bottom:26px; gap:20px; flex-wrap:wrap;}
.topbar .eyebrow{ font-family:var(--font-mono); font-size:11px; letter-spacing:.14em; text-transform:uppercase; color:var(--accent); font-weight:600; margin-bottom:6px; display:block;}
.topbar h1{ font-size:28px;}
.topbar .sub{ color:var(--ink-soft); font-size:13.5px; margin-top:6px; max-width:520px;}

.user-chip{
  display:flex; align-items:center; gap:10px; background:var(--surface); border:1px solid var(--border);
  padding:7px 8px 7px 7px; border-radius:999px; box-shadow:var(--shadow-s);
}
.user-chip .avatar{
  width:34px; height:34px; border-radius:50%; background:linear-gradient(135deg,var(--primary),var(--primary-light));
  color:#fff; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:13px; flex-shrink:0;
}
.user-chip .who{ text-align:left; line-height:1.25;}
.user-chip .who .name{ font-size:12.5px; font-weight:700; color:var(--primary-dark);}
.user-chip .who .role{ font-size:11px; color:var(--ink-soft);}
.user-chip .signout{
  width:30px; height:30px; border-radius:50%; border:none; background:var(--surface-alt); color:var(--ink-soft); cursor:pointer;
  display:flex; align-items:center; justify-content:center; margin-left:4px; transition:all .15s ease;
}
.user-chip .signout:hover{ background:var(--danger-bg); color:var(--danger);}
.user-chip .signout svg{ width:14px; height:14px;}

/* ============ CARDS / STATS ============ */
.stat-grid{ display:grid; grid-template-columns:repeat(4,1fr); gap:16px; margin-bottom:30px;}
.stat-card{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-l); padding:20px;
  box-shadow:var(--shadow-s); position:relative; overflow:hidden;
}
.stat-card::before{ content:''; position:absolute; top:0; left:0; width:4px; height:100%; background:var(--accent);}
.stat-card.alert::before{ background:var(--danger);}
.stat-card .n{ font-family:var(--font-display); font-size:32px; font-weight:700; color:var(--primary-dark); line-height:1;}
.stat-card .l{ font-size:12.5px; color:var(--ink-soft); margin-top:8px; font-weight:500;}

.panel{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-l);
  box-shadow:var(--shadow-s); margin-bottom:24px; overflow:hidden;
}
.panel-head{ display:flex; align-items:center; justify-content:space-between; padding:20px 22px; border-bottom:1px solid var(--border); gap:14px; flex-wrap:wrap;}
.panel-head h3{ font-size:17px;}
.panel-head .sub{ font-size:12.5px; color:var(--ink-soft); margin-top:3px;}
.panel-head .actions{ display:flex; gap:8px; flex-wrap:wrap; align-items:center;}
.panel-body{ padding:20px 22px;}

/* ============ BUTTONS ============ */
.btn{
  display:inline-flex; align-items:center; gap:8px; border-radius:999px; border:1px solid transparent;
  padding:10px 18px; font-weight:600; font-size:13.5px; cursor:pointer; transition:all .15s ease; white-space:nowrap;
}
.btn svg{ width:15px; height:15px;}
.btn-primary{ background:var(--primary); color:#fff; }
.btn-primary:hover{ background:var(--primary-light); }
.btn-accent{ background:var(--accent); color:#3A2405;}
.btn-accent:hover{ background:var(--accent-light);}
.btn-ghost{ background:transparent; border-color:var(--border); color:var(--primary-dark);}
.btn-ghost:hover{ background:var(--surface-alt);}
.btn-danger{ background:transparent; border-color:var(--danger); color:var(--danger);}
.btn-danger:hover{ background:var(--danger-bg);}
.btn-sm{ padding:7px 12px; font-size:12.5px;}
.btn:disabled{ opacity:.45; cursor:not-allowed;}

.icon-btn{
  width:32px; height:32px; border-radius:8px; border:1px solid var(--border); background:var(--surface);
  display:inline-flex; align-items:center; justify-content:center; cursor:pointer; color:var(--ink-soft);
  transition:all .15s ease;
}
.icon-btn:hover{ background:var(--surface-alt); color:var(--primary-dark);}
.icon-btn svg{width:15px; height:15px;}
.icon-btn.danger:hover{ background:var(--danger-bg); color:var(--danger); border-color:var(--danger);}

/* ============ FORMS ============ */
.field{ display:flex; flex-direction:column; gap:6px; margin-bottom:16px;}
.field label{ font-size:12.5px; font-weight:600; color:var(--ink-soft); }
.field input, .field select, .field textarea{
  border:1px solid var(--border); border-radius:var(--radius-s); padding:10px 12px; font-size:14px; font-family:inherit;
  background:var(--surface); color:var(--ink); transition:border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus{
  border-color:var(--primary-light); box-shadow:0 0 0 3px rgba(46,110,95,.12); outline:none;
}
.field .hint{ font-size:11.5px; color:var(--ink-faint);}
.form-grid{ display:grid; grid-template-columns:1fr 1fr; gap:0 16px;}
.form-grid .span2{ grid-column:1/-1;}

.search-row{ display:flex; gap:10px; flex-wrap:wrap; align-items:center;}
.search-row input, .search-row select{
  border:1px solid var(--border); border-radius:999px; padding:9px 16px; font-size:13.5px; background:var(--surface);
}
.search-row input{ min-width:220px;}

/* ============ TABLE ============ */
table{ width:100%; border-collapse:collapse; font-size:13.5px;}
thead th{
  text-align:left; font-size:11px; text-transform:uppercase; letter-spacing:.06em; color:var(--ink-faint);
  font-weight:600; padding:0 14px 10px; border-bottom:1px solid var(--border);
}
tbody td{ padding:13px 14px; border-bottom:1px solid var(--border); vertical-align:middle;}
tbody tr:last-child td{ border-bottom:none;}
tbody tr:hover{ background:var(--surface-alt);}
td.mono, .mono{ font-family:var(--font-mono); font-size:12.5px; color:var(--ink-soft);}
.row-actions{ display:flex; gap:6px; justify-content:flex-end;}

.badge{
  display:inline-flex; align-items:center; gap:5px; padding:4px 11px; border-radius:999px; font-size:11.5px; font-weight:700;
  letter-spacing:.02em;
}
.badge-O{ background:#DCEEE4; color:#166446;}
.badge-Aplus{ background:#E4F1E9; color:#2D7D5A;}
.badge-A{ background:#E6F2EE; color:#276B5A;}
.badge-Bplus{ background:var(--warning-bg); color:#8A5A0E;}
.badge-B{ background:#FDF3E4; color:#96650F;}
.badge-C{ background:#FBE9DA; color:#A2540F;}
.badge-P{ background:#FBE9DA; color:#A2540F;}
.badge-F{ background:var(--danger-bg); color:var(--danger);}
.badge-neutral{ background:var(--surface-alt); color:var(--ink-soft);}
.badge-live{ background:var(--success-bg); color:var(--success);}
.badge-upcoming{ background:var(--info-bg); color:var(--info);}
.badge-past{ background:var(--surface-alt); color:var(--ink-soft);}
.badge-eligible{ background:var(--success-bg); color:var(--success);}
.badge-detained{ background:var(--danger-bg); color:var(--danger);}
.badge-admin{ background:#E6E1F5; color:#5B3FA0;}
.badge-faculty{ background:var(--info-bg); color:var(--info);}
.badge-viewer{ background:var(--surface-alt); color:var(--ink-soft);}

.empty-state{ text-align:center; padding:56px 20px; color:var(--ink-soft);}
.empty-state svg{ width:46px; height:46px; margin-bottom:14px; color:var(--accent);}
.empty-state h4{ font-size:16px; color:var(--primary-dark); margin-bottom:6px;}
.empty-state p{ font-size:13px; max-width:360px; margin:0 auto 18px;}

.locked-note{
  display:flex; align-items:center; gap:10px; background:var(--surface-alt); border:1px dashed var(--border);
  border-radius:var(--radius-m); padding:12px 16px; font-size:12.5px; color:var(--ink-soft); margin-bottom:16px;
}
.locked-note svg{ width:16px; height:16px; flex-shrink:0; color:var(--accent);}

/* ============ MODAL ============ */
.modal-overlay{
  position:fixed; inset:0; background:rgba(15,51,44,.45); backdrop-filter:blur(2px);
  display:none; align-items:center; justify-content:center; z-index:600; padding:20px;
}
.modal-overlay.active{ display:flex; }
.modal{
  background:var(--surface); border-radius:var(--radius-l); width:100%; max-width:560px; max-height:88vh; overflow:auto;
  box-shadow:var(--shadow-l); animation: modalIn .22s cubic-bezier(.2,.8,.2,1) both;
}
.modal.wide{ max-width:760px;}
@keyframes modalIn{ from{opacity:0; transform:translateY(10px) scale(.98);} to{opacity:1; transform:translateY(0) scale(1);} }
.modal-head{ display:flex; align-items:center; justify-content:space-between; padding:20px 24px; border-bottom:1px solid var(--border);}
.modal-head h3{ font-size:18px;}
.modal-body{ padding:22px 24px;}
.modal-foot{ display:flex; justify-content:flex-end; gap:10px; padding:16px 24px; border-top:1px solid var(--border); background:var(--surface-alt);}
.close-x{ width:30px; height:30px; border-radius:50%; border:none; background:var(--surface-alt); cursor:pointer; display:flex; align-items:center; justify-content:center; color:var(--ink-soft);}
.close-x:hover{ background:var(--danger-bg); color:var(--danger);}

/* ============ TOAST ============ */
#toast-wrap{ position:fixed; bottom:24px; right:24px; z-index:700; display:flex; flex-direction:column; gap:10px; pointer-events:none; align-items:flex-end;}
.toast{
  background:var(--primary-dark); color:#F6F3EA; padding:13px 18px; border-radius:var(--radius-m); font-size:13.5px;
  box-shadow:var(--shadow-l); display:flex; align-items:center; gap:10px; animation: toastIn .25s ease both;
  min-width:220px; pointer-events:auto;
}
.toast.err{ background:var(--danger);}
.toast svg{ width:16px; height:16px; flex-shrink:0;}
@keyframes toastIn{ from{opacity:0; transform:translateX(20px);} to{opacity:1; transform:translateX(0);} }

/* ============ MARKS / ATTENDANCE TABLES ============ */
.marks-table input, .attendance-table input{ width:78px; text-align:center; padding:7px; border-radius:6px; border:1px solid var(--border);}
.pass-tag{font-weight:700; font-size:11.5px;}
.pass-tag.pass{color:var(--success);}
.pass-tag.fail{color:var(--danger);}
.attendance-total-row{
  display:flex; align-items:center; gap:12px; background:var(--surface-alt); border:1px solid var(--border);
  border-radius:var(--radius-m); padding:12px 16px; margin-bottom:16px; flex-wrap:wrap;
}
.attendance-total-row label{ font-size:12.5px; font-weight:600; color:var(--ink-soft);}
.attendance-total-row input{ width:90px; padding:7px 10px; border-radius:6px; border:1px solid var(--border);}
.pct-bar{ width:70px; height:7px; border-radius:999px; background:var(--surface-alt); overflow:hidden; display:inline-block; vertical-align:middle; margin-right:8px;}
.pct-bar > span{ display:block; height:100%; background:var(--success); border-radius:999px;}
.pct-bar.low > span{ background:var(--danger);}

/* ============ CSV ROW ============ */
.csv-row{ display:flex; gap:8px; align-items:center; flex-wrap:wrap;}
.file-label{
  display:inline-flex; align-items:center; gap:8px; border-radius:999px; border:1px solid var(--border);
  padding:10px 18px; font-weight:600; font-size:13.5px; cursor:pointer; background:transparent; color:var(--primary-dark);
  transition:all .15s ease;
}
.file-label:hover{ background:var(--surface-alt);}
.file-label svg{ width:15px; height:15px;}
.file-label input[type=file]{ display:none;}

/* ============ SETTINGS ============ */
.settings-block{ margin-bottom:26px;}
.settings-block h4{ font-size:14.5px; margin-bottom:4px;}
.settings-block .desc{ font-size:12.5px; color:var(--ink-soft); margin-bottom:14px;}
.threshold-row{ display:flex; align-items:center; gap:12px;}
.threshold-row input{ width:90px; padding:9px 12px; border-radius:var(--radius-s); border:1px solid var(--border);}

/* ============ REPORT CARD (print) ============ */
.report-card{ border:1px solid var(--border); border-radius:var(--radius-m); padding:22px; background:#fff;}
.report-card .rc-head{ display:flex; justify-content:space-between; align-items:flex-start; border-bottom:2px solid var(--primary-dark); padding-bottom:14px; margin-bottom:14px;}
.report-card .rc-head h2{ font-size:19px;}
.report-card .rc-head .rc-sub{ font-size:12px; color:var(--ink-soft); margin-top:4px;}
.report-card .rc-meta{ display:grid; grid-template-columns:1fr 1fr; gap:6px 20px; font-size:13px; margin-bottom:16px;}
.report-card .rc-meta b{ color:var(--ink-soft); font-weight:600;}

@media print{
  body *{ visibility:hidden;}
  #print-area, #print-area *{ visibility:visible;}
  #print-area{ position:absolute; top:0; left:0; width:100%; padding:20px;}
}

/* ============ RESPONSIVE ============ */
@media (max-width:980px){
  #app{ grid-template-columns:1fr;}
  .sidebar{ position:relative; height:auto; flex-direction:row; align-items:center; overflow-x:auto;}
  .sidebar .brand{ flex-shrink:0;}
  .nav-capsule{ flex-direction:row; overflow-x:auto;}
  .sidebar-footer{ display:none;}
  .stat-grid{ grid-template-columns:1fr 1fr;}
  .form-grid{ grid-template-columns:1fr;}
  main{ padding:20px;}
}
