:root {
  --blue: #0f3d91;
  --blue-2: #1d4ed8;
  --bg: #f4f6fb;
  --card: #fff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --gray-bg: #f3f4f6;
  --purple: #7c3aed;
  --purple-bg: #ede9fe;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--blue); color: #fff;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.brand { font-weight: 700; font-size: 18px; margin-right: auto; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a, nav button {
  color: #dbe5ff; text-decoration: none; background: none; border: 0; font: inherit; font-size: 14px;
  padding: 6px 10px; border-radius: 8px; cursor: pointer;
}
nav a.active { background: rgba(255,255,255,.18); color: #fff; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
main.narrow { max-width: 560px; }
.loading { color: var(--muted); text-align: center; padding: 40px; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 14px; }
.card h2 { margin: 0 0 10px; font-size: 18px; }
.card h3 { margin: 14px 0 6px; font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } }

.clock { font-size: 34px; font-weight: 700; letter-spacing: .5px; }
.deadline { padding: 10px 12px; border-radius: 10px; background: var(--amber-bg); color: var(--amber); font-size: 14px; margin-top: 10px; }
.deadline.over { background: var(--red-bg); color: var(--red); }
.deadline.ok { background: var(--green-bg); color: var(--green); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--blue-2); color: #fff; text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.big { width: 100%; padding: 18px; font-size: 19px; border-radius: 14px; }
.btn.green { background: var(--green); }
.btn.red { background: var(--red); }
.btn.ghost { background: var(--gray-bg); color: var(--text); }
.btn.wa { background: #25d366; color: #073b1d; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.stack > * + * { margin-top: 10px; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
label.field > span .req { color: var(--red); }
input, textarea, select {
  width: 100%; font: inherit; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 10px; background: #fff; color: var(--text);
}
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: auto; }
.list-inputs input + input { margin-top: 6px; }

.gps { padding: 10px 12px; border-radius: 10px; font-size: 14px; background: var(--gray-bg); margin-bottom: 12px; }
.gps.ok { background: var(--green-bg); color: #14532d; }
.gps.err { background: var(--red-bg); color: #7f1d1d; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.s-PRESENT { background: var(--green-bg); color: var(--green); }
.s-ABSENT { background: var(--red-bg); color: var(--red); }
.s-HALF_DAY { background: var(--amber-bg); color: var(--amber); }
.s-PENDING, .s-NOT_IN { background: #e0e7ff; color: #3730a3; }
.s-LEAVE { background: var(--purple-bg); color: var(--purple); }
.s-HOLIDAY, .s-WEEK_OFF, .s-UPCOMING, .s-NOT_JOINED, .s-none { background: var(--gray-bg); color: var(--muted); }
.late { background: var(--amber-bg); color: var(--amber); }

.answers dt { font-size: 13px; color: var(--muted); margin-top: 8px; }
.answers dd { margin: 0; white-space: pre-wrap; }
.answers ol { margin: 0; padding-left: 20px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
tr.click { cursor: pointer; }
tr.click:hover { background: #f9fafb; }
.table-wrap { overflow-x: auto; }

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 14px; }
.summary .tile { background: var(--card); border-radius: 12px; padding: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.summary .num { font-size: 26px; font-weight: 700; }
.summary .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; }

.month { border-collapse: separate; border-spacing: 2px; font-size: 12px; }
.month th, .month td { border: 0; padding: 0; text-align: center; }
.month td.name { text-align: left; padding-right: 8px; white-space: nowrap; font-weight: 600; position: sticky; left: 0; background: var(--card); }
.month .cell { width: 26px; height: 26px; line-height: 26px; border-radius: 6px; cursor: pointer; font-weight: 700; position: relative; }
.month .cell.manual::after { content: ''; position: absolute; top: 2px; right: 2px; width: 5px; height: 5px; border-radius: 50%; background: var(--blue-2); }
.month th.wknd { color: var(--red); }
.month td.tot, .month th.tot { padding: 0 6px; min-width: 28px; }
.legend { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; margin-top: 10px; }

.history .day { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.history .day .d { width: 92px; font-size: 14px; }

.fields-editor .frow { display: grid; grid-template-columns: 1fr 150px 64px 70px auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.fields-editor .frow .ctrls { display: flex; gap: 4px; }
@media (max-width: 700px) { .fields-editor .frow { grid-template-columns: 1fr 1fr; } }
.chk { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 50; max-width: 90vw;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.err { background: var(--red); }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(640px, 94vw); max-height: 90vh; }
dialog::backdrop { background: rgba(17,24,39,.5); }
#modal-body { padding: 18px; }

.login { max-width: 380px; margin: 40px auto; }
.error { color: var(--red); font-size: 14px; min-height: 20px; }
a { color: var(--blue-2); }
