/* QC Anh Đào — Bespoke Design System */
:root {
  --bg: #F7F7F5;
  --surface: #FFFFFF;
  --surface-alt: #F1F5F4;
  --primary: #0F4C5C;
  --primary-light: #17697E;
  --primary-tint: rgba(15, 76, 92, 0.08);
  --accent: #E36414;
  --accent-tint: rgba(227, 100, 20, 0.11);
  --text: #1E293B;
  --muted: #64748B;
  --border: #E2E8F0;
  --ok: #0F766E;
  --ok-bg: #ECFDF5;
  --warn: #B45309;
  --warn-bg: #FEF3C7;
  --err: #B91C1C;
  --err-bg: #FEF2F2;
  --radius: 14px;
  --shadow: 0 4px 16px rgba(15, 76, 92, 0.06);
  --sidebar-w: 248px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

/* Auth Screen */
.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at top right, rgba(227, 100, 20, 0.12), transparent 45%),
              radial-gradient(circle at bottom left, rgba(15, 76, 92, 0.14), transparent 50%),
              var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 20px 45px rgba(15, 76, 92, 0.1);
}
.brand-lockup { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.brand-badge {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; flex-shrink: 0;
  font-weight: 800; letter-spacing: 0.5px;
}
.brand-title { font-size: 19px; font-weight: 800; color: var(--primary); margin: 0; }
.brand-sub { font-size: 12.5px; color: var(--muted); margin: 2px 0 0; }

/* App Shell */
.app-shell { display: flex; min-height: 100dvh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: #E2E8F0;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  z-index: 20;
}
.sidebar .brand-title { color: #FFFFFF; font-size: 17px; }
.sidebar .brand-sub { color: #CBD5E1; }
.sidebar .brand-badge { background: var(--accent); }

.nav-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; flex: 1; overflow-y: auto; }
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; border: 0; background: transparent; color: #CBD5E1;
  padding: 11px 12px; border-radius: 10px; cursor: pointer;
  font-weight: 600; font-size: 14px; text-align: left;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-btn.active { background: #fff; color: var(--primary); font-weight: 700; }

.sidebar-foot {
  border-top: 1px solid rgba(255,255,255,.14);
  padding-top: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.user-pill { font-size: 13px; color: #fff; }
.user-pill small { display: block; color: #CBD5E1; font-size: 11.5px; }

.main-area {
  margin-inline-start: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky; top: 0; z-index: 15;
  background: rgba(247, 247, 245, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 12px 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar-title { font-size: 18px; font-weight: 800; color: var(--primary); margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.content { padding: 20px 22px 84px; max-width: 1360px; width: 100%; margin: 0 auto; }

/* Bottom Nav for Mobile */
.bottom-nav { display: none; }
.mobile-only-pw, .mobile-only-out { display: none; }

@media (max-width: 900px) {
  .mobile-only-pw, .mobile-only-out { display: inline-flex; }
  .sidebar { display: none; }
  .main-area { margin-inline-start: 0; }
  .topbar { padding: 10px 14px; }
  .content { padding: 14px 14px 92px; }
  .bottom-nav {
    position: fixed; inset-block-end: 0; inset-inline: 0; z-index: 25;
    background: var(--surface); border-top: 1px solid var(--border);
    display: flex; justify-content: space-around; align-items: stretch;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(0,0,0,.05);
  }
  .bottom-nav-btn {
    flex: 1; border: 0; background: transparent; color: var(--muted);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; font-size: 11px; font-weight: 600; padding: 6px 2px; border-radius: 8px; cursor: pointer;
    min-height: 44px;
  }
  .bottom-nav-btn.active { color: var(--primary); background: var(--primary-tint); }
  .bottom-nav-btn span.ico { font-size: 18px; line-height: 1; }
}

/* Cards & Grids */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.kpi-val { font-size: 22px; font-weight: 800; color: var(--text); letter-spacing: -0.3px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi-card.primary { border-left: 4px solid var(--primary); }
.kpi-card.accent { border-left: 4px solid var(--accent); }
.kpi-card.ok { border-left: 4px solid var(--ok); }
.kpi-card.warn { border-left: 4px solid var(--warn); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-bottom: 18px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-title { font-size: 16px; font-weight: 700; margin: 0; color: var(--primary); }

/* Tabs */
.subtabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; background: var(--surface); padding: 6px; border-radius: 12px; border: 1px solid var(--border); width: fit-content; max-width: 100%; }
.subtab-btn {
  border: 0; background: transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; font-weight: 600; font-size: 13.5px; cursor: pointer;
}
.subtab-btn.active { background: var(--primary); color: #fff; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 10px;
  padding: 9px 14px; min-height: 40px; font-size: 13.5px; font-weight: 700;
  cursor: pointer; transition: filter .15s, background .15s;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { filter: brightness(1.06); }
.btn-outline { background: var(--surface); border-color: #CBD5E1; color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--surface-alt); }
.btn-danger { background: var(--err); color: #fff; }
.btn-sm { min-height: 32px; padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-lg { min-height: 52px; padding: 14px 20px; font-size: 16px; border-radius: 14px; width: 100%; }

/* Pills & Badges */
.pill { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-err { background: var(--err-bg); color: var(--err); }
.pill-info { background: var(--primary-tint); color: var(--primary); }
.pill-accent { background: var(--accent-tint); color: var(--accent); }
.pill-muted { background: #F1F5F9; color: var(--muted); }

/* Forms & :user-invalid validation */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.hint { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 11px; min-height: 40px;
  border: 1px solid #CBD5E1; border-radius: 9px; background: #fff; font-size: 14px;
}
textarea.input { min-height: 76px; resize: vertical; }
.input:focus { outline: 2px solid rgba(15, 76, 92, 0.22); border-color: var(--primary); }
.error-msg { display: none; color: var(--err); font-size: 12.5px; margin-top: 4px; }
:is(.input:user-invalid, .input.user-invalid-fallback) { border-color: var(--err); background: #FEF2F2; }
:is(.input:user-invalid, .input.user-invalid-fallback) + .error-msg { display: block; }
.input:user-valid { border-color: #16A34A; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .input { width: auto; min-width: 180px; flex: 1 1 200px; }

/* Responsive Semantic Tables (@container stacked cards on small screens) */
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(620px, 72vh);
  container-type: inline-size;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
table.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
table.data-table thead { position: sticky; inset-block-start: 0; z-index: 2; }
table.data-table th {
  background: #F8FAFC; color: var(--primary); font-weight: 700; text-align: left;
  padding: 11px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data-table td { padding: 10px 12px; border-bottom: 1px solid #F1F5F9; vertical-align: middle; }
table.data-table tbody tr:hover { background: #FAFBFA; }
table.data-table tbody th {
  position: sticky; inset-inline-start: 0; background: var(--surface);
  font-weight: 700; color: var(--text); text-align: left; padding: 10px 12px;
  border-bottom: 1px solid #F1F5F9; z-index: 1;
}
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data-table th.num { text-align: right; }

@container (width < 640px) {
  .table-wrapper { max-block-size: none; border: 0; background: transparent; }
  table.data-table, table.data-table thead, table.data-table tbody, table.data-table tr, table.data-table th, table.data-table td { display: block; }
  table.data-table thead { display: none; }
  table.data-table tbody tr {
    margin-block-end: 12px; border: 1px solid var(--border); border-radius: 12px;
    background: var(--surface); overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,.03);
  }
  table.data-table tbody th {
    position: sticky; inset-block-start: 0; z-index: 2;
    background: var(--surface-alt); border-bottom: 1px solid var(--border);
  }
  table.data-table td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    text-align: right; padding: 8px 12px;
  }
  table.data-table td::before {
    content: attr(data-label);
    font-weight: 600; color: var(--muted); text-align: left; flex-shrink: 0;
  }
}

/* Native <dialog> Modals */
dialog.q-dialog {
  width: min(680px, calc(100vw - 24px));
  max-height: calc(100dvh - 28px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(15, 76, 92, 0.22);
}
dialog.q-dialog[open] { display: flex; flex-direction: column; }
dialog.q-dialog:modal { overscroll-behavior: contain; }
dialog.q-dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  overflow: hidden;
  overscroll-behavior: contain;
}
.dialog-head {
  padding: 15px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.dialog-head h1 { font-size: 17px; margin: 0; color: var(--primary); }
.dialog-body { padding: 18px; overflow-y: auto; flex: 1; }
.dialog-foot {
  padding: 12px 18px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
}

/* Toast Notification */
.toast-box {
  position: fixed; inset-block-end: 24px; inset-inline-end: 24px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  background: #0F172A; color: #fff; padding: 11px 16px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; box-shadow: 0 10px 25px rgba(0,0,0,.2);
  max-width: 340px;
}
.toast.ok { background: #065F46; }
.toast.err { background: #991B1B; }

/* Attendance Check-in Hero */
.checkin-hero {
  background: linear-gradient(135deg, var(--primary) 0%, #156175 100%);
  color: #fff; border-radius: 18px; padding: 22px; margin-bottom: 16px;
}
.checkin-hero h2 { margin: 0 0 4px; font-size: 20px; }
.checkin-clock { font-size: 30px; font-weight: 800; letter-spacing: 0.5px; margin: 8px 0 14px; font-variant-numeric: tabular-nums; }

.photo-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); cursor: pointer; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.gallery-item { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; }
.gallery-item img { width: 100%; height: 100px; object-fit: cover; display: block; cursor: pointer; }
.gallery-item span { display: block; padding: 6px 8px; font-size: 11.5px; color: var(--muted); }

/* Print Stylesheet for Payslips & Debt Statements */
@media print {
  .sidebar, .topbar, .bottom-nav, .no-print { display: none !important; }
  .main-area { margin: 0 !important; }
  .content { padding: 0 !important; }
  body { background: #fff; }
  .card, .table-wrapper { box-shadow: none; border-color: #cbd5e1; }
}
