/* ── Reset & Tokens ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:   #1a3a6b;
  --blue2:  #2855a0;
  --blue3:  #e8eef8;
  --orange: #e65c00;
  --orange2:#ff8c42;
  --bg:     #f0f4f9;
  --surf:   #ffffff;
  --text:   #1a1f2e;
  --muted:  #64748b;
  --border: #dde3ee;
  --success:#16a34a;
  --danger: #dc2626;
  --radius: 14px;
  --sh:     0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --sh2:    0 8px 32px rgba(0,0,0,.12);
  --sidebar-w: 220px;
  --topbar-h:  56px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: inherit; text-decoration: none; }
img { display: block; }
button { cursor: pointer; font-family: inherit; }

/* ── Common ──────────────────────────────────────────────────────────── */

.hidden { display: none !important; }
.muted  { color: var(--muted); }
.num    { text-align: right; font-variant-numeric: tabular-nums; }
.bold   { font-weight: 600; }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  color: #fff; border: none; border-radius: 10px;
  padding: 12px 24px; font-size: .95rem; font-weight: 600;
  cursor: pointer; transition: opacity .15s, transform .1s;
  text-decoration: none;
}
.btn-primary:hover { opacity: .9; }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-ghost {
  background: transparent; border: 1.5px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 8px 16px;
  font-size: .875rem; font-weight: 500; transition: background .15s;
}
.btn-ghost:hover { background: var(--blue3); }

.btn-sm { padding: 6px 12px; font-size: .8rem; }

.icon-btn {
  background: transparent; border: none; font-size: 1.1rem;
  padding: 6px; border-radius: 6px; color: var(--muted);
  transition: background .15s;
}
.icon-btn:hover { background: var(--blue3); color: var(--text); }

.card {
  background: var(--surf); border-radius: var(--radius);
  box-shadow: var(--sh); padding: 20px;
  margin-bottom: 16px;
}
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 16px; color: var(--blue); }

/* ── Toast ───────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(12px);
  background: #1e293b; color: #fff; padding: 10px 20px;
  border-radius: 999px; font-size: .875rem; font-weight: 500;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 9999;
  white-space: nowrap; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error   { background: var(--danger); }
.toast.toast-success { background: var(--success); }

/* ════════════════════ LOGIN PAGE ════════════════════════════════════════ */
.login-page {
  background: linear-gradient(135deg, var(--blue) 0%, #2a5298 50%, #1e3a5f 100%);
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.login-page::before {
  content: ''; position: fixed; inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
}

.login-wrap { width: 100%; max-width: 420px; position: relative; z-index: 1; }

.login-card {
  background: var(--surf); border-radius: 20px;
  box-shadow: var(--sh2); padding: 36px 32px 28px;
}

.login-brand {
  display: flex; align-items: center; gap: 14px; margin-bottom: 28px;
}
.brand-emblem {
  width: 52px; height: 52px; border-radius: 12px;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; flex-shrink: 0;
}
.brand-title { font-size: 1.25rem; font-weight: 700; color: var(--blue); line-height: 1.2; }
.brand-sub { font-size: .72rem; color: var(--muted); margin-top: 2px; }

.field { margin-bottom: 18px; }
.field label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; letter-spacing: .02em; text-transform: uppercase; }

.field input {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border);
  border-radius: 10px; font-size: .95rem; color: var(--text);
  background: var(--bg); transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.field input:focus { border-color: var(--blue2); box-shadow: 0 0 0 3px rgba(40,85,160,.12); background: var(--surf); }

.input-wrap { position: relative; }
.input-wrap input { padding-right: 44px; }
.input-wrap .icon-btn { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); }

.captcha-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.captcha-img {
  height: 46px; min-width: 120px; border-radius: 8px;
  border: 1.5px solid var(--border); background: #f8f9fb;
  object-fit: contain; transition: opacity .2s;
}
.refresh-btn { font-size: 1.2rem; }

.login-card .btn-primary { width: 100%; margin-top: 8px; padding: 13px; font-size: 1rem; }

.login-footer { text-align: center; margin-top: 20px; font-size: .78rem; color: rgba(255,255,255,.55); }

/* OTP Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
  backdrop-filter: blur(4px);
}
.modal-card {
  background: var(--surf); border-radius: 20px;
  padding: 32px 28px; width: 340px; max-width: 90vw;
  box-shadow: var(--sh2);
}
.modal-card h2 { font-size: 1.2rem; font-weight: 700; margin-bottom: 8px; color: var(--blue); }
.modal-desc { color: var(--muted); font-size: .875rem; margin-bottom: 20px; }
.modal-card .btn-primary { width: 100%; margin-top: 4px; margin-bottom: 10px; }
.modal-card .btn-ghost { width: 100%; }

/* ════════════════════ APP PAGE ══════════════════════════════════════════ */
.app-page { display: flex; flex-direction: column; }

/* Topbar */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  background: var(--blue); color: #fff; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.topbar-left  { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.topbar-logo { display: flex; align-items: center; gap: 4px; font-weight: 700; font-size: 1rem; }
.logo-pb { background: var(--orange); color: #fff; padding: 2px 7px; border-radius: 6px; font-size: .85rem; }
.logo-hrms { color: rgba(255,255,255,.9); }

.user-chip {
  font-size: .82rem; color: rgba(255,255,255,.85);
  background: rgba(255,255,255,.12); padding: 4px 10px; border-radius: 99px;
  max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar .btn-ghost { color: rgba(255,255,255,.85); border-color: rgba(255,255,255,.25); font-size: .78rem; }
.topbar .icon-btn { color: rgba(255,255,255,.8); }

/* Sidebar */
.sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0;
  width: var(--sidebar-w); background: var(--surf);
  border-right: 1px solid var(--border); z-index: 90;
  overflow-y: auto; padding: 12px 0;
  transition: transform .25s ease;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 20px; font-size: .9rem; color: var(--muted);
  border-left: 3px solid transparent; transition: all .15s;
  cursor: pointer;
}
.nav-item:hover { background: var(--blue3); color: var(--text); }
.nav-item.active { background: var(--blue3); color: var(--blue); font-weight: 600; border-left-color: var(--blue); }
.nav-item svg { flex-shrink: 0; }

/* Main */
.app-main {
  margin-top: var(--topbar-h); margin-left: var(--sidebar-w);
  padding: 24px; min-height: calc(100vh - var(--topbar-h));
}

/* Home */
.welcome-block {
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue2) 100%);
  border-radius: var(--radius); padding: 24px 28px; margin-bottom: 20px; color: #fff;
}
.welcome-block h2 { font-size: 1.4rem; font-weight: 700; margin-bottom: 4px; }
.welcome-block .muted { color: rgba(255,255,255,.7); font-size: .9rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }

.stat-card {
  background: var(--surf); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--sh);
  border-top: 3px solid var(--blue2);
  animation: fadeUp .3s ease both;
  animation-delay: calc(var(--i, 0) * 60ms);
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.stat-label { font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 8px; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--blue); line-height: 1; }
.stat-meta  { font-size: .75rem; color: var(--muted); margin-top: 6px; }

/* Section */
.section { animation: fadeUp .25s ease; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-head h2 { font-size: 1.2rem; font-weight: 700; color: var(--text); }

/* Tables */
.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th { background: var(--blue3); color: var(--blue); font-weight: 600; padding: 11px 14px; text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--text); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--blue3); }
.loader-cell, .err-cell, .empty-cell { text-align: center; padding: 32px; color: var(--muted); font-size: .9rem; }
.err-cell { color: var(--danger); }

/* Profile card */
.profile-card {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  color: #fff; font-size: 1.3rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.profile-text h3 { font-size: 1.1rem; font-weight: 700; }
.profile-text p { font-size: .875rem; color: var(--muted); margin-top: 2px; }
.profile-badges { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.badge { background: var(--blue3); color: var(--blue); padding: 4px 12px; border-radius: 999px; font-size: .78rem; }
.badge b { font-weight: 700; }

/* Detail grid */
.detail-grid { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; }
.detail-grid dt { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; display: flex; align-items: center; }
.detail-grid dd { font-size: .9rem; color: var(--text); }

/* Apply card */
.apply-card { text-align: center; padding: 40px 32px; }
.apply-icon { font-size: 3rem; margin-bottom: 12px; }
.apply-card h3 { font-size: 1.2rem; font-weight: 700; margin-bottom: 8px; }
.apply-card .muted { margin-bottom: 24px; max-width: 340px; margin-left: auto; margin-right: auto; }
.apply-link { display: inline-flex; padding: 12px 28px; margin-bottom: 14px; }
.apply-note { font-size: .78rem; color: var(--muted); }

/* History filters */
.history-filters { display: flex; align-items: center; gap: 8px; }
.select-sm {
  border: 1.5px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: .82rem; color: var(--text);
  background: var(--surf); outline: none; cursor: pointer;
}
.select-sm:focus { border-color: var(--blue2); }

/* Loader/Error cells as divs */
div.loader-cell, div.err-cell {
  text-align: center; padding: 40px; color: var(--muted); font-size: .9rem;
  display: block;
}

/* ── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--sh2); }
  .sidebar.open { transform: translateX(0); }
  .app-main { margin-left: 0; padding: 16px; }
  .login-card { padding: 28px 20px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-value { font-size: 1.6rem; }
  .profile-card { flex-direction: column; align-items: flex-start; }
  .profile-badges { margin-left: 0; }
  .detail-grid { grid-template-columns: 1fr; gap: 4px 0; }
  .detail-grid dt { margin-top: 10px; }
  .user-chip { display: none; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .welcome-block { padding: 18px; }
  .topbar { padding: 0 12px; }
}
