:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1d2433; --muted: #6b7486; --line: #e1e5ec; --line2: #eef1f5;
  --brand: #1f4e79; --brand2: #2e75b6; --brand-soft: #e8f0f9;
  --red-bg: #ffc7ce; --red-ink: #9c0006; --amb-bg: #ffeb9c; --amb-ink: #8a5300; --grn-bg: #c6efce; --grn-ink: #006100;
  --A: #2e75b6; --B: #7a4fb5; --C: #c55a11;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 54px; background: var(--brand); color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.brand { font-weight: 700; font-size: 17px; letter-spacing: .2px; white-space: nowrap; }
nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
nav a { color: #dce7f3; text-decoration: none; padding: 8px 14px; border-radius: 6px; white-space: nowrap; }
nav a b { display: inline-block; width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 4px; background: rgba(255,255,255,.18); font-size: 11px; margin-right: 6px; }
nav a:hover { background: rgba(255,255,255,.1); color: #fff; }
nav a.on { background: #fff; color: var(--brand); font-weight: 600; }
nav a.on b { background: var(--brand); color: #fff; }
.who { background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: 18px; padding: 5px 14px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.who:hover { background: rgba(255,255,255,.25); }

main { padding: 18px 22px 40px; max-width: 1500px; margin: 0 auto; }

/* ---------- toolbar & filters ---------- */
.toolbar, .filters { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar { margin-bottom: 12px; }
.toolbar h1 { font-size: 21px; margin: 0; display: flex; align-items: center; gap: 10px; }
.toolbar h1 .sub { font-size: 14px; font-weight: 400; }
.filters { background: var(--card); border: 1px solid var(--line); border-radius: 8px 8px 0 0; padding: 10px 12px; border-bottom: none; }
.filters input[type=search] { width: 240px; }
.spacer { flex: 1; }

input, select, textarea { border: 1px solid #c9d0db; border-radius: 6px; padding: 6px 9px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand2); outline-offset: -1px; border-color: var(--brand2); }
textarea { resize: vertical; width: 100%; }
input:disabled { background: #f0f2f5; color: #999; }
button, .btn { border: 1px solid #c9d0db; background: #fff; border-radius: 6px; padding: 6px 14px; cursor: pointer; text-decoration: none; display: inline-block; color: var(--ink); }
button:hover, .btn:hover { background: #f2f5f9; }
button.primary { background: var(--brand2); border-color: var(--brand2); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--brand); }
button.danger { color: #b3261e; border-color: #e6b3b0; }
button.danger:hover { background: #fdecea; }
button:disabled { opacity: .55; cursor: default; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.field.inline { flex-direction: row; align-items: center; gap: 6px; }
.field.inline > span { text-transform: none; font-size: 13px; letter-spacing: 0; }
.field.grow { flex: 1; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; white-space: nowrap; }
.check input { width: 17px; height: 17px; }
input.short { width: 110px; }

/* ---------- tables ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 0 0 8px 8px; overflow: auto; }
table.grid { width: 100%; border-collapse: collapse; }
.grid th { position: sticky; top: 0; background: #f7f9fc; text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; color: #4a5568; padding: 9px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; z-index: 1; }
.grid th.sortable { cursor: pointer; }
.grid th.sortable:hover { background: #eef2f8; }
.grid th.sorted { color: var(--brand2); }
.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line2); vertical-align: top; }
.grid tr.click { cursor: pointer; }
.grid tbody tr:hover td { background: #f5f9ff; }
.grid td.notes { color: #4a5568; white-space: pre-wrap; max-width: 380px; }
.grid td.empty { text-align: center; color: var(--muted); padding: 40px; }
.grid tr.done td { color: #8a93a3; }
.grid tr.done td b { font-weight: 500; }
.grid tr.overdue td.date { color: var(--red-ink); font-weight: 700; }
.grid tr.overdue td.date::after { content: ' ●'; font-size: 10px; }
.grid tr.soon td.date { color: var(--amb-ink); font-weight: 700; }
.grid tr.inactive td { color: #9aa2b1; }
.w-date { width: 110px; } .w-small { width: 80px; } .w-users { width: 150px; } .w-name { width: 160px; } .w-sel { width: 130px; } .w-client { width: 180px; }
.center { text-align: center !important; } .right { text-align: right; } .nowrap { white-space: nowrap; }
input.big { width: 19px; height: 19px; cursor: pointer; accent-color: #2e8540; }

/* Excel-like filter row (Other Jobs) */
.grid tr.filter-row th { top: 37px; background: #fff; padding: 5px 6px; text-transform: none; font-weight: 400; letter-spacing: 0; border-bottom: 1px solid var(--line); }
.grid tr.filter-row input, .grid tr.filter-row select { width: 100%; padding: 4px 6px; font-size: 13px; }

/* status / priority colours (same as the Excel file) */
.pill, .pill-sel { display: inline-block; border-radius: 4px; padding: 2px 8px; font-size: 13px; border: 1px solid transparent; white-space: nowrap; }
.pill-sel { cursor: pointer; padding: 3px 6px; width: 100%; background: #fff; border-color: #dde2ea; }
.st-Pending { background: var(--red-bg); color: var(--red-ink); }
.st-Inprogress { background: var(--amb-bg); color: var(--amb-ink); }
.st-Completed { background: var(--grn-bg); color: var(--grn-ink); }
.st-Notapplicable { background: #eceff3; color: #5d6676; }
.pr-Urgent { background: var(--red-bg); color: var(--red-ink); font-weight: 600; }
.pr-High { background: var(--amb-bg); color: var(--amb-ink); }
.pr-Normal, .pr-Low { background: #fff; }
.pill.yearly { background: var(--brand-soft); color: var(--brand); }
.red { color: var(--red-ink); font-weight: 700; } .amber { color: var(--amb-ink); font-weight: 600; }
.muted { color: var(--muted); } .small { font-size: 12px; }

.chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.chip { display: inline-block; min-width: 30px; text-align: center; padding: 1px 6px; border-radius: 10px; background: #e7ebf1; color: #34405a; font-size: 12px; font-weight: 600; }
.chip.me { background: var(--brand2); color: #fff; }
.chips-pick { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn { min-width: 52px; border-radius: 18px; font-weight: 700; padding: 6px 12px; }
.chip-btn.on { background: var(--brand2); color: #fff; border-color: var(--brand2); }
.chip-btn.inactive { border-style: dashed; }

.mod { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 5px; color: #fff; font-size: 12px; font-weight: 700; flex: none; }
.modA { background: var(--A); } .modB { background: var(--B); } .modC { background: var(--C); } .mod\! { background: #b3261e; }

/* ---------- home ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; text-decoration: none; color: var(--ink); }
.stat b { font-size: 26px; }
.stat span:last-child { color: var(--muted); }
a.stat:hover { border-color: var(--brand2); }
.stat.danger b { color: var(--red-ink); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 16px; }
.card h3 { margin: 0 0 8px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.card .count { background: #e7ebf1; border-radius: 10px; padding: 0 9px; font-size: 13px; }
.card.c-red { border-left: 4px solid #d9534f; } .card.c-red .count { background: var(--red-bg); color: var(--red-ink); }
.card.c-grey { border-left: 4px solid #aab2c0; }
.card.c-blue { border-left: 4px solid var(--brand2); }
.grid.home { table-layout: fixed; }
.card .grid td { border-bottom-color: var(--line2); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20,30,50,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 620px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-head .x { border: none; font-size: 24px; line-height: 1; padding: 0 6px; background: none; }
.modal-body { padding: 16px 18px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); background: #fafbfc; border-radius: 0 0 10px 10px; }
.modal-foot .left { margin-right: auto; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form .row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.form .row .check { padding-bottom: 7px; }
.form .field input:not([type=checkbox]):not(.short), .form .field select { width: 100%; }
.who-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.who-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px 8px; border-radius: 8px; }
.who-btn b { font-size: 22px; color: var(--brand2); }
.who-btn.on { border-color: var(--brand2); background: var(--brand-soft); }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: 420px; }
.toast { padding: 11px 16px; border-radius: 7px; color: #fff; background: #2e7d32; box-shadow: 0 6px 18px rgba(0,0,0,.2); transition: opacity .4s; }
.toast.err { background: #b3261e; }
.toast.out { opacity: 0; }

@media (max-width: 900px) { .two { grid-template-columns: 1fr; } .top { gap: 8px; padding: 0 10px; } .brand { display: none; } main { padding: 12px; } }

/* ---------- print ---------- */
@media print {
  .top, .toolbar button, .filters, #toasts, .grid tr.filter-row { display: none !important; }
  body { background: #fff; font-size: 11px; }
  main { padding: 0; max-width: none; }
  .table-wrap { border: none; overflow: visible; }
  .grid th { position: static; }
  .grid td.notes { max-width: none; }
  .pill-sel { border: none; appearance: none; -webkit-appearance: none; }
}

/* ---------- v2: login, menu, clients, officers ---------- */
.top[hidden] { display: none; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 40px; background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.18); min-width: 230px; padding: 6px; z-index: 30; }
.menu[hidden] { display: none; }
.menu-name { padding: 8px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line2); margin-bottom: 4px; }
.menu button { display: block; width: 100%; text-align: left; border: none; background: none; padding: 8px 10px; border-radius: 6px; }
.menu button:hover { background: var(--brand-soft); }

.auth-wrap { min-height: calc(100vh - 60px); display: flex; align-items: center; justify-content: center; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px 30px; width: 100%; max-width: 440px; box-shadow: 0 12px 40px rgba(20,40,80,.12); display: flex; flex-direction: column; gap: 14px; }
.auth-card .row { display: flex; gap: 12px; }
.auth-card input { width: 100%; }
.auth-brand { font-weight: 700; color: var(--brand); font-size: 15px; letter-spacing: .3px; }
.auth-card h2 { margin: 0 0 4px; font-size: 22px; }
.auth-msg { color: var(--red-ink); font-weight: 600; min-height: 1px; }
.auth-msg:empty { display: none; }
.big-btn { padding: 10px; font-size: 15px; }

fieldset.box { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px 12px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
fieldset.box[hidden] { display: none; }
fieldset.box legend { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); padding: 0 6px; }
.client-pick { display: flex; gap: 8px; }
.client-pick input { flex: 1; }
.small-btn { white-space: nowrap; font-size: 13px; padding: 5px 10px; }
.chip.role { background: #efe8f8; color: #5b3a8c; border-radius: 4px; }
.grid.mini td { padding: 6px 8px; }
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.three .card { margin-bottom: 16px; }
.scroll-x { overflow-x: auto; }
@media (max-width: 1100px) { .three { grid-template-columns: 1fr; } }
@media (max-width: 700px) {
  .form .row { flex-direction: column; align-items: stretch; }
  .filters input[type=search] { width: 100%; }
  nav a { padding: 8px 9px; }
  .modal-back { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; }
}
