:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --border: #e4e7ec;
  --border-strong: #d3d8e0;
  --text: #101828;
  --text-2: #344054;
  --muted: #667085;
  --accent: #3538cd;
  --accent-hover: #2b2ea6;
  --accent-soft: #eef0fb;
  --present: #067647;
  --present-soft: #ecfdf3;
  --absent: #b42318;
  --absent-soft: #fef3f2;
  --leave: #b54708;
  --leave-soft: #fffaeb;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 6px 10px 22px;
}
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  display: grid; place-items: center; box-shadow: var(--shadow-sm);
}
.brand .logo svg { width: 19px; height: 19px; }
.brand .title { line-height: 1.15; }
.brand .title .n { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.brand .title .s { font-size: 11.5px; color: var(--muted); }

.nav-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; padding: 8px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--text-2); cursor: pointer; font-weight: 500;
  border: none; background: none; width: 100%; text-align: left;
  font-size: 14px; transition: background 0.12s, color 0.12s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--muted); }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.active svg { color: var(--accent); }
.sidebar .spacer { flex: 1; }
.sidebar .hint { font-size: 11.5px; color: var(--muted); padding: 12px 10px; border-top: 1px solid var(--border); line-height: 1.45; }

/* Main */
.main { flex: 1; padding: 34px 44px; max-width: 1120px; }
.view { display: none; }
.view.active { display: block; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.view-head { margin-bottom: 26px; }
.view-head h1 { margin: 0 0 5px; font-size: 23px; font-weight: 700; letter-spacing: -0.02em; }
.view-head p { margin: 0; color: var(--muted); font-size: 14.5px; }

.toolbar { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 22px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--text-2); font-weight: 600; }

input, select {
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  padding: 9px 12px; border-radius: 8px; font-size: 14px; font-family: inherit; outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder { color: #98a2b3; }

.btn {
  background: var(--accent); color: #fff; border: 1px solid var(--accent); padding: 9px 16px;
  border-radius: 8px; font-weight: 600; font-size: 14px; cursor: pointer; font-family: inherit;
  transition: background 0.12s;
}
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: var(--surface); color: var(--text-2); border: 1px solid var(--border-strong); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger-ghost { background: none; color: var(--absent); border: 1px solid transparent; padding: 6px 10px; font-size: 13px; }
.btn.danger-ghost:hover { background: var(--absent-soft); border-color: var(--absent-soft); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); margin-bottom: 22px; overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 18px 20px; }
.card h3 { margin: 0; font-size: 14.5px; font-weight: 600; }
.card .card-pad + table { border-top: 1px solid var(--border); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 20px; border-bottom: 1px solid var(--border); }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td code, .who code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

.status-group { display: inline-flex; gap: 3px; background: var(--surface-2); padding: 3px; border-radius: 9px; border: 1px solid var(--border); }
.status-btn {
  border: none; background: none; color: var(--muted); cursor: pointer;
  padding: 6px 14px; border-radius: 6px; font-size: 13px; font-weight: 600; font-family: inherit;
  transition: color 0.1s;
}
.status-btn:hover { color: var(--text); }
.status-btn.on[data-status="present"] { background: var(--present); color: #fff; }
.status-btn.on[data-status="absent"]  { background: var(--absent);  color: #fff; }
.status-btn.on[data-status="leave"]   { background: var(--leave);   color: #fff; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.present { background: var(--present-soft); color: var(--present); }
.pill.absent  { background: var(--absent-soft);  color: var(--absent); }
.pill.leave   { background: var(--leave-soft);   color: var(--leave); }

.rate-bar { display: inline-block; position: relative; height: 7px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; width: 110px; vertical-align: middle; margin-left: 8px; }
.rate-bar > span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--present); }

.empty { padding: 46px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.stat .n { font-size: 25px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(160%);
  background: var(--text); color: #fff;
  padding: 12px 20px; border-radius: 9px; box-shadow: var(--shadow-md);
  transition: transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1); z-index: 50; font-size: 14px; font-weight: 500;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--absent); }

.row-actions { text-align: right; }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }

.banner {
  background: var(--accent-soft); border: 1px solid #c7ccf5; color: var(--text-2);
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 20px; font-size: 14px; line-height: 1.5;
}
.banner strong { color: var(--accent); }

/* Student lookup */
.profile {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px; margin-bottom: 22px; box-shadow: var(--shadow-sm);
}
.profile .avatar {
  width: 58px; height: 58px; border-radius: 14px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  display: grid; place-items: center; font-size: 21px; font-weight: 700; color: #fff;
}
.profile .who { flex: 1; min-width: 180px; }
.profile .who .nm { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.profile .who .meta { color: var(--muted); font-size: 14px; margin-top: 3px; }
.profile .who .meta code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 7px; border-radius: 6px; color: var(--text-2); }
.profile .big-rate { text-align: center; padding-left: 20px; border-left: 1px solid var(--border); }
.profile .big-rate .v { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; color: var(--accent); }
.profile .big-rate .k { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Account block in sidebar */
.account { border-top: 1px solid var(--border); padding-top: 14px; }
.account-user { display: flex; align-items: center; gap: 10px; padding: 4px 8px 12px; }
.account-avatar {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px;
}
.account-name .k { font-size: 11px; color: var(--muted); }
.account-name .v { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.account .btn.ghost { width: 100%; }

/* Login / registration screen */
.auth-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #e5e8fb 0%, var(--bg) 60%);
}
.auth-screen.hidden { display: none; }
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow-md); padding: 34px 32px;
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-brand .logo {
  width: 40px; height: 40px; border-radius: 11px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  display: grid; place-items: center; box-shadow: var(--shadow-sm);
}
.auth-brand .logo svg { width: 22px; height: 22px; }
.auth-brand .n { font-weight: 700; font-size: 18px; letter-spacing: -0.02em; }
.auth-brand .s { font-size: 12.5px; color: var(--muted); }
.auth-tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); padding: 4px; border-radius: 10px; margin-bottom: 22px; }
.auth-tab { flex: 1; border: none; background: none; padding: 8px; border-radius: 7px; font-family: inherit; font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.auth-tab.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }
#auth-form .field { margin-bottom: 16px; }
#auth-form .field input { width: 100%; }

/* show/hide password toggle */
.password-wrap { position: relative; display: flex; align-items: center; }
.password-wrap input { width: 100%; padding-right: 42px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; padding: 5px; cursor: pointer;
  color: var(--muted); display: grid; place-items: center; border-radius: 6px;
  transition: color 0.12s;
}
.pw-toggle:hover { color: var(--text); }
.pw-toggle svg { width: 18px; height: 18px; display: block; }
#auth-submit { width: 100%; padding: 11px; margin-top: 4px; font-size: 15px; }
.auth-error { color: var(--absent); font-size: 13px; font-weight: 500; min-height: 18px; margin-bottom: 6px; }
.auth-error:empty { margin-bottom: 0; }
.auth-hint { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: 18px; }

@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; flex-direction: row; overflow-x: auto; align-items: center; }
  .sidebar .brand, .sidebar .spacer, .sidebar .hint, .nav-label { display: none; }
  .nav-item span { display: none; }
  .main { padding: 22px; }
  .profile .big-rate { border-left: none; padding-left: 0; }
}
