:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0f172a;
  --primary-fg: #f8fafc;
  --accent: #2563eb;
  --success: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 0 96px;
  min-height: 100vh;
  background: var(--bg);
}

.appbar {
  position: sticky; top: 0;
  background: var(--primary); color: var(--primary-fg);
  padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
  z-index: 10;
}
.appbar h1 { margin: 0; font-size: 16px; font-weight: 600; flex: 1; }
.appbar button.icon {
  background: transparent; border: 0; color: var(--primary-fg); font-size: 20px;
  padding: 4px 8px; cursor: pointer;
}

.screen { padding: 16px; }
.screen h2 { margin: 0 0 12px; font-size: 18px; }
.screen .subtitle { color: var(--muted); margin: 0 0 16px; font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 4px; font-size: 15px; word-break: break-word; }
.card .meta { color: var(--muted); font-size: 13px; }

.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.row.between .tag { flex-shrink: 0; }
.row.between h3 { flex: 1; min-width: 0; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: 2px solid var(--accent); outline-offset: 0;
  border-color: var(--accent);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 11px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
}
.btn:hover { background: #f1f5f9; }
.btn.primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn.primary:hover { background: #1e293b; }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.success { background: var(--success); color: #fff; border-color: var(--success); }
.btn.block { width: 100%; }
.btn.small { padding: 6px 10px; font-size: 13px; font-weight: 500; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.tag {
  display: inline-flex; align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: #e2e8f0; color: #334155;
}
.tag.pending { background: #fef3c7; color: #92400e; }
.tag.level1_approved { background: #dbeafe; color: #1e40af; }
.tag.approved { background: #dcfce7; color: #166534; }
.tag.rejected { background: #fee2e2; color: #991b1b; }
.tag.cancelled { background: #f1f5f9; color: #475569; }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 10;
  max-width: 640px; margin: 0 auto;
}
.bottom-nav a {
  flex: 1;
  text-align: center;
  padding: 10px 4px 12px;
  text-decoration: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  border-top: 2px solid transparent;
}
.bottom-nav a.active { color: var(--primary); border-top-color: var(--primary); }
.bottom-nav a .ic { display: block; font-size: 22px; line-height: 1; margin-bottom: 2px; }

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

.toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%);
  background: var(--primary); color: var(--primary-fg);
  padding: 10px 16px; border-radius: 999px;
  font-size: 14px;
  z-index: 100;
  max-width: 90%;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid #e2e8f0;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 28px 22px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(15,23,42,.08);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; text-align: center; }
.login-card .tagline { text-align: center; color: var(--muted); margin: 0 0 20px; font-size: 14px; }

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.detail-row:last-child { border-bottom: 0; }
.detail-row .k { color: var(--muted); font-size: 13px; flex-shrink: 0; }
.detail-row .v {
  font-size: 14px;
  text-align: right;
  word-break: break-word;
  min-width: 0;
}

.balance-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #fff;
  border-color: transparent;
}
.balance-card .meta { color: #cbd5e1; }
.balance-card .balance-num { font-size: 22px; font-weight: 700; }

.balance-warn {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
}
.balance-warn.ok { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.balance-warn.err { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 18px 18px 24px;
  max-width: 640px; width: 100%;
}
.modal h3 { margin: 0 0 12px; }

@media (min-width: 720px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 16px; max-width: 480px; margin: 24px; }
}

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tabs a {
  padding: 10px 12px;
  text-decoration: none;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-size: 14px; font-weight: 500;
}
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

.list-divider { height: 8px; }

.kbd {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: #f1f5f9;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.report-scroll {
  overflow-x: auto;
  margin: 0 -16px;
  padding: 0 16px;
}
.report-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  min-width: 560px;
}
.report-table th,
.report-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.report-table th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--muted);
  position: sticky; top: 0;
}
.report-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.report-table td.num.warn { color: var(--danger); font-weight: 600; }

/* ── Calendar (Bảng chấm công của tôi) ── */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.month-nav strong { font-size: 16px; }

.cal-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}
.cal-head .we { color: var(--danger); }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-cell {
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  font-size: 13px;
  cursor: default;
  background: #fff;
}
.cal-cell.blank { border: 0; background: transparent; }
.cal-cell .num { font-weight: 600; }
.cal-cell .ic { font-size: 11px; line-height: 1; }
.cal-cell.weekend { background: #f8fafc; color: var(--muted); }
.cal-cell.future { background: #fff; color: #cbd5e1; }
.cal-cell.complete { background: #dcfce7; border-color: #86efac; color: #166534; }
.cal-cell.incomplete { background: #fef3c7; border-color: #fcd34d; color: #92400e; cursor: pointer; }
.cal-cell.missing { background: #fee2e2; border-color: #fca5a5; color: #991b1b; cursor: pointer; }
.cal-cell.leave { background: #dbeafe; border-color: #93c5fd; color: #1e40af; cursor: pointer; }
.cal-cell.has-adj-pending::after {
  content: '';
  position: absolute;
  top: 4px; right: 4px;
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
}

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  font-size: 13px;
}
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cal-legend .dot {
  width: 12px; height: 12px; border-radius: 3px;
  border: 1px solid var(--border);
  display: inline-block;
}
.cal-legend .dot.complete { background: #dcfce7; border-color: #86efac; }
.cal-legend .dot.incomplete { background: #fef3c7; border-color: #fcd34d; }
.cal-legend .dot.missing { background: #fee2e2; border-color: #fca5a5; }
.cal-legend .dot.leave { background: #dbeafe; border-color: #93c5fd; }
.cal-legend .dot.weekend { background: #f8fafc; }
.cal-legend .dot.has-adj-pending { background: var(--accent); border-color: var(--accent); border-radius: 50%; width: 10px; height: 10px; }
