:root {
  --navy: #17407a;
  --navy-dark: #123468;
  --blue: #2e6fc6;
  --blue-btn: #2b6bc4;
  --blue-soft: #eaf1fb;
  --bg: #f4f7fc;
  --card: #ffffff;
  --line: #e1e8f3;
  --text: #15294b;
  --muted: #5b6b86;
  --red: #c0392b;
  --red-soft: #fbdcd9;
  --green: #2f8a4e;
  --green-soft: #dff3e6;
  --amber: #b7791f;
  --amber-soft: #fdf0cf;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue-btn); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #d9e6f8 0%, #f1f6fd 100%);
}
.login-card {
  width: 100%; max-width: 380px;
  background: #fff; border: 1px solid var(--line);
  border-radius: 18px; padding: 32px 32px 36px;
  text-align: center;
}
.login-logo {
  width: 96px; height: 96px; margin: 0 auto 18px;
  border-radius: 50%; background: var(--navy); color: #fff;
  font-weight: 700; font-size: 24px;
  display: flex; align-items: center; justify-content: center;
}
.login-card h1 { margin: 0 0 6px; font-size: 22px; color: var(--navy); line-height: 1.3; }
.login-card .sub { margin: 0 0 22px; color: var(--muted); font-size: 14.5px; line-height: 1.4; }
.login-card input {
  width: 100%; margin-bottom: 14px; padding: 13px 12px;
  border: 1px solid transparent; border-radius: 8px;
  background: #eaf0fb; font: inherit; font-size: 15px; color: #000;
}
.login-card input:focus { outline: none; border-color: #111; }
.login-card .btn { width: 100%; padding: 13px; font-size: 16px; }
.login-card .forgot { margin: 18px 0 0; color: var(--muted); font-size: 14.5px; line-height: 1.4; }
.form-error { color: var(--red); font-size: 14px; margin: -4px 0 12px; text-align: left; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100%; }
.sidebar {
  width: 224px; flex: 0 0 224px;
  background: var(--navy);
  color: #fff;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 0 24px; height: 64px; display: flex; align-items: center; font-size: 24px; font-weight: 700; letter-spacing: .2px; }
.nav { display: flex; flex-direction: column; flex: 1; }
.nav a, .nav button.logout {
  display: block; width: 100%; text-align: left;
  padding: 0 24px; height: 45.5px; line-height: 45.5px;
  color: #fff; text-decoration: none; background: none; border: 0;
  font: inherit; font-size: 16px; cursor: pointer;
  border-left: 4px solid transparent;
  padding-left: 24px;
}
.nav a:hover, .nav button.logout:hover { background: rgba(255, 255, 255, .08); }
.nav a.active { background: var(--blue); border-left-color: #fff; }
.nav .spacer { flex: 1; }
.nav .logout { margin-bottom: 16px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--blue); color: #fff;
  height: 62px; padding: 0 24px;
  display: flex; align-items: center; gap: 12px;
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 700; }
.topbar .back { color: #fff; text-decoration: none; font-size: 20px; margin-right: -2px; }
.topbar .top-action {
  margin-left: auto; color: #fff; background: none; border: 0;
  font: inherit; font-size: 16px; cursor: pointer; text-decoration: none;
}
.topbar .top-action.plus { font-size: 24px; line-height: 1; }
.content { padding: 24px; max-width: 1000px; width: 100%; }
.content > h2.welcome { margin: 0 0 12px; font-size: 18px; }
.content .overview { margin: 0 0 20px; color: var(--muted); font-size: 17px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block; border: 1px solid transparent; cursor: pointer;
  background: var(--blue-btn); color: #fff;
  font: inherit; font-size: 15px; text-decoration: none;
  padding: 11px 18px; border-radius: 8px; white-space: nowrap;
}
.btn:hover { background: #2460b3; }
.btn.light { background: var(--blue-soft); color: var(--blue-btn); border-color: #dbe7f8; }
.btn.light:hover { background: #dde9fa; }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger:hover { background: #a93226; }
.btn.small { padding: 7px 13px; font-size: 14px; border-radius: 6px; }
.btn[disabled] { opacity: .6; cursor: default; }

/* ---------- Cards / tables ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.card.pad { padding: 18px; }
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th {
  text-align: left; background: var(--blue-soft); color: var(--navy);
  font-weight: 600; padding: 14px; white-space: nowrap;
}
td { padding: 15px 14px; border-top: 1px solid #e8eef7; vertical-align: middle; }
tr:first-child td { border-top: 0; }
td.actions { white-space: nowrap; }
td.actions .btn + .btn { margin-left: 4px; }
.empty { text-align: center; color: var(--muted); padding: 28px 14px !important; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 34px 0 14px; }
.section-head.first { margin-top: 0; }
.section-head h3 { margin: 0; font-size: 18px; }
.section-head .btns { display: flex; gap: 10px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 30px; }
.stat { display: flex; align-items: center; gap: 14px; padding: 18px 16px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.stat .dot {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px;
}
.stat .num { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: 15px; }
.dot.blue { background: #e3edfb; color: var(--blue-btn); }
.dot.green { background: var(--green-soft); color: var(--green); }
.dot.red { background: var(--red-soft); color: var(--red); }
.dot.amber { background: var(--amber-soft); color: var(--amber); }

.badge { display: inline-block; padding: 5px 11px; border-radius: 6px; font-size: 13px; font-weight: 700; }
.badge.absent { background: var(--red-soft); color: var(--red); }
.badge.present { background: var(--green-soft); color: var(--green); }
.badge.late { background: var(--amber-soft); color: var(--amber); }
.badge.sent { background: var(--green-soft); color: var(--green); }
.badge.saved { background: #e3edfb; color: var(--blue-btn); }
.badge.failed { background: var(--red-soft); color: var(--red); }

/* ---------- Toolbars / forms ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.toolbar .grow { flex: 1; min-width: 180px; }
.toolbar label { font-weight: 600; font-size: 15px; }
.input, select.input {
  width: 100%; font: inherit; font-size: 15px; color: var(--text);
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 11px 14px; height: 44px;
}
.input::placeholder { color: #7b8aa3; }
.input.date { width: auto; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: 14.5px; margin-bottom: 7px; }
.field .hint { color: var(--muted); font-size: 13px; margin-top: 5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.note { color: var(--muted); font-size: 15px; margin: 14px 0 0; }

/* ---------- Detail pages ---------- */
.profile { display: flex; gap: 16px; align-items: center; margin-bottom: 20px; }
.avatar {
  width: 72px; height: 72px; border-radius: 50%; background: var(--blue);
  color: #fff; font-weight: 700; font-size: 26px;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.profile h2 { margin: 0 0 4px; font-size: 22px; }
.profile p { margin: 0; color: var(--muted); font-size: 16px; line-height: 1.5; }
.tabs { display: flex; gap: 22px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs a {
  padding: 8px 2px 11px; color: var(--muted); text-decoration: none; font-size: 16px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a.active { color: var(--blue-btn); font-weight: 700; border-bottom-color: var(--blue-btn); }
.kv { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.kv .row { display: flex; padding: 12px 14px; border-top: 1px solid #e8eef7; min-height: 42px; align-items: center; }
.kv .row:first-child { border-top: 0; }
.kv .k { width: 200px; color: var(--muted); flex: none; }
.kv .v { flex: 1; }
.qr-card { text-align: center; padding: 14px 14px 22px; }
.qr-box { display: inline-block; padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.qr-box canvas { width: 220px; height: 220px; display: block; image-rendering: pixelated; }
.qr-card .nm { margin: 18px 0 0; font-weight: 700; }
.qr-card .id { margin: 4px 0 16px; }
.qr-card .btn + .btn { margin-left: 2px; }
.range-summary { margin: 16px 0; color: var(--muted); }

/* ---------- SMS ---------- */
.alert { border-radius: 8px; padding: 14px 14px; margin-bottom: 14px; font-size: 15.5px; }
.alert.green { background: #dff3e6; color: #26774a; }
.alert.blue { background: #e3edfb; color: #1f5199; }
.sms-item { padding: 14px 16px; border-top: 1px solid #e8eef7; }
.sms-item:first-child { border-top: 0; }
.sms-item .top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.sms-item .to { font-weight: 700; }
.sms-item .when { color: var(--muted); font-size: 14px; margin-left: auto; }
.sms-item .msg { margin: 0; line-height: 1.5; }
.sms-item .err { color: var(--red); font-size: 13.5px; margin: 6px 0 0; }

/* ---------- Settings ---------- */
.settings-col { max-width: 520px; }
.settings-col .card { padding: 16px; margin-bottom: 18px; }
.settings-col h3 { margin: 0 0 16px; font-size: 18px; }
.user-line { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid #e8eef7; font-size: 15px; }
.user-line:first-of-type { border-top: 0; }
.user-line .who { flex: 1; min-width: 0; }
.user-line .who small { display: block; color: var(--muted); }

/* ---------- Scan ---------- */
.scan-wrap { max-width: 460px; margin: 0 auto; }
.cam {
  position: relative; width: 100%; aspect-ratio: 4 / 3; background: #1b1b1b;
  border-radius: 10px; overflow: hidden;
}
.cam video { width: 100%; height: 100%; object-fit: cover; display: block; transform: scaleX(-1); }
.cam .frame { position: absolute; left: 50%; top: 50%; width: 54%; aspect-ratio: 1; transform: translate(-50%, -50%); background: rgba(255, 255, 255, .12); }
.cam .frame i { position: absolute; width: 18%; height: 18%; border: 0 solid #fff; }
.cam .frame i:nth-child(1) { left: 0; top: 0; border-width: 3px 0 0 3px; }
.cam .frame i:nth-child(2) { right: 0; top: 0; border-width: 3px 3px 0 0; }
.cam .frame i:nth-child(3) { left: 0; bottom: 0; border-width: 0 0 3px 3px; }
.cam .frame i:nth-child(4) { right: 0; bottom: 0; border-width: 0 3px 3px 0; }
.cam .cam-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px; color: #fff; font-size: 15px; background: #2a2f3a; }
.scan-hint { text-align: center; color: var(--muted); margin: 18px 0; }
.scan-result { border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; font-size: 15.5px; line-height: 1.45; }
.scan-result.ok { background: var(--green-soft); color: #1f6b3c; }
.scan-result.warn { background: var(--amber-soft); color: #8a5a10; }
.scan-result.err { background: var(--red-soft); color: #9c2d22; }
.scan-result b { display: block; font-size: 16.5px; }
.manual { padding: 16px; margin-bottom: 18px; }
.manual h4 { margin: 0 0 12px; font-size: 17px; }
.manual .line { display: flex; gap: 10px; }
.center { text-align: center; }

/* ---------- Modal / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 30, 60, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 480px; max-height: 92vh; overflow: auto; padding: 22px; }
.modal h3 { margin: 0 0 16px; font-size: 19px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal p { margin: 0; line-height: 1.5; }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #14284a; color: #fff; padding: 12px 20px; border-radius: 8px;
  font-size: 15px; z-index: 60; max-width: 90vw;
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; flex-basis: auto; position: static; }
  .brand { height: 52px; }
  .nav { flex-direction: row; flex-wrap: wrap; padding-bottom: 8px; }
  .nav a, .nav button.logout { width: auto; height: 40px; line-height: 40px; padding: 0 14px; border-left: 0; border-radius: 6px; }
  .nav .spacer { display: none; }
  .nav .logout { margin: 0; }
  .topbar { position: static; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .field-row { grid-template-columns: 1fr; }
  .kv .k { width: 130px; }
}

@media print {
  .sidebar, .topbar, .toast { display: none !important; }
}
