:root {
  --c-bg: #f6f7f9;
  --c-surface: #ffffff;
  --c-border: #e5e7eb;
  --c-text: #111827;
  --c-muted: #6b7280;
  --c-primary: #1f4e78;
  --c-primary-hover: #2a6699;
  --c-accent: #d35400;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --r: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  color: var(--c-text);
  background: var(--c-bg);
  line-height: 1.5;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #eef0f3; padding: 1px 4px; border-radius: 3px; font-size: 0.9em; }

.centered {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.container {
  max-width: 960px;
  margin: 1.5rem auto;
  padding: 0 1rem;
}

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  padding: 2rem;
  box-shadow: var(--shadow-sm);
  max-width: 480px;
  width: 100%;
}

.container .card { max-width: 100%; }

h1, h2, h3 { margin: 0 0 0.5rem; }
h1 { font-size: 1.6rem; color: var(--c-primary); }
h2 { font-size: 1.25rem; }

p { margin: 0.5rem 0; }
.muted { color: var(--c-muted); }
.footnote { font-size: 0.85rem; margin-top: 1.5rem; }

.btn {
  display: inline-block;
  padding: 0.6rem 1.1rem;
  border-radius: var(--r);
  border: 1px solid transparent;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

.btn.primary {
  background: var(--c-primary);
  color: #fff;
}
.btn.primary:hover {
  background: var(--c-primary-hover);
  text-decoration: none;
}
.btn.primary:disabled {
  background: #9db5cc;
  cursor: not-allowed;
  opacity: 0.7;
}

.btn.ghost {
  background: transparent;
  color: var(--c-text);
  border-color: var(--c-border);
}
.btn.ghost:hover {
  background: var(--c-bg);
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.5rem;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}
.topbar .brand {
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--c-primary);
}
.topbar nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.badge {
  display: inline-block;
  background: var(--c-accent);
  color: #fff;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
}

/* ── Buttons small ── */
.btn.small { padding: 0.35rem 0.75rem; font-size: 0.85rem; }

/* ── Balance card ── */
.balance-card { margin-bottom: 1rem; }
.balance-row  { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.balance-label { font-size: 0.85rem; color: var(--c-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: .2rem; }
.balance-value { font-size: 2rem; font-weight: 700; color: var(--c-primary); }
.balance-value.balance-neg { color: #c0392b; }
.balance-sub   { font-size: 0.85rem; margin-top: .15rem; }

/* ── Card header row ── */
.card-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.card-header-row h2 { margin: 0; }

/* ── Leave row (history) ── */
.leave-row {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .6rem 0; border-bottom: 1px solid var(--c-border); flex-wrap: wrap;
}
.leave-row:last-child { border-bottom: none; }
.leave-info  { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.leave-meta  { display: flex; align-items: center; gap: .5rem; }
.leave-type  { font-size: 0.78rem; font-weight: 700; padding: 2px 8px; border-radius: 4px; }
.leave-type-AL { background: #dbeafe; color: #1e40af; }
.leave-type-CL { background: #dcfce7; color: #166534; }
.leave-type-SL { background: #fef9c3; color: #854d0e; }
.leave-days    { font-size: 0.82rem; font-weight: 600; color: var(--c-muted); white-space: nowrap; }

/* ── Test mode badge ── */
.badge-test {
  display: inline-block;
  background: #ef4444;
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .06em;
  padding: 2px 7px;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: .35rem;
  text-transform: uppercase;
}

/* ── Status badges ── */
.badge-status  { padding: 2px 8px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.badge-pending   { background: #fef3c7; color: #92400e; }
.badge-confirmed { background: #dcfce7; color: #166534; }
.badge-rejected  { background: #fee2e2; color: #991b1b; }
.badge-cancelled { background: #f3f4f6; color: #6b7280; }
.badge-travel    { background: #ede9fe; color: #5b21b6; font-size: 0.78rem; padding: 2px 8px; border-radius: 4px; }

/* ── Required star ── */
.req { color: #dc2626; font-weight: 700; margin-left: 2px; }

/* ── Form fields ── */
.field { margin-bottom: 1.1rem; }
.field-row { display: flex; gap: 1rem; }
.field-row .field { flex: 1; }
.field-label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: .35rem; }
.input {
  display: block; width: 100%; padding: .55rem .75rem;
  border: 1px solid var(--c-border); border-radius: 6px;
  font-size: 0.95rem; font-family: inherit; color: var(--c-text);
  background: var(--c-surface); transition: border-color .15s;
}
.input:focus { outline: none; border-color: var(--c-primary); }
textarea.input { resize: vertical; min-height: 80px; }

/* ── Radio card group ── */
.radio-group { display: flex; gap: .5rem; flex-wrap: wrap; }
.radio-card  {
  flex: 1; min-width: 80px;
  display: flex; flex-direction: column; align-items: center; gap: .15rem;
  padding: .65rem .5rem; border: 2px solid var(--c-border); border-radius: 8px;
  cursor: pointer; transition: border-color .15s; text-align: center;
}
.radio-card input[type=radio] { display: none; }
.radio-card:has(input:checked) { border-color: var(--c-primary); background: #eff6ff; }
.radio-title { font-weight: 700; font-size: 0.95rem; }
.radio-desc  { font-size: 0.78rem; color: var(--c-muted); }

/* ── Info / error boxes ── */
.info-box {
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 6px;
  padding: .65rem .85rem; font-size: 0.9rem; margin-bottom: 1rem;
}
.info-box-warn { background: #fff7ed; border-color: #fdba74; color: #9a3412; }
.error-box {
  background: #fee2e2; border: 1px solid #fca5a5; border-radius: 6px;
  padding: .65rem .85rem; font-size: 0.9rem; color: #991b1b; margin-bottom: 1rem;
}

/* ── Form actions ── */
.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1.5rem; }

/* ── Confirm queue ── */
.confirm-row {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .75rem 0; border-bottom: 1px solid var(--c-border); flex-wrap: wrap;
}
.confirm-row:last-child { border-bottom: none; }
.confirm-info    { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.confirm-actions { display: flex; gap: .5rem; flex-shrink: 0; margin-left: auto; }

/* ── Cert upload button (label acting as button) ── */
.cert-upload-btn { cursor: pointer; }
.cert-upload-btn:hover { background: var(--c-bg); }

/* ── Date + time selector row ── */
.date-time-row { display:flex; align-items:stretch; gap:.5rem; flex-wrap:nowrap; }
.date-time-row .input { flex:2; min-width:0; }
.date-time-row .radio-group { flex:2; min-width:0; flex-wrap:nowrap; }
.date-time-row .radio-card { flex:1; min-width:0; }
.portion-preview { font-size:.9rem; font-weight:600; color:var(--c-primary); min-height:1.4rem; }
.portion-preview.invalid { color:var(--c-danger); }

/* ── AL balance breakdown ── */
.al-breakdown { display:flex; flex-direction:column; gap:.2rem; }
.al-breakdown-row { display:flex; justify-content:space-between; align-items:baseline; gap:1rem; font-size:.85rem; }
.al-breakdown-val { font-weight:600; white-space:nowrap; }
.al-breakdown-val.pos { color:#166534; }
.al-breakdown-val.neg { color:#991b1b; }
.al-tip {
  position:relative;
  display:inline-flex; align-items:center; justify-content:center;
  width:15px; height:15px; border-radius:50%;
  background:var(--c-muted); color:#fff;
  font-size:.65rem; font-weight:700; line-height:1;
  cursor:pointer; vertical-align:middle; margin-left:3px;
  user-select:none;
}
.al-tip-popup {
  display:none;
  position:absolute; bottom:calc(100% + 7px); left:50%; transform:translateX(-50%);
  background:#1f4e78; color:#fff;
  padding:.4rem .65rem; border-radius:6px;
  font-size:.78rem; font-weight:400; white-space:nowrap;
  box-shadow:0 2px 8px rgba(0,0,0,.2);
  pointer-events:none; z-index:100;
}
.al-tip-popup::after {
  content:''; position:absolute; top:100%; left:50%; transform:translateX(-50%);
  border:5px solid transparent; border-top-color:#1f4e78;
}
.al-tip:hover .al-tip-popup,
.al-tip.open .al-tip-popup { display:block; }

/* ── Admin tabs (underline style) ── */
.admin-tabs-bar {
  display: flex;
  border-bottom: 2px solid var(--c-border);
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.admin-tab {
  padding: 9px 20px;
  border: none;
  background: none;
  font-size: .9rem;
  font-weight: 500;
  color: var(--c-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  border-radius: 4px 4px 0 0;
  transition: color .15s, border-color .15s;
  font-family: inherit;
  white-space: nowrap;
}
.admin-tab:hover { color: var(--c-text); }
.admin-tab.active-tab { color: var(--c-primary); border-bottom-color: var(--c-primary); font-weight: 600; }

/* ── Staff filter tabs ── */
.staff-tab { background: transparent; color: var(--c-muted); border-color: var(--c-border); }
.staff-tab:hover { background: var(--c-bg); color: var(--c-text); }
.staff-tab.active-tab { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }

/* ── Staff history accordion toggle ── */
.staff-toggle-btn {
  background: none; border: none; cursor: pointer;
  color: var(--c-muted); display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 4px; padding: 0;
  transition: background .1s, color .1s;
}
.staff-toggle-btn:hover { background: var(--c-bg); color: var(--c-text); }
.staff-toggle-btn svg { transition: transform .15s; }
.staff-toggle-btn.open svg { transform: rotate(90deg); }

/* ── Former staff badge ── */
.badge-former { display:inline-block; background:#f3f4f6; color:#6b7280; padding:1px 7px; border-radius:999px; font-size:.72rem; font-weight:500; }

/* ── Danger colour ── */
:root { --c-danger: #dc2626; }
.btn.btn-danger { background:#dc2626; color:#fff; border-color:#dc2626; }
.btn.btn-danger:hover { background:#b91c1c; }

/* ── Year group (All Leave Applications) ── */
.year-group { margin-bottom: .25rem; }
.year-group-hdr {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  padding: .5rem 0 .3rem; border-bottom: 2px solid var(--c-border);
  margin-top: 1.25rem;
}
.year-group:first-child .year-group-hdr { margin-top: 0; }
.year-group-label { font-weight: 700; font-size: 1rem; color: var(--c-primary); }
.year-group-label-other { font-size: .9rem; color: var(--c-muted); font-weight: 600; }
.year-group-summary { font-size: .82rem; color: var(--c-muted); }
.year-group-others { margin-top: 1.5rem; }
.year-group-footer {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .45rem 0 .2rem; font-size: .85rem;
  border-top: 1px solid var(--c-border); margin-top: .1rem;
}
.year-group-footer-sep { color: var(--c-border); margin: 0 .1rem; }
.leave-days-tag { font-size: .82rem; color: var(--c-muted); font-weight: 600; white-space: nowrap; }

/* ── Quota tooltip (click-only) ── */
.quota-tip {
  position: relative;
  cursor: pointer;
  display: inline-block;
  border-bottom: 1px dashed var(--c-muted);
}
.quota-tip-popup {
  display: none;
  position: fixed;
  background: #1f4e78;
  color: #fff;
  padding: .4rem .65rem;
  border-radius: 6px;
  font-size: .78rem;
  font-weight: 400;
  max-width: 320px;
  white-space: normal;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  pointer-events: none;
  z-index: 1000;
}
.quota-tip-popup::after {
  content: '';
  position: absolute;
  top: 100%;
  right: 8px;
  border: 5px solid transparent;
  border-top-color: #1f4e78;
}
.quota-tip.open .quota-tip-popup { display: block; }

/* ── Guide button ── */
.btn-guide {
  background: transparent;
  border: 1.5px solid var(--c-border);
  color: var(--c-muted);
  width: 28px; height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: border-color .15s, color .15s;
}
.btn-guide:hover { border-color: var(--c-primary); color: var(--c-primary); }

/* ── Guide modal ── */
.guide-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 1000;
  align-items: center; justify-content: center;
}
.guide-overlay.visible { display: flex; }
.guide-box {
  background: var(--c-surface);
  border-radius: 10px;
  width: clamp(320px, calc(100vw - 32px), 640px);
  max-height: 88vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,.15);
}
.guide-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}
.guide-title { font-size: 1rem; }
.guide-body {
  padding: 18px 22px 24px;
  overflow-y: auto;
  flex: 1;
  font-size: .9rem;
  line-height: 1.65;
}
.guide-lang-toggle { display: flex; gap: 3px; }
.guide-lang-btn {
  background: transparent;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--c-muted);
  font-family: inherit;
  transition: background .15s, color .15s;
}
.guide-lang-btn.active { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.guide-download-btn {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: .75rem; font-weight: 600; color: var(--c-primary);
  text-decoration: none; border: 1px solid var(--c-primary);
  border-radius: 4px; padding: 2px 8px; white-space: nowrap;
  transition: background .15s, color .15s;
}
.guide-download-btn:hover { background: var(--c-primary); color: #fff; text-decoration: none; }
.guide-close-btn {
  background: none; border: none;
  font-size: 22px; color: var(--c-muted);
  cursor: pointer; line-height: 1; padding: 0 2px;
}
.guide-close-btn:hover { color: var(--c-text); }
.guide-section {
  font-size: .92rem;
  font-weight: 700;
  color: var(--c-primary);
  margin: 1.2rem 0 .4rem;
  padding-bottom: .25rem;
  border-bottom: 1px solid #e5e7eb;
}
.guide-section:first-of-type { margin-top: .5rem; }
.guide-list {
  margin: 0 0 .5rem;
  padding-left: 1.3rem;
}
.guide-list li {
  margin-bottom: .35rem;
  font-size: .88rem;
}
@media (min-width: 768px) { .guide-box { width: clamp(320px, 70vw, 720px); } }

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
}
.modal-box {
  background: var(--c-surface); border-radius: var(--r);
  padding: 1.5rem 2rem; max-width: 400px; width: 90%;
  box-shadow: var(--shadow-md);
}
.modal-box h3 { margin: 0 0 .5rem; }

/* ── Feedback button ─────────────────────────────────────────────────────── */
.btn-feedback {
  background: transparent;
  border: 1.5px solid var(--c-border);
  color: var(--c-muted);
  width: 28px; height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  padding: 0;
  transition: border-color .15s, color .15s;
}
.btn-feedback:hover    { border-color: var(--c-accent); color: var(--c-accent); }
.btn-feedback:disabled { opacity: .5; cursor: wait; pointer-events: none; }

/* ── Feedback modal ──────────────────────────────────────────────────────── */
.fb-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1100;
  align-items: center; justify-content: center;
  padding: 1rem;
}
.fb-overlay.visible { display: flex; }
.fb-box {
  background: var(--c-surface);
  border-radius: 10px;
  width: clamp(320px, calc(100vw - 32px), 560px);
  max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.fb-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}
.fb-title { font-size: 1rem; font-weight: 600; }
.fb-body  { padding: 18px 20px 20px; overflow-y: auto; flex: 1; }
.fb-type-row { display: flex; gap: .5rem; }
.fb-type-btn {
  flex: 1; padding: .55rem .75rem;
  border: 2px solid var(--c-border); border-radius: 8px;
  background: transparent; font-size: .88rem; font-weight: 500;
  cursor: pointer; font-family: inherit; color: var(--c-muted);
  display: flex; align-items: center; justify-content: center; gap: .35rem;
  transition: border-color .15s, background .15s, color .15s;
}
.fb-type-btn.selected            { border-color: var(--c-primary); background: #eff6ff; color: var(--c-primary); }
.fb-type-btn:hover:not(.selected) { border-color: #9ca3af; color: var(--c-text); }
.fb-ss-wrap {
  border: 1px solid var(--c-border); border-radius: 6px; overflow: hidden;
  min-height: 56px; max-height: 180px;
  display: flex; align-items: center; justify-content: center;
  background: var(--c-bg); cursor: zoom-in;
}
.fb-ss-wrap img { max-width: 100%; max-height: 180px; display: block; }
.fb-ss-ph { color: var(--c-muted); font-size: .85rem; padding: 1.2rem; text-align: center; }
