:root {
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --sidebar: #0f172a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 12px rgba(15, 23, 42, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

/* ===== Đăng nhập ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a, #2563eb 60%, #3b82f6);
}
.login-card {
  background: #fff;
  padding: 36px 32px;
  border-radius: 16px;
  width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
  text-align: center;
}
.login-logo { font-size: 44px; }
.login-card h1 { margin: 8px 0 4px; font-size: 22px; }
.login-sub { color: var(--muted); margin: 0 0 22px; }
.login-card label { display: block; text-align: left; font-weight: 600; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.login-card input {
  width: 100%; padding: 10px 12px; margin-top: 6px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.login-card input:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* ===== Layout ===== */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; background: var(--sidebar); color: #cbd5e1;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { font-size: 19px; font-weight: 700; color: #fff; padding: 20px 18px; border-bottom: 1px solid #1e293b; }
#nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.nav-group {
  padding: 14px 18px 4px; font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px; color: #64748b;
}
#nav .nav-group:first-child { padding-top: 4px; }
#nav a {
  display: block; padding: 11px 18px; color: #cbd5e1; text-decoration: none;
  border-left: 3px solid transparent; transition: background .15s;
}
#nav a:hover { background: #1e293b; color: #fff; }
#nav a.active { background: #1e293b; color: #fff; border-left-color: var(--primary); }
.sidebar-footer { padding: 14px 18px; border-top: 1px solid #1e293b; font-size: 13px; }
#current-user { margin-bottom: 8px; }
#current-user .role-tag { color: #94a3b8; font-size: 12px; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 14px 24px; position: sticky; top: 0; z-index: 10;
}
.topbar h2 { margin: 0; font-size: 18px; }
.page { padding: 22px 24px; flex: 1; }

/* ===== Thành phần chung ===== */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px;
}
.card h3 { margin: 0 0 14px; font-size: 15px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-2 { grid-template-columns: 1fr 1fr; }
.stat-card { text-align: left; }
.stat-card .label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: 700; }
.stat-card .value.green { color: var(--green); }
.stat-card .value.red { color: var(--red); }
.stat-card .value.amber { color: var(--amber); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13.5px; font-weight: 600;
  transition: all .15s;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); background: #fef2f2; color: var(--red); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-ghost { background: transparent; border-color: #334155; color: #cbd5e1; }
.btn-ghost:hover { color: #fff; border-color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; justify-content: center; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
input[type="text"], input[type="number"], input[type="date"], input[type="time"],
input[type="month"], input[type="password"], select, textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13.5px; background: #fff; color: var(--text); font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
.form-error { color: var(--red); font-size: 13px; margin: 8px 0; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; padding: 10px 10px; color: var(--muted); font-weight: 600;
  border-bottom: 2px solid var(--border); white-space: nowrap; background: #f8fafc;
}
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:hover td { background: #f8fafc; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-wrap { overflow-x: auto; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-green { background: #dcfce7; color: #15803d; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-gray { background: #e2e8f0; color: #475569; }
.badge-purple { background: #ede9fe; color: #6d28d9; }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-start; justify-content: center;
  z-index: 100; padding: 40px 16px; overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 14px; width: 560px; max-width: 100%;
  box-shadow: 0 24px 60px rgba(0,0,0,.25); animation: pop .18s ease;
}
.modal.wide { width: 900px; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal header h3 { margin: 0; font-size: 16px; }
.modal .close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.modal .modal-body { padding: 20px; }
.modal footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; }

/* ===== Toast ===== */
#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: 13.5px; animation: pop .18s ease; max-width: 360px;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

/* ===== Chấm công: bảng lưới ===== */
.att-grid { overflow-x: auto; }
.att-grid table { border-collapse: collapse; font-size: 12px; }
.att-grid th, .att-grid td { border: 1px solid var(--border); padding: 0; }
.att-grid thead th { position: sticky; top: 0; background: #f8fafc; padding: 6px 4px; text-align: center; font-size: 11px; min-width: 34px; }
.att-grid .emp-cell { position: sticky; left: 0; background: #fff; padding: 6px 10px; min-width: 180px; z-index: 2; border-right: 2px solid var(--border); }
.att-grid thead .emp-cell { z-index: 3; }
.att-grid td.day { text-align: center; min-width: 34px; height: 30px; cursor: pointer; font-weight: 700; }
.att-grid td.day:hover { outline: 2px solid var(--primary); outline-offset: -2px; }
.cell-P { background: #dcfce7; color: #15803d; }   /* Đi làm */
.cell-L { background: #fef3c7; color: #b45309; }   /* Đi muộn */
.cell-A { background: #fee2e2; color: #b91c1c; }   /* Vắng */
.cell-E { background: #dbeafe; color: #1d4ed8; }   /* Nghỉ phép */
.cell-H { background: #f3e8ff; color: #7e22ce; }   /* Lễ */
.cell-R { background: #cffafe; color: #0e7490; }   /* Remote */
.cell-WE { background: #f1f5f9; color: #cbd5e1; }  /* Cuối tuần */
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin: 10px 0; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; border: 1px solid var(--border); }

/* ===== Dashboard ===== */
.chart-bars { display: flex; align-items: flex-end; gap: 14px; height: 180px; padding: 8px 4px 0; }
.chart-bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.chart-bar .bar {
  width: 100%; max-width: 52px; background: linear-gradient(180deg, #3b82f6, #2563eb);
  border-radius: 6px 6px 0 0; min-height: 3px; transition: height .3s;
}
.chart-bar .bar-label { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.25; word-break: break-word; }
.chart-bar .bar-value { font-size: 12px; font-weight: 700; }
.list-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); gap: 10px; }
.list-row:last-child { border-bottom: none; }
.list-row .sub { color: var(--muted); font-size: 12.5px; }

.payslip-detail dt { color: var(--muted); font-size: 12.5px; margin-top: 10px; }
.payslip-detail dd { margin: 2px 0 0; font-weight: 600; }
.payslip-detail .divider { border-top: 1px solid var(--border); margin-top: 14px; }
.payslip-total { font-size: 20px; color: var(--green); }

@media (max-width: 860px) {
  .sidebar { width: 64px; }
  .sidebar .brand { text-align: center; padding: 16px 4px; font-size: 15px; }
  .nav-group { display: none; }
  #nav a { padding: 12px 8px; text-align: center; font-size: 16px; }
  #nav a .label, .sidebar-footer #current-user { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
