:root {
  --bg: #0b1120;
  --surface: #111a2e;
  --surface-2: #16223c;
  --border: #243150;
  --text: #e6ecf7;
  --muted: #8da2c5;
  --primary: #4f7cff;
  --primary-600: #3d68f0;
  --success: #2bb673;
  --warn: #e0a32e;
  --danger: #e05656;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 12px 40px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
/* The `hidden` attribute must win over component display rules (e.g. .login-wrap{display:grid}). */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1a2a52 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.center { text-align: center; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; cursor: pointer; transition: .15s;
  display: inline-flex; align-items: center; gap: 8px; line-height: 1;
}
.btn:hover { border-color: #36507f; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger { background: transparent; border-color: #5a2b2b; color: #ff9b9b; }
.btn-danger:hover { background: rgba(224,86,86,.12); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { font-size: 19px; margin: 0; }
.brand p { margin: 2px 0 0; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #8a5bff); color: #fff;
  font-weight: 800; font-size: 22px; flex: none;
}
.brand-mark.sm { width: 30px; height: 30px; border-radius: 8px; font-size: 15px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field > span { font-weight: 600; }
input, select, textarea {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 11px 12px; font-size: 14px; font-family: inherit;
  width: 100%; outline: none; transition: .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,124,255,.18); }
textarea { resize: vertical; min-height: 70px; }
.form-error { color: #ff9b9b; font-size: 13px; margin: 0; }

/* ---------- App bar (top) ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; padding: 10px 18px;
  background: rgba(11,17,32,.9); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
#screenTitle { font-size: 17px; margin: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topnav { display: flex; gap: 4px; margin-left: 10px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.topnav::-webkit-scrollbar { display: none; }
.topnav button {
  background: transparent; border: none; color: var(--muted); padding: 8px 13px;
  border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.topnav button:hover { color: var(--text); background: var(--surface-2); }
.topnav button.active { color: #fff; background: var(--primary); }
.appbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  width: 36px; height: 36px; border-radius: 10px; font-size: 24px; line-height: 1;
  cursor: pointer; display: grid; place-items: center; flex: none; padding: 0;
}
.icon-btn:active { transform: scale(.94); }
.badge {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  padding: 3px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--muted);
}
.badge.admin { color: #ffd479; border-color: #5a4a1e; background: rgba(224,163,46,.12); }
.badge.employee { color: #8fd0ff; border-color: #1e4a5a; background: rgba(46,160,224,.12); }

/* ---------- Bottom tab bar (mobile only) ---------- */
.tabbar { display: none; }
.tabbar button {
  flex: 1; background: transparent; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 2px; font-size: 11px; font-weight: 600; cursor: pointer; min-width: 0;
}
.tabbar button .ic { font-size: 21px; line-height: 1; }
.tabbar button.active { color: var(--primary); }
.tabbar button span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ---------- Mobile-first overrides ---------- */
@media (max-width: 760px) {
  .topnav { display: none; }
  #whoami { display: none; }
  #appLogo { display: none; }                 /* back button or title carries identity */
  .appbar { padding: 10px 14px; }
  .appbar-right { gap: 8px; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: rgba(11,17,32,.96); backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .page { padding-bottom: 84px; }             /* clear the fixed tab bar */
}

/* ---------- Page / cards ---------- */
.page { max-width: 1080px; margin: 0 auto; padding: 22px 18px 60px; display: flex; flex-direction: column; gap: 18px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: 0 4px 20px rgba(0,0,0,.18);
}
.card h2 { margin: 0 0 4px; font-size: 17px; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.card .sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- Stats ---------- */
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .num { font-size: 28px; font-weight: 800; line-height: 1; }
.stat .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 14px; }

/* ---------- List (tappable rows) ---------- */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: transparent; border: none; border-bottom: 1px solid var(--border);
  padding: 12px 12px; cursor: pointer; color: var(--text); font: inherit;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--surface-2); }
.list-item:active { background: rgba(255,255,255,.04); }
.li-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--muted); font-size: 22px; line-height: 1; }
.avatar {
  width: 40px; height: 40px; border-radius: 11px; flex: none; display: grid; place-items: center;
  font-weight: 800; color: #fff; background: linear-gradient(135deg, var(--primary), #8a5bff);
}
.avatar.lg { width: 56px; height: 56px; border-radius: 15px; font-size: 24px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; font-weight: 700; background: var(--surface-2); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,.02); }
td.wrap { white-space: normal; }

/* ---------- Pills ---------- */
.pill { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; display: inline-block; }
.pill-office { background: rgba(43,182,115,.15); color: #6ee7b0; }
.pill-wfh { background: rgba(79,124,255,.15); color: #9db8ff; }
.pill-present { background: rgba(43,182,115,.15); color: #6ee7b0; }
.pill-pending { background: rgba(224,163,46,.15); color: #ffd479; }
.pill-approved { background: rgba(43,182,115,.15); color: #6ee7b0; }
.pill-rejected { background: rgba(224,86,86,.15); color: #ff9b9b; }
.pill-active { background: rgba(43,182,115,.15); color: #6ee7b0; }
.pill-inactive { background: rgba(224,86,86,.15); color: #ff9b9b; }
.pill-leave { background: rgba(224,86,86,.15); color: #ff9b9b; }

.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); cursor: pointer; background: var(--surface-2); }

/* ---------- Calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal .dow { text-align: center; color: var(--muted); font-size: 11px; font-weight: 700; padding-bottom: 4px; }
.cal .cell {
  aspect-ratio: 1; border-radius: 9px; border: 1px solid var(--border); display: flex;
  flex-direction: column; align-items: center; justify-content: center; font-size: 13px; position: relative;
}
.cal .cell .d { font-weight: 700; }
.cal .cell.empty { border: none; background: transparent; }
.cell.s-office { background: rgba(43,182,115,.16); border-color: rgba(43,182,115,.4); }
.cell.s-wfh { background: rgba(79,124,255,.16); border-color: rgba(79,124,255,.4); }
.cell.s-present { background: rgba(43,182,115,.16); border-color: rgba(43,182,115,.4); }
.cell.s-leave { background: rgba(224,86,86,.16); border-color: rgba(224,86,86,.4); }
.cell.s-absent { background: rgba(224,86,86,.10); border-color: rgba(224,86,86,.25); color: #ff9b9b; }
.cell.s-holiday { background: var(--surface-2); color: var(--muted); }
.cell.s-today { outline: 2px solid var(--primary); outline-offset: 1px; }
.cell.s-upcoming { opacity: .5; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 12px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* ---------- Map ---------- */
.map { height: 320px; border-radius: var(--radius-sm); border: 1px solid var(--border); z-index: 1; }
.leaflet-container { background: var(--surface-2); }

/* ---------- Toast ---------- */
.toasts { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
  border-radius: 10px; padding: 12px 16px; box-shadow: var(--shadow); max-width: 340px;
  font-size: 14px; animation: slideIn .2s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(3,7,18,.7); z-index: 100;
  display: grid; place-items: center; padding: 20px; backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; box-shadow: var(--shadow);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.x-btn { background: transparent; border: none; color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1; }
.cred-box { background: var(--surface-2); border: 1px dashed var(--border); border-radius: 10px; padding: 14px; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
.cred-box div { display: flex; justify-content: space-between; padding: 3px 0; }
.cred-box b { color: #fff; }
.photo-full { max-width: 100%; border-radius: 10px; }
.modal-foot .btn { flex: 1; justify-content: center; }
/* On mobile, modals become bottom sheets that slide up. */
@media (max-width: 760px) {
  .modal-back { align-items: end; padding: 0; }
  .modal { max-width: 100%; max-height: 92vh; border-radius: 18px 18px 0 0; border-bottom: none; animation: sheetUp .22s ease; }
  .modal-foot { position: sticky; bottom: 0; background: var(--surface); padding-bottom: calc(14px + env(safe-area-inset-bottom, 0)); }
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: .6; } }

/* ---------- Misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.loader { text-align: center; color: var(--muted); padding: 30px; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { flex: 1; min-width: 150px; }
.preview-img { width: 90px; height: 90px; border-radius: 10px; object-fit: cover; border: 1px solid var(--border); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { width: auto; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.kv .k { color: var(--muted); }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
