/* P3 Advisory brand: navy + gold, taken from the business logo. */
:root {
  --navy: #0f2147;
  --navy-2: #1b3266;
  --gold: #c8962e;
  --gold-soft: #f6ecd6;
  --bg: #f4f5f8;
  --panel: #fff;
  --line: #dfe3ea;
  --text: #18233a;
  --muted: #637089;
  --ok: #14703c;
  --ok-bg: #dcf3e3;
  --warn: #8a5a00;
  --warn-bg: #fff1cc;
  --bad: #a02525;
  --bad-bg: #fbe0e0;
  --info: #1f4e79;
  --info-bg: #dbe6f7;
}
* { box-sizing: border-box; }
/* Must beat any rule that sets display - otherwise [hidden] elements stay visible (the same bug the
   CTOA model hit with its modal backdrop). */
[hidden] { display: none !important; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, sans-serif; font-size: 14px; background: var(--bg); color: var(--text); }
a { color: var(--info); }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: .92rem; margin: 14px 0 6px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); background: var(--bad-bg); padding: 8px 10px; border-radius: 6px; font-size: 13px; }

header { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px 20px; background: linear-gradient(120deg, var(--navy), var(--navy-2)); color: #fff; border-bottom: 3px solid var(--gold); flex-wrap: wrap; }
.brand-block { display: flex; align-items: center; gap: 12px; }
.brand-block img { height: 48px; width: 48px; object-fit: cover; border-radius: 50%; background: #fff; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.brand-sub { font-size: 11px; color: #e7cf98; letter-spacing: .08em; text-transform: uppercase; }
.header-right { display: flex; align-items: center; gap: 12px; font-size: 13px; flex-wrap: wrap; }
.badge-pill { font-size: 11px; padding: 4px 10px; border-radius: 20px; background: #ffffff22; }
.badge-pill.ok { background: #19855b88; }
button.ghost { background: transparent; color: #fff; border: 1px solid #ffffff55; }
button.ghost:hover { background: #ffffff22; }

nav { display: flex; background: var(--navy); overflow-x: auto; }
nav button { background: none; border: none; border-radius: 0; color: #cdd6ea; padding: 12px 18px; font-size: 14px; white-space: nowrap; }
nav button:hover { color: #fff; background: #ffffff10; }
nav button.active { background: var(--bg); color: var(--navy); font-weight: 600; box-shadow: inset 0 3px 0 var(--gold); }

main { padding: 20px; }
.page { display: none; }
.page.active { display: block; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 18px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 18px; align-items: start; }
.grid-2 > .panel { margin-bottom: 0; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar h2 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions.right { justify-content: flex-end; margin-top: 12px; }

button { font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; }
button:hover { border-color: #b9c1cf; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
button.primary:hover { background: var(--navy-2); }
button.danger { color: var(--bad); border-color: #e6b5b5; }
button.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
button.link { border: none; background: none; color: var(--info); padding: 2px 4px; }
button.link.danger { color: var(--bad); }
button.icon { border: none; background: none; font-size: 22px; line-height: 1; padding: 0 6px; }
button.wide { width: 100%; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
label.inline-label { flex-direction: row; align-items: center; gap: 8px; }
input, select, textarea { font: inherit; font-size: 14px; color: var(--text); padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c8962e66; border-color: var(--gold); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--navy); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 12px; }
.entry-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.entry-form label { flex: 1 1 160px; }
.entry-form label.narrow { flex: 0 0 90px; }
.entry-form label.grow { flex: 3 1 240px; }
.entry-form label.check { flex: 0 0 auto; padding-bottom: 8px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; border-bottom: 2px solid var(--line); padding: 8px; white-space: nowrap; }
td { border-bottom: 1px solid var(--line); padding: 8px; vertical-align: top; }
tr:hover td { background: #fafbfd; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: none; }
.table-wrap { overflow-x: auto; }
.empty { padding: 18px; text-align: center; color: var(--muted); }

.status { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.status.Draft { background: #eceff3; color: #4d5870; }
.status.Submitted { background: var(--info-bg); color: var(--info); }
.status.Approved { background: var(--ok-bg); color: var(--ok); }
.status.Rejected { background: var(--bad-bg); color: var(--bad); }
.status.Invoiced { background: var(--gold-soft); color: #7a5813; }
.status.x-DRAFT, .status.x-SUBMITTED { background: var(--info-bg); color: var(--info); }
.status.x-AUTHORISED { background: var(--warn-bg); color: var(--warn); }
.status.x-PAID { background: var(--ok-bg); color: var(--ok); }
.status.x-DELETED, .status.x-VOIDED { background: var(--bad-bg); color: var(--bad); }
.status.x-none { background: #eceff3; color: #4d5870; }
.flag { color: var(--warn); font-size: 11px; font-weight: 600; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: 8px; padding: 14px 16px; }
.kpi small { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.kpi b { display: block; font-size: 22px; margin-top: 4px; color: var(--navy); font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12px; color: var(--muted); }
.alert { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; font-size: 13px; }
.alert button { margin-left: 8px; }

.week-nav { display: flex; align-items: center; gap: 6px; }
.week-nav b { margin-left: 8px; font-size: 15px; }
.range-picker { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.range-picker #tsCustom:not([hidden]) { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.day.static { cursor: default; }
.day.static:hover { border-color: var(--line); }
.week-grid { display: grid; grid-template-columns: repeat(7, 1fr) 1.1fr; gap: 8px; }
.day { border: 1px solid var(--line); border-radius: 8px; padding: 10px; text-align: center; cursor: pointer; background: #fff; }
.day:hover { border-color: var(--gold); }
.day.today { border-color: var(--navy); box-shadow: inset 0 3px 0 var(--navy); }
.day.selected { background: var(--gold-soft); border-color: var(--gold); }
.day small { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.day b { display: block; font-size: 20px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.day.total { background: var(--navy); color: #fff; cursor: default; border-color: var(--navy); }
.day.total small { color: #e7cf98; }

.modal-backdrop { position: fixed; inset: 0; background: #0f214766; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; padding: 18px 20px; box-shadow: 0 20px 50px #0003; }
.modal.wide { max-width: 980px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-head h2 { margin: 0; }
.modal .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal .form-grid .full { grid-column: 1 / -1; }
.modal .actions { justify-content: flex-end; margin-top: 16px; }
.preview-box { background: var(--bg); border-radius: 8px; padding: 10px 12px; margin: 10px 0; font-size: 13px; }
.preview-box dt { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.preview-box dd { margin: 0 0 6px; font-weight: 600; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 8px 24px #0003; z-index: 100; max-width: 420px; font-size: 13px; }
.toast.bad { background: var(--bad); }

.auth-overlay { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--navy); }
.auth-overlay::before { content: ""; position: absolute; inset: 0; background: url('/assets/logo.png') repeat; background-size: 80px; opacity: .05; }
.auth-card { position: relative; z-index: 1; width: 100%; max-width: 380px; background: #fff; border-radius: 12px; overflow: hidden; box-shadow: 0 24px 60px #0006; }
.auth-head { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 3px solid var(--gold); }
.auth-head img { width: 56px; height: 56px; object-fit: cover; border-radius: 50%; }
.auth-head b { display: block; font-size: 17px; letter-spacing: .06em; text-transform: uppercase; color: var(--navy); }
.auth-head small { color: var(--gold); letter-spacing: .1em; text-transform: uppercase; font-size: 11px; font-weight: 600; }
.auth-body { display: flex; flex-direction: column; gap: 12px; padding: 20px 22px; }
.auth-body h2 { margin: 0; }
.auth-body p { margin: 0; font-size: 13px; }
.auth-foot { background: var(--navy); color: #e7cf98; text-align: center; font-size: 11px; letter-spacing: .2em; text-transform: uppercase; padding: 8px; }

/* Offline / waiting-to-upload notice under the tabs. */
.offline-banner { background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid #ecd9a3; padding: 10px 20px; font-size: 13px; font-weight: 600; }
.offline-banner.bad { background: var(--bad-bg); color: var(--bad); border-color: #e6b5b5; }
.status.NotSynced { background: var(--warn-bg); color: var(--warn); }
.status.InInbox { background: var(--info-bg); color: var(--info); white-space: normal; }

/* In-app PDF viewer (phones / installed app). */
.pdf-viewer { position: fixed; inset: 0; z-index: 150; background: #3a4150; display: flex; flex-direction: column; }
.pdf-viewer-bar { display: flex; align-items: center; gap: 10px; background: var(--navy); color: #fff; border-bottom: 3px solid var(--gold);
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left)); }
.pdf-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 15px; text-align: center; }
.pdf-close, .pdf-share { background: #ffffff1f; color: #fff; border: 1px solid #ffffff55; border-radius: 8px; padding: 9px 14px; font-size: 16px; font-weight: 600; }
.pdf-close { min-width: 96px; }
.pdf-share { min-width: 80px; }
.pdf-pages { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 12px 8px max(16px, env(safe-area-inset-bottom)); }
.pdf-pages canvas { display: block; width: 100%; height: auto; margin: 0 auto 12px; background: #fff; box-shadow: 0 2px 10px #0006; }
.pdf-pages .pdf-msg { color: #fff; text-align: center; padding: 40px 16px; font-size: 15px; }

/* Installed iPhone app: the status bar is drawn over the page (black-translucent), so keep content
   clear of the notch / home indicator. env() is 0 everywhere else. */
header { padding-top: max(10px, env(safe-area-inset-top)); padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
main { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
.toast { bottom: max(20px, env(safe-area-inset-bottom)); }

@media (max-width: 720px) {
  main { padding: 12px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  /* iOS Safari zooms into any field with text under 16px when it's tapped - keep them at 16px. */
  input, select, textarea { font-size: 16px; }
  /* Compact header so the timesheet starts higher on a phone. */
  header { padding-bottom: 8px; gap: 8px; }
  .brand-block img { width: 38px; height: 38px; }
  .brand-name { font-size: 15px; }
  .header-right { gap: 8px; font-size: 12px; }
  .header-right button { padding: 5px 10px; font-size: 12px; }
  /* Bigger tap targets for the entry form and week navigation. */
  .entry-form label, .entry-form label.narrow, .entry-form label.grow { flex: 1 1 100%; }
  .entry-form label.check { padding-bottom: 0; }
  .entry-form button[type=submit] { width: 100%; padding: 12px; font-size: 16px; }
  .week-nav button { padding: 9px 14px; }
  .range-picker { margin-left: 0; width: 100%; }
  .toast { left: 12px; right: 12px; max-width: none; }
  /* My Timesheet entries as cards on a phone: one card per entry, label on the left, value on the right. */
  #weekEntries thead { display: none; }
  #weekEntries table, #weekEntries tbody, #weekEntries tfoot { display: block; }
  #weekEntries tbody tr { display: block; position: relative; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 8px 44px; margin-bottom: 10px; background: #fff; }
  #weekEntries tbody td { display: flex; justify-content: space-between; gap: 12px; border: none; padding: 3px 0; text-align: right; }
  #weekEntries tbody td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex-shrink: 0; }
  #weekEntries tbody td:first-child { position: absolute; left: 12px; top: 12px; padding: 0; }
  #weekEntries tbody td:first-child::before, #weekEntries tbody td:last-child::before { content: none; }
  #weekEntries tbody td:last-child { justify-content: flex-end; gap: 16px; padding-top: 6px; }
  #weekEntries tbody td:last-child:empty { display: none; }
  #weekEntries tfoot tr { display: flex; justify-content: space-between; padding: 6px 12px; }
  #weekEntries tfoot td { border: none; padding: 0; }
  #weekEntries tfoot td:empty { display: none; }
  #weekEntries .table-wrap { overflow: visible; }
  #weekEntries tr:hover td { background: none; }
  .week-grid { grid-template-columns: repeat(4, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .modal .form-grid { grid-template-columns: 1fr; }
}
.setup-steps { margin: 6px 0 10px; padding-left: 20px; line-height: 1.6; }
