:root {
  --navy: #14213d; --navy-2: #1f2f55; --orange: #f77f00; --orange-d: #d96f00;
  --bg: #f3f5f8; --card: #fff; --line: #dde2ea; --text: #1d2433; --muted: #6b7489;
  --booked: #2563eb; --booked-bg: #e8f0fe;
  --progress: #d97706; --progress-bg: #fff4e0;
  --done: #15803d; --done-bg: #e7f6ec;
  --cancelled: #8a93a6; --cancelled-bg: #f0f1f4;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Top bar */
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; padding-top: max(12px, env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { background: var(--orange); color: var(--navy); font-weight: 800; letter-spacing: .5px; border-radius: 8px; padding: 8px 9px; font-size: 15px; flex: none; }
.topbar h1 { margin: 0; font-size: 19px; font-weight: 700; line-height: 1.2; }
.topbar h1 .sub { color: #ffd2a3; font-weight: 600; }
.topbar h1 .dash { opacity: .6; }
.tagline { font-size: 12px; opacity: .7; margin-top: 2px; }
.top-actions { display: flex; gap: 8px; flex: none; }

/* Buttons */
.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: 14px; line-height: 1.2; white-space: nowrap; }
.btn:hover { background: #f6f7fa; }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.primary:hover { background: var(--orange-d); }
.btn.danger { color: #b42318; border-color: #f2c4bf; }
.btn.danger:hover { background: #fdeceb; }
.btn.ghost-light { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.btn.ghost-light:hover { background: rgba(255,255,255,.1); }
.btn.icon { font-size: 20px; padding: 4px 12px; }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 12px 20px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 8px 16px; font-weight: 600; cursor: pointer; font-size: 14px; }
.seg button[aria-selected="true"] { background: var(--navy); color: #fff; }
.nav { display: flex; align-items: center; gap: 6px; }
.jump { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 14px; }
.range { font-weight: 700; font-size: 16px; }
.legend { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; border: 1px solid transparent; }
.pill.booked { background: var(--booked-bg); color: var(--booked); border-color: #c7d8fb; }
.pill.in_progress { background: var(--progress-bg); color: var(--progress); border-color: #f7d9a8; }
.pill.done { background: var(--done-bg); color: var(--done); border-color: #bfe5cc; }
.pill.cancelled { background: var(--cancelled-bg); color: var(--cancelled); border-color: #dadde4; }

main { flex: 1; padding: 16px 20px; }

/* Week board */
.week-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.board { display: grid; grid-template-columns: 120px repeat(7, minmax(150px, 1fr)); min-width: 1170px; }
.board .h { background: #f8f9fb; border-bottom: 1px solid var(--line); padding: 10px; font-size: 13px; font-weight: 700; text-align: center; position: sticky; top: 0; }
.board .h .d { display: block; font-weight: 500; color: var(--muted); font-size: 12px; margin-top: 2px; }
.board .h.today { background: #fff1e2; color: var(--orange-d); }
.board .h.today .d { color: var(--orange-d); }
.board .corner { text-align: left; color: var(--muted); font-weight: 600; }
.board .person { position: sticky; left: 0; z-index: 2; background: #fff; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 12px 10px; font-weight: 700; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.board .person .count { font-weight: 500; font-size: 12px; color: var(--muted); }
.board .person.former { color: var(--muted); font-style: italic; }
.board .cell { border-bottom: 1px solid var(--line); border-right: 1px solid #eef0f4; padding: 6px; min-height: 110px; display: flex; flex-direction: column; gap: 6px; position: relative; }
.board .cell.weekend { background: #fafbfc; }
.board .cell.today { background: #fffaf3; }
.board .cell .add { opacity: 0; border: 1px dashed var(--line); background: transparent; border-radius: 8px; color: var(--muted); font-size: 12px; padding: 4px; cursor: pointer; margin-top: auto; transition: opacity .15s; }
.board .cell:hover .add, .board .cell .add:focus { opacity: 1; }
@media (hover: none) { .board .cell .add { opacity: .7; } }

/* Job card */
.job { text-align: left; width: 100%; border: 1px solid var(--line); border-left: 4px solid var(--booked); background: var(--booked-bg); border-radius: 8px; padding: 6px 8px; cursor: pointer; font-size: 12.5px; line-height: 1.3; display: block; }
.job:hover { filter: brightness(.98); box-shadow: 0 1px 4px rgba(20,33,61,.12); }
.job .t { font-weight: 700; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 2px 6px; flex-wrap: wrap; }
.job .c { font-weight: 700; margin-top: 2px; color: var(--text); word-break: break-word; }
.job .s { color: #3a4356; margin-top: 2px; word-break: break-word; }
.job .n { color: var(--muted); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.job .type { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; color: var(--navy-2); opacity: .75; }
.job.st-in_progress { border-left-color: var(--progress); background: var(--progress-bg); }
.job.st-done { border-left-color: var(--done); background: var(--done-bg); }
.job.st-cancelled { border-left-color: var(--cancelled); background: var(--cancelled-bg); }
.job.st-cancelled .c, .job.st-cancelled .s { text-decoration: line-through; color: var(--muted); }
.job .also { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* Day view */
.day-wrap { max-width: 760px; margin: 0 auto; }
.day-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.day-head h2 { margin: 0; font-size: 20px; }
.day-head select { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; }
.day-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.day-summary .who { background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.day-summary .who b { color: var(--navy); }
.day-list { display: flex; flex-direction: column; gap: 10px; }
.day-list .job { font-size: 15px; padding: 12px 14px; border-radius: 10px; background-color: #fff; }
.day-list .job .t { font-size: 14px; }
.day-list .job .c { font-size: 16px; }
.day-list .job .n { -webkit-line-clamp: unset; display: block; }
.day-list .job.st-booked { background: #fff; }
.day-list .job .people { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.day-list .job .people span { background: var(--navy); color: #fff; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 2px 9px; }
.day-list .job .map { display: inline-block; margin-top: 4px; font-size: 13px; color: var(--booked); font-weight: 600; text-decoration: none; }
.empty { text-align: center; color: var(--muted); background: #fff; border: 1px dashed var(--line); border-radius: var(--radius); padding: 30px 16px; }

.foot { text-align: center; font-size: 12px; color: var(--muted); padding: 10px 16px 18px; }

/* Dialogs */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); box-shadow: 0 20px 60px rgba(20,33,61,.3); }
dialog::backdrop { background: rgba(20,33,61,.45); }
dialog form { margin: 0; display: flex; flex-direction: column; max-height: calc(100vh - 24px); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.dlg-head h3 { margin: 0; font-size: 18px; }
.x { border: 0; background: transparent; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); }
.dlg-body { padding: 14px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.dlg-foot { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: #fafbfc; }
.spacer { flex: 1; }
label, fieldset { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: #3a4356; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { padding: 0; margin-bottom: 5px; }
input[type=text], input[type=date], input[type=time], select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font-size: 15px; font-weight: 400; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #ffd2a3; border-color: var(--orange); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.req { color: #b42318; }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label { flex-direction: row; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-weight: 600; background: #fff; }
.chips label:has(input:checked) { background: var(--navy); color: #fff; border-color: var(--navy); }
.chips input { margin: 0; accent-color: var(--orange); }
.errors { background: #fdeceb; color: #b42318; border: 1px solid #f2c4bf; border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.staff-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.staff-list li { display: flex; gap: 6px; align-items: center; }
.staff-list li input { flex: 1; }
.staff-list li.former input { color: var(--muted); font-style: italic; }
.staff-add { display: flex; gap: 6px; }
.staff-add input { flex: 1; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Phone */
@media (max-width: 700px) {
  .topbar { padding: 10px 12px; }
  .topbar h1 { font-size: 15px; }
  .topbar h1 .dash, .topbar h1 .sub { display: none; }
  .tagline { display: block; }
  .tagline::before { content: "Job Diary · "; color: #ffd2a3; opacity: 1; }
  .logo { padding: 6px 7px; font-size: 13px; }
  .btn { padding: 8px 11px; }
  .toolbar { padding: 10px 12px; gap: 8px; }
  .jump { display: none; }
  .legend { margin-left: 0; width: 100%; }
  .range { font-size: 14px; }
  main { padding: 12px; }
  .board { grid-template-columns: 84px repeat(7, 150px); min-width: 0; }
  .board .person { font-size: 13px; padding: 10px 8px; }
  .day-head h2 { font-size: 18px; }
  .topbar .wide { display: none; }
  .topbar .btn { padding: 7px 10px; font-size: 13px; }
  .topbar h1 { font-size: 14px; }
  body.view-day .range { display: none; }
}

/* status row, empty board, account */
.st-row { margin-top: 6px; }
.board-empty { grid-column: 1 / -1; margin: 16px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack h4 { margin: 6px 0 0; font-size: 15px; }
.who-line { margin: 0; color: var(--muted); font-size: 14px; }
.okmsg { background: var(--done-bg); color: var(--done); border: 1px solid #bfe5cc; border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.okmsg code { font-size: 15px; font-weight: 700; color: var(--text); background: #fff; padding: 1px 6px; border-radius: 4px; user-select: all; }
.users-list li { justify-content: space-between; flex-wrap: wrap; }
.users-list .u-name { flex: 1; min-width: 140px; }
.user-add { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
input[type=password] { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font-size: 15px; font-weight: 400; background: #fff; width: 100%; }
@media (max-width: 700px) { .wide-only { display: none; } }

/* login page */
.login-body { justify-content: center; align-items: center; background: var(--navy); padding: 16px; }
.login-card { flex: none; padding: 0; background: #fff; border-radius: 14px; width: min(400px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.35); overflow: hidden; }
.login-card .lc-head { background: var(--navy-2); color: #fff; padding: 22px 24px; display: flex; gap: 12px; align-items: center; }
.login-card .lc-head h1 { font-size: 18px; margin: 0; line-height: 1.25; }
.login-card .lc-head h1 span { display: block; color: #ffd2a3; font-weight: 600; font-size: 15px; }
.login-card form { padding: 22px 24px 26px; display: flex; flex-direction: column; gap: 14px; }
.login-card .btn.primary { padding: 11px; font-size: 16px; }
.login-foot { color: rgba(255,255,255,.6); font-size: 12px; text-align: center; margin-top: 14px; }
