/* Ratan Attendance: a ruled attendance register, in ink blue. */

:root {
  --paper: #F6F8FB;
  --sheet: #FFFFFF;
  --ink: #1B2438;
  --ink-2: #4A5570;
  --ink-3: #7A879F;
  --rule: #DCE4F0;
  --rule-strong: #B9C7DD;
  --accent: #2448A8;
  --accent-ink: #FFFFFF;
  --accent-soft: #E7EDFB;
  --margin: #D2564C;

  --present: #23744A;
  --present-soft: #E1F1E7;
  --half: #9A6210;
  --half-soft: #FAEED6;
  --absent: #B3372F;
  --absent-soft: #FBE6E3;
  --off: #7A879F;
  --off-soft: #EDF1F6;

  --radius-s: 6px;
  --radius-m: 10px;
  --font: "Avenir Next", Avenir, "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --shadow-pop: 0 12px 40px rgba(27, 36, 56, 0.18);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0F1726;
    --sheet: #162036;
    --ink: #E6EBF5;
    --ink-2: #AEB9CF;
    --ink-3: #7987A3;
    --rule: #26314A;
    --rule-strong: #36435F;
    --accent: #85A3F2;
    --accent-ink: #0F1726;
    --accent-soft: #1E2B4C;
    --margin: #F08A80;
    --present: #63C792;
    --present-soft: #163223;
    --half: #E3AA4E;
    --half-soft: #382A12;
    --absent: #F27D73;
    --absent-soft: #3B1C1B;
    --off: #7987A3;
    --off-soft: #1D2639;
    --shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.boot { padding: 48px 16px; color: var(--ink-3); text-align: center; }

/* ------------------------------------------------------------- header */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; white-space: nowrap; color: var(--ink); text-decoration: none; }
.brand img { width: 26px; height: 26px; }
.brand span { color: var(--ink-3); font-weight: 500; }

.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 7px 12px;
  border-radius: var(--radius-s);
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}
.nav a:hover { background: var(--accent-soft); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--ink); color: var(--paper); }

.machine-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
  white-space: nowrap;
  text-decoration: none;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); flex: none; }
.dot.on { background: var(--present); box-shadow: 0 0 0 3px var(--present-soft); }
.dot.off { background: var(--absent); box-shadow: 0 0 0 3px var(--absent-soft); }

/* ------------------------------------------------------------- page */

main { max-width: 1280px; margin: 0 auto; padding: 28px 24px 64px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--ink-3); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.stepper { display: flex; align-items: center; gap: 6px; }
.stepper h1 { min-width: 0; }

.btn {
  appearance: none;
  border: 1px solid var(--rule-strong);
  background: var(--sheet);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius-s);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.quiet:hover { background: var(--accent-soft); color: var(--ink); }
.btn.danger { color: var(--absent); }
.btn.icon { padding: 6px 9px; font-size: 16px; line-height: 1; }
.btn:disabled { opacity: 0.5; cursor: default; }

.notice {
  border-left: 3px solid var(--margin);
  background: var(--absent-soft);
  padding: 10px 14px;
  border-radius: 0 var(--radius-s) var(--radius-s) 0;
  margin-bottom: 18px;
  color: var(--ink);
}
.notice.info { border-left-color: var(--accent); background: var(--accent-soft); }
.notice strong { font-weight: 600; }

/* ------------------------------------------------------------- summary strip */

.tally { display: flex; gap: 32px; flex-wrap: wrap; margin: 4px 0 22px; }
.tally div { display: flex; align-items: baseline; gap: 8px; }
.tally b { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; }
.tally span { color: var(--ink-2); }
.tally .present b { color: var(--present); }
.tally .in b { color: var(--accent); }
.tally .absent b { color: var(--absent); }
.tally .half b { color: var(--half); }

/* ------------------------------------------------------------- today register */

.today-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 28px; align-items: start; }

.register {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius-m);
  overflow: hidden;
}
.reg-head, .reg-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.1fr) minmax(220px, 2.4fr) 76px 76px 64px 112px;
  align-items: center;
  column-gap: 14px;
  padding: 0 16px;
}
.reg-head {
  font-size: 12px;
  color: var(--ink-3);
  border-bottom: 1px solid var(--rule-strong);
  height: 38px;
}
.reg-head .num, .reg-row .num { text-align: right; }
.reg-row {
  min-height: 52px;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  position: relative;
}
.reg-row:last-of-type { border-bottom: 0; }
.reg-row:hover { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.reg-row.open { background: var(--accent-soft); }
.reg-row .who { min-width: 0; padding: 8px 0; }
.reg-row .who b { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reg-row .who small { color: var(--ink-3); font-size: 12px; }
.reg-row .time { color: var(--ink); }
.reg-row .time.missing { color: var(--ink-3); }

.hours-scale { position: relative; height: 38px; }
.hours-scale span { position: absolute; top: 50%; transform: translate(-50%, -50%); font-size: 11px; }

/* The day as a ruled strip; the bar spans first punch to last punch. */
.track {
  position: relative;
  height: 22px;
  background-image: linear-gradient(to right, var(--rule) 1px, transparent 1px);
  background-size: var(--hour) 100%;
  background-position: 0 0;
  border-left: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
}
.track .bar {
  position: absolute;
  top: 5px;
  height: 12px;
  border-radius: 6px;
  background: var(--present);
  min-width: 4px;
}
.track .bar.half_day, .track .bar.short { background: var(--half); }
.track .bar.in { background: var(--accent); border-top-right-radius: 0; border-bottom-right-radius: 0; }
.track .bar.in::after {
  content: "";
  position: absolute;
  right: -1px;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--accent);
}
.track .bar.missing_out { background: none; border: 2px dashed var(--absent); top: 4px; height: 14px; }
.track .tick { position: absolute; top: 2px; width: 2px; height: 18px; background: var(--ink); border-radius: 1px; opacity: 0.55; }
.track .now { position: absolute; top: -4px; bottom: -4px; width: 0; border-left: 1px dashed var(--margin); }

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
  background: var(--off-soft);
  color: var(--off);
}
.badge.present { background: var(--present-soft); color: var(--present); }
.badge.half_day, .badge.short { background: var(--half-soft); color: var(--half); }
.badge.in { background: var(--accent-soft); color: var(--accent); }
.badge.absent, .badge.missing_out { background: var(--absent-soft); color: var(--absent); }
.badge.needs { background: var(--half-soft); color: var(--half); }

.row-detail {
  grid-column: 1 / -1;
  padding: 4px 0 16px;
  cursor: default;
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.punch-list { display: flex; gap: 8px; flex-wrap: wrap; }
.punch-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--sheet);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-s);
  padding: 3px 4px 3px 10px;
  font-size: 13px;
}
.punch-chip.manual { border-style: dashed; }
.punch-chip button { border: 0; background: none; color: var(--ink-3); cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 6px; border-radius: 4px; }
.punch-chip button:hover { color: var(--absent); background: var(--absent-soft); }
.punch-chip .src { color: var(--ink-3); font-size: 11px; padding-right: 6px; }

.empty { padding: 48px 24px; text-align: center; color: var(--ink-2); }
.empty h2 { margin-bottom: 8px; color: var(--ink); }
.empty p { max-width: 46ch; margin: 0 auto 16px; }

/* ------------------------------------------------------------- side column */

.side h3 { margin-bottom: 10px; }
.side section + section { margin-top: 28px; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--rule); font-size: 14px; }
.feed li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed li span:last-child { color: var(--ink-2); white-space: nowrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ------------------------------------------------------------- tables */

.table-wrap { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius-m); overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; font-size: 12px; color: var(--ink-3); padding: 10px 12px; border-bottom: 1px solid var(--rule-strong); white-space: nowrap; background: var(--sheet); }
td { padding: 10px 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
td .muted, .muted { color: var(--ink-3); }
tr.inactive td { color: var(--ink-3); }
tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 40%, transparent); }

/* ------------------------------------------------------------- month register grid */

.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: var(--radius-s); overflow: hidden; }
.seg button { border: 0; background: var(--sheet); color: var(--ink-2); font: inherit; font-size: 14px; padding: 6px 14px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--rule-strong); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

.grid-wrap { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius-m); overflow: auto; max-height: calc(100vh - 220px); }
table.grid { font-size: 12px; width: auto; min-width: 100%; }
table.grid th, table.grid td { padding: 0; text-align: center; border-bottom: 1px solid var(--rule); border-right: 1px solid var(--rule); }
table.grid thead th { position: sticky; top: 0; z-index: 2; height: 40px; min-width: 30px; line-height: 1.15; color: var(--ink-2); }
table.grid thead th small { display: block; color: var(--ink-3); font-weight: 400; font-size: 10px; }
table.grid th.namecol, table.grid td.namecol {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--sheet);
  text-align: left;
  padding: 0 12px;
  min-width: 170px;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-right: 2px solid var(--margin);
  font-size: 13px;
}
table.grid thead th.namecol { z-index: 3; }
table.grid td.cell { height: 34px; min-width: 30px; font-weight: 600; }
table.grid th.offcol, table.grid td.offcol { background: var(--off-soft); }
table.grid td.cell.present { color: var(--present); }
table.grid td.cell.half_day, table.grid td.cell.short { color: var(--half); background: var(--half-soft); }
table.grid td.cell.absent, table.grid td.cell.missing_out { color: var(--absent); background: var(--absent-soft); }
table.grid td.cell.in { color: var(--accent); }
table.grid td.cell.off, table.grid td.cell.holiday { color: var(--off); }
table.grid td.tot { padding: 0 10px; font-weight: 600; white-space: nowrap; }
table.grid th.tot { padding: 0 10px; }

.legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-top: 12px; }
.legend b { font-weight: 600; margin-right: 4px; }
.legend .present b { color: var(--present); }
.legend .half b { color: var(--half); }
.legend .absent b { color: var(--absent); }
.legend .off b { color: var(--off); }

/* ------------------------------------------------------------- forms */

.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
input, select, textarea {
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-s);
  padding: 7px 10px;
  min-height: 38px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-error { color: var(--absent); font-size: 14px; min-height: 1.5em; }

.days-pick { display: flex; gap: 6px; flex-wrap: wrap; }
.days-pick label {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 52px; padding: 6px 10px; border: 1px solid var(--rule-strong); border-radius: var(--radius-s);
  cursor: pointer; font-size: 14px; color: var(--ink-2); background: var(--sheet);
}
.days-pick input { position: absolute; opacity: 0; pointer-events: none; }
.days-pick label:has(input:checked) { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.days-pick label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.settings { display: grid; grid-template-columns: 220px minmax(0, 640px); gap: 36px 40px; }
.settings > h2 { padding-top: 2px; }
.settings > h2 small { display: block; font-size: 13px; font-weight: 400; color: var(--ink-3); margin-top: 6px; line-height: 1.45; }
.settings .panel { display: flex; flex-direction: column; gap: 14px; padding-bottom: 36px; border-bottom: 1px solid var(--rule); }

dialog {
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-m);
  padding: 24px;
  width: min(520px, calc(100vw - 32px));
  background: var(--sheet);
  color: var(--ink);
  box-shadow: var(--shadow-pop);
}
dialog::backdrop { background: rgba(15, 23, 38, 0.45); }
dialog h2 { margin-bottom: 18px; }
dialog .actions { justify-content: flex-end; margin-top: 18px; }

/* ------------------------------------------------------------- login */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background-image: linear-gradient(var(--rule) 1px, transparent 1px);
  background-size: 100% 32px;
}
.login form {
  width: min(380px, 100%);
  background: var(--sheet);
  border: 1px solid var(--rule-strong);
  border-left: 3px solid var(--margin);
  border-radius: var(--radius-m);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-pop);
}
.login img { width: 40px; height: 40px; }
.login p { color: var(--ink-2); }

/* ------------------------------------------------------------- toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 18px;
  border-radius: var(--radius-s);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--absent); color: #fff; }

.print-title { display: none; }

/* ------------------------------------------------------------- responsive */

@media (max-width: 1100px) {
  .today-layout { grid-template-columns: minmax(0, 1fr); }
  .side { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 28px; }
  .side section + section { margin-top: 0; }
}

@media (max-width: 760px) {
  .topbar-inner { padding: 10px 16px; gap: 12px; flex-wrap: wrap; }
  .nav { order: 3; flex-basis: 100%; }
  .machine-pill { margin-left: auto; }
  .machine-pill .label { display: none; }
  main { padding: 20px 16px 48px; }
  h1 { font-size: 21px; }
  .tally { gap: 20px; }
  .tally b { font-size: 23px; }
  .reg-head { display: none; }
  .reg-row {
    grid-template-columns: 1fr auto;
    grid-template-areas: "who status" "track track" "times times";
    row-gap: 6px;
    padding: 10px 14px 12px;
  }
  .reg-row .who { grid-area: who; padding: 0; }
  .reg-row .status { grid-area: status; }
  .reg-row .track { grid-area: track; }
  .reg-row .t-in, .reg-row .t-out, .reg-row .t-hours { display: none; }
  .reg-row .times-m { grid-area: times; display: block !important; font-size: 13px; color: var(--ink-2); }
  .form-grid { grid-template-columns: 1fr; }
  .settings { grid-template-columns: 1fr; gap: 12px; }
  .settings .panel { margin-bottom: 20px; }
}
.times-m { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ------------------------------------------------------------- print / PDF */

@media print {
  @page { size: A4 landscape; margin: 10mm; }
  :root { --paper: #fff; --sheet: #fff; }
  body { font-size: 11px; background: #fff; color: #000; }
  .topbar, .actions, .side, .notice, .no-print, .seg, #toast, .row-detail, .filters { display: none !important; }
  main { padding: 0; max-width: none; }
  .print-title { display: block; font-size: 16px; font-weight: 600; margin-bottom: 8px; }
  .page-head { margin-bottom: 8px; }
  .today-layout { display: block; }
  .register, .table-wrap, .grid-wrap { border: 1px solid #999; max-height: none; overflow: visible; }
  .reg-row { min-height: 30px; break-inside: avoid; }
  table.grid td.cell { height: 22px; }
  table.grid th.namecol, table.grid td.namecol { position: static; }
  table.grid thead th { position: static; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
