/* Camp David schedules. Touch-first, responsive for POS terminals, tablets and phones. */
:root {
  --green: #1f3a2e;
  --green-2: #2d5a45;
  --accent: #c8963e;
  --bg: #f4f2ee;
  --card: #ffffff;
  --ink: #1d1d1b;
  --muted: #6b6a66;
  --line: #dedad2;
  --ok: #1e7a46;
  --ok-bg: #e2f3e8;
  --warn: #8a5a00;
  --warn-bg: #fdf0d5;
  --bad: #b3261e;
  --bad-bg: #fde4e1;
  --radius: 14px;
  --tap: 52px;               /* minimum touch target */
  --gutter: clamp(12px, 2.5vw, 28px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: clamp(15px, 1.1vw + 10px, 18px);
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
h1 { font-size: clamp(1.35rem, 2.2vw + .6rem, 2rem); margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
a { color: var(--green-2); }
code { font-size: .85em; }
code.wrap { white-space: pre-wrap; word-break: break-word; }
[hidden] { display: none !important; }

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--gutter);
  padding-bottom: calc(var(--gutter) + 90px); /* room for sticky submit bar */
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 8px var(--gutter);
  background: var(--green); color: #fff;
  flex-wrap: wrap;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.1rem; letter-spacing: .02em; }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: #fff; text-decoration: none; padding: 0 14px; border-radius: 10px;
  min-height: 44px; display: inline-flex; align-items: center; white-space: nowrap; opacity: .8;
}
.nav a.active, .nav a:hover { background: rgba(255,255,255,.14); opacity: 1; }
.who { display: flex; align-items: center; gap: 10px; }
.who form { margin: 0; }
.who-name { opacity: .85; }
@media (max-width: 640px) {
  .topbar { gap: 6px; }
  .brand { order: 1; }
  .who { order: 2; margin-left: auto; }
  .who-name { display: none; }
  .nav { order: 3; flex-basis: 100%; }
}

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:disabled { background: #9aa8a1; border-color: #9aa8a1; cursor: not-allowed; }
.btn-danger { color: var(--bad); border-color: var(--bad); }
.btn-ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,.4); }
.btn-lg { min-height: var(--tap); padding: 0 32px; font-size: 1.1rem; letter-spacing: .04em; }

.input, .field input:not([type=checkbox]), .field select, .field textarea, .panel textarea {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: #fff; font: inherit; color: var(--ink);
}
.input:focus, .field input:focus, .field select:focus { outline: 3px solid rgba(45,90,69,.25); border-color: var(--green-2); }
.input.code, textarea.code { font-family: ui-monospace, Consolas, monospace; font-size: 14px; line-height: 1.4; }
.input.time { width: auto; min-width: 8.5em; font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: .85rem; color: var(--muted); font-weight: 600; }
.field small { color: var(--muted); }
.field .errorlist, .errorlist { color: var(--bad); margin: 4px 0 0; padding: 0; list-style: none; font-size: .9rem; }

.toggle { display: inline-flex; align-items: center; gap: 10px; min-height: 48px; cursor: pointer; user-select: none; }
.toggle input { width: 24px; height: 24px; accent-color: var(--green); }
.toggle.small { min-height: 36px; }

/* ---------- Layout bits ---------- */
.page-head { margin-bottom: 16px; }
.page-head .sub, .sub { color: var(--muted); margin: 0; }
.back { display: inline-flex; min-height: 40px; align-items: center; text-decoration: none; font-weight: 600; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.actions form { margin: 0; }
.step {
  display: inline-grid; place-items: center; width: 1.6em; height: 1.6em; margin-right: .3em;
  border-radius: 50%; background: var(--accent); color: #fff; font-size: .8em; vertical-align: middle;
}
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(14px, 2vw, 22px); margin-bottom: 16px; }
.hint { color: var(--muted); font-size: .9rem; }
.empty { color: var(--muted); padding: 24px; text-align: center; grid-column: 1 / -1; }
.errors { background: var(--bad-bg); color: var(--bad); border-radius: 12px; padding: 10px 16px; margin-bottom: 14px; }
.errors p { margin: 4px 0; }
.error-text { color: var(--bad); font-size: .85rem; }
.flash { margin-bottom: 14px; }
.flash-item { background: var(--ok-bg); color: var(--ok); border-radius: 12px; padding: 12px 16px; }
.flash-item.error { background: var(--bad-bg); color: var(--bad); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.chip {
  flex: none; min-height: 44px; padding: 0 16px; display: inline-flex; align-items: center;
  border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); text-decoration: none; white-space: nowrap;
}
.chip.on { background: var(--green); border-color: var(--green); color: #fff; }
.filters { margin-bottom: 8px; }
.filters .input { max-width: 520px; margin-bottom: 8px; }

/* ---------- Cards (employees, agents) ---------- */
.grid-cards {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr));
  margin-bottom: 24px;
}
.grid-cards.wide { grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.card {
  display: flex; flex-direction: column; gap: 4px; justify-content: center;
  min-height: 84px; padding: 14px 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); text-decoration: none; touch-action: manipulation;
}
.card:active { background: #eef3f0; border-color: var(--green-2); }
.emp-name { font-weight: 700; font-size: 1.05rem; }
.emp-meta { color: var(--muted); font-size: .88rem; }

/* ---------- Login keypad ---------- */
.login-page { background: var(--green); color: #fff; }
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login { display: flex; flex-direction: column; align-items: center; gap: clamp(8px, 2vh, 24px); width: 100%; }
.login-brand { text-align: center; }
.login-brand h1 { font-size: clamp(1.6rem, 4vh + .5rem, 2.6rem); letter-spacing: .03em; }
.login-brand p { margin: 0; opacity: .75; }
.keypad-form { display: flex; flex-direction: column; align-items: center; }
.pin-label { margin: 0 0 8px; opacity: .85; }
.pin-dots { display: flex; gap: 14px; margin-bottom: 4px; }
.pin-dots span { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); transition: background .1s; }
.pin-dots span.filled { background: #fff; border-color: #fff; }
.pin-dots.shake { animation: shake .35s; }
.pin-error { min-height: 1.4em; margin: 6px 0; color: #ffd2cc; font-weight: 600; text-align: center; }
.keypad {
  --key: clamp(64px, min(22vw, 11vh), 96px);
  display: grid; grid-template-columns: repeat(3, var(--key)); gap: clamp(10px, 1.6vh, 16px);
}
.key {
  width: var(--key); height: var(--key); border-radius: 50%;
  border: 0; background: rgba(255,255,255,.12); color: #fff;
  font: 600 calc(var(--key) * .36) var(--font); cursor: pointer; touch-action: manipulation;
}
.key:active { background: rgba(255,255,255,.32); }
.key-fn { font-size: calc(var(--key) * .2); background: transparent; }
.keypad.locked .key { opacity: .35; pointer-events: none; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
/* Landscape screens (POS terminals, tablets on their side, phones on their side): side by side. */
@media (orientation: landscape) and (min-width: 700px), (orientation: landscape) and (max-height: 500px) {
  .login { flex-direction: row; justify-content: center; gap: clamp(32px, 8vw, 120px); }
  .login-brand { text-align: left; }
  .keypad { --key: clamp(52px, 13vh, 96px); }
}

/* ---------- Schedule editor ---------- */
.week-label { margin: 8px 0 6px; font-weight: 600; color: var(--muted); font-size: .9rem; }
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: clamp(4px, 1vw, 10px); margin-bottom: 8px; }
.day {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: clamp(64px, 9vw, 92px); padding: 6px 2px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff;
  cursor: pointer; user-select: none; touch-action: manipulation;
}
.day input { position: absolute; opacity: 0; pointer-events: none; }
.day .dow { font-size: .75rem; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.day .dnum { font-size: clamp(1.1rem, 2.2vw, 1.6rem); font-weight: 700; line-height: 1.1; }
.day .dmon { font-size: .7rem; color: var(--muted); }
.day.today { border-color: var(--accent); }
.day.past { background: #f7f6f3; }
.day.past .dnum { color: var(--muted); }
.day:has(input:checked), .day.checked { background: var(--green); border-color: var(--green); color: #fff; }
.day:has(input:checked) .dow, .day:has(input:checked) .dmon, .day.checked .dow, .day.checked .dmon,
.day:has(input:checked) .dnum, .day.checked .dnum { color: #fff; }
.day .dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
@media (max-width: 420px) { .day .dmon { display: none; } }

.apply-all {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px; margin-bottom: 12px; border-radius: 12px; background: #f1efe9;
}
.apply-all > span:first-child { font-weight: 600; font-size: .9rem; }
.dash { color: var(--muted); }
.rows { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.row {
  display: grid; grid-template-columns: minmax(180px, 1fr) auto; align-items: center; gap: 8px 16px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
}
.row-date strong { font-size: 1.05rem; }
.row-date span { color: var(--muted); }
.row-date .current { display: block; color: var(--warn); margin-top: 2px; }
.row-times { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.row-times .field { margin: 0; }
.row.off .row-times .field { opacity: .35; pointer-events: none; }
.overnight { grid-column: 1 / -1; margin: 0; color: var(--warn); font-size: .85rem; font-weight: 600; }
.note { margin-top: 6px; }
@media (max-width: 760px) {
  .row { grid-template-columns: 1fr; }
  .row-times { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .row-times .toggle { grid-column: 1 / -1; }
  .row-times .input.time, .apply-all .input.time { width: 100%; min-width: 0; padding: 10px 6px; font-size: 1rem; }
  .apply-all { display: grid; grid-template-columns: 1fr auto 1fr; }
  .apply-all > span:first-child, .apply-all .btn { grid-column: 1 / -1; }
}

.submit-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px var(--gutter); padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(0,0,0,.06);
}
.summary { color: var(--muted); font-size: .95rem; }
@media (max-width: 480px) { .submit-bar .btn-lg { flex: 1; } .summary { display: none; } }

/* ---------- Status ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.badge.pending { background: var(--warn-bg); color: var(--warn); }
.badge.exported { background: var(--ok-bg); color: var(--ok); }
.badge.failed { background: var(--bad-bg); color: var(--bad); }
.badge.replaced { background: #eee; color: var(--muted); }

.done { max-width: 620px; margin: 4vh auto; text-align: center; }
.done-icon { width: 84px; height: 84px; margin: 0 auto 12px; display: grid; place-items: center; border-radius: 50%; background: var(--ok-bg); color: var(--ok); font-size: 44px; }
.done .actions { justify-content: center; margin-top: 18px; }
.list { list-style: none; padding: 0; margin: 18px 0; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li strong { flex: 1; }
.big-code { font: 700 clamp(2rem, 8vw, 3.4rem) ui-monospace, Consolas, monospace; letter-spacing: .15em; background: var(--card); border: 2px dashed var(--accent); border-radius: var(--radius); padding: 16px; word-break: break-all; }
.big-code.small-code { font-size: clamp(.9rem, 2.4vw, 1.2rem); letter-spacing: 0; user-select: all; }

/* ---------- Tables -> cards on narrow screens ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 20px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #faf9f6; }
.table tr:last-child td { border-bottom: 0; }
.table form { margin: 0; }
@media (max-width: 760px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .table td { border: 0; padding: 3px 0; display: flex; gap: 12px; }
  .table td[data-label]::before { content: attr(data-label); flex: 0 0 34%; color: var(--muted); font-size: .85rem; }
}
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; }

/* ---------- Manager assignment ---------- */
.dept { border: 1px solid var(--line); border-radius: 12px; margin: 12px 0 0; padding: 4px 12px 12px; }
.dept legend { padding: 0 6px; font-weight: 700; }
.assign-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 8px; }
.assign {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.assign input { width: 22px; height: 22px; accent-color: var(--green); flex: none; }
.assign span { flex: 1; }
.assign small { color: var(--muted); }
.assign:has(input:checked) { border-color: var(--green-2); background: #eef5f1; }
.form-grid { max-width: 1000px; }
