:root {
  --forest: #1f3d2b;
  --forest-2: #2d5a3f;
  --moss: #6b8f4e;
  --sand: #f4efe6;
  --sand-2: #e8dfcf;
  --clay: #b8643a;
  --clay-2: #9c5130;
  --ink: #1d221e;
  --muted: #5d665f;
  --line: #ddd5c6;
  --white: #ffffff;
  --danger: #a3332b;
  --danger-bg: #fbe9e7;
  --ok-bg: #e6f0df;
  --warn-bg: #fdf3dc;
  --radius: 12px;
  --font-head: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font-body); color: var(--ink); background: var(--sand); line-height: 1.5; font-size: 15px; }
h1, h2, h3 { font-family: var(--font-head); color: var(--forest); margin: 0 0 0.5em; line-height: 1.2; font-weight: 600; }
a { color: var(--forest-2); }
[hidden] { display: none !important; }

/* ---------- Auth pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side {
  background: linear-gradient(160deg, var(--forest), #142a1d);
  color: var(--sand); padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
}
.auth-side h1 { color: var(--white); font-size: 2.2rem; }
.auth-side p { color: #cbd7c4; max-width: 40ch; }
.auth-side a { color: var(--sand); }
.auth-main { display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: min(420px, 100%); }
.auth-card h2 { font-size: 1.8rem; }
.auth-card .sub { color: var(--muted); margin-bottom: 24px; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-family: var(--font-head); font-weight: 600; font-size: 1.1rem; }
.brand img { width: 34px; height: 34px; }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 600; font-size: 0.88rem; }
.field .hint { color: var(--muted); font-size: 0.8rem; }
input, select, textarea {
  font: inherit; color: inherit; width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--white);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--moss); outline-offset: 1px; border-color: var(--moss); }
input[readonly] { background: var(--sand); color: var(--muted); }
textarea { min-height: 90px; resize: vertical; }
.radio-row { display: flex; gap: 10px; }
.radio-row label { flex: 1; display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--white); cursor: pointer; font-weight: 500; }
.radio-row input { width: auto; }
.radio-row label:has(input:checked) { border-color: var(--forest-2); background: var(--ok-bg); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 999px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  background: var(--forest); color: var(--white);
}
.btn:hover { background: var(--forest-2); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.accent { background: var(--clay); }
.btn.accent:hover { background: var(--clay-2); }
.btn.ghost { background: transparent; color: var(--forest); border-color: var(--line); }
.btn.ghost:hover { background: var(--sand-2); }
.btn.danger { background: transparent; color: var(--danger); border-color: #e6c3bf; }
.btn.danger:hover { background: var(--danger-bg); }
.btn.sm { padding: 6px 12px; font-size: 0.85rem; }

.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 0.92rem; }
.alert.error { background: var(--danger-bg); color: var(--danger); }
.alert.ok { background: var(--ok-bg); color: var(--forest); }
.alert.warn { background: var(--warn-bg); color: #7a5a12; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--forest); color: var(--sand); padding: 20px 14px; display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { color: var(--white); padding: 0 8px; }
.sidebar nav { display: grid; gap: 2px; }
.sidebar .nav-label { font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: #9fb397; padding: 14px 10px 6px; }
.sidebar nav a { color: #e3eadf; text-decoration: none; padding: 9px 12px; border-radius: 8px; font-weight: 500; display: flex; justify-content: space-between; align-items: center; }
.sidebar nav a:hover { background: rgba(255,255,255,0.08); }
.sidebar nav a.active { background: rgba(255,255,255,0.15); color: var(--white); }
.sidebar .badge { background: var(--clay); color: var(--white); border-radius: 999px; font-size: 0.72rem; padding: 1px 8px; }
.sidebar .me { margin-top: auto; font-size: 0.85rem; color: #cbd7c4; padding: 0 8px; }
.sidebar .me strong { color: var(--white); display: block; overflow-wrap: anywhere; }
.sidebar .me .btn { margin-top: 10px; background: rgba(255,255,255,0.1); width: 100%; }
.topbar-mobile { display: none; }

.main { padding: 28px clamp(16px, 3vw, 40px); min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 1.8rem; }
.page-head .sub { color: var(--muted); margin: 2px 0 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.toolbar select, .toolbar input { width: auto; }

.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.card h2 { font-size: 1.2rem; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--white); }
.seg button { font: inherit; border: 0; background: transparent; padding: 8px 16px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--forest); color: var(--white); }

.period-nav { display: inline-flex; align-items: center; gap: 6px; }
.period-nav .label { font-weight: 600; min-width: 210px; text-align: center; }
.icon-btn { border: 1px solid var(--line); background: var(--white); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 1.1rem; color: var(--forest); }
.icon-btn:hover { background: var(--sand-2); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.stat .v { font-family: var(--font-head); font-size: 1.6rem; color: var(--forest); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--white); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); background: #faf7f1; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
tr.subtotal td { background: #faf7f1; font-weight: 600; }
tfoot td { font-weight: 700; background: var(--sand-2); }
.desc-cell { max-width: 360px; white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.pill.pending { background: var(--warn-bg); color: #7a5a12; }
.pill.approved { background: var(--ok-bg); color: var(--forest); }
.pill.disabled { background: #eee; color: #666; }
.pill.admin { background: #f6e2d6; color: var(--clay-2); }
.pill.Project { background: #e2ebf5; color: #274b72; }
.pill.Billable { background: #f6e2d6; color: var(--clay-2); }

/* ---------- Calendar ---------- */
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-head div { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 8px; text-align: center; }
.cal-grid { border-top: 1px solid var(--line); border-left: 1px solid var(--line); background: var(--white); border-radius: var(--radius); overflow: hidden; }
.cal-day { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); min-height: 116px; padding: 6px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; position: relative; }
.cal-day:hover { background: #fbf9f4; }
.cal-day.out { background: #f7f4ee; color: #aaa; cursor: default; }
.cal-day.out-period { background: #fbfaf7; }
.cal-day.in-period { box-shadow: inset 0 0 0 2px rgba(107, 143, 78, 0.35); }
.cal-day.today .dnum { background: var(--clay); color: var(--white); }
.cal-day .top { display: flex; justify-content: space-between; align-items: center; }
.cal-day .dnum { font-weight: 600; font-size: 0.85rem; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; }
.cal-day .dtotal { font-size: 0.75rem; font-weight: 700; color: var(--forest); }
.cal-entry { font-size: 0.75rem; padding: 3px 6px; border-radius: 6px; background: var(--ok-bg); color: var(--forest); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; text-align: left; font: inherit; font-size: 0.75rem; cursor: pointer; }
.cal-entry.Billable { background: #f6e2d6; color: var(--clay-2); }
.cal-entry.Project { background: #e2ebf5; color: #274b72; }
.cal-legend { display: flex; gap: 14px; font-size: 0.8rem; color: var(--muted); margin-top: 10px; flex-wrap: wrap; }
.cal-legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.cal-legend .lp::before { background: #e2ebf5; }
.cal-legend .lb::before { background: #f6e2d6; }
.cal-legend .lper::before { background: transparent; box-shadow: inset 0 0 0 2px rgba(107,143,78,.6); }

/* ---------- Notes ---------- */
.notes-panel { background: var(--warn-bg); border: 1px solid #efdca9; border-radius: var(--radius); padding: 14px 18px; margin-bottom: 20px; }
.notes-panel summary { cursor: pointer; font-weight: 600; color: #6b4e0f; }
.notes-panel .note { margin-top: 12px; }
.notes-panel .note h3 { font-family: var(--font-body); font-size: 0.95rem; margin: 0 0 4px; color: #5a420d; }
.notes-panel .note p { margin: 0; white-space: pre-wrap; }

/* ---------- Dialog ---------- */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100% - 24px)); box-shadow: 0 20px 60px rgba(0,0,0,0.25); }
dialog::backdrop { background: rgba(20, 30, 22, 0.45); }
dialog form { padding: 22px 24px; }
dialog .dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
dialog .dlg-head h2 { margin: 0; font-size: 1.3rem; }
dialog .dlg-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; }
dialog .dlg-actions .right { display: flex; gap: 8px; margin-left: auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--forest); color: var(--white); padding: 10px 18px; border-radius: 999px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); z-index: 100; font-weight: 500; }
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-side { padding: 28px 20px; }
  .auth-side .long { display: none; }
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: none; }
  .topbar-mobile { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--forest); color: var(--white); }
  .topbar-mobile .brand { color: var(--white); }
  .topbar-mobile button { background: none; border: 0; color: var(--white); font-size: 1.5rem; cursor: pointer; }
  .cal-day { min-height: 76px; padding: 4px; }
  .cal-entry { display: none; }
  .cal-day .dtotal { font-size: 0.7rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .period-nav .label { min-width: 0; }
}

@media print {
  .sidebar, .topbar-mobile, .toolbar, .no-print, .notes-panel, td.actions, th.actions { display: none !important; }
  .app { display: block; }
  .main { padding: 0; }
  .card { border: 0; padding: 0; }
  body { background: #fff; font-size: 11pt; }
}
.auth-card .foot { margin-top: 18px; }
.main > .toolbar.no-print { margin-bottom: 14px; }

/* ---------- Per-employee colours (admin "All employees" calendar) ---------- */
.emp-c0 { --emp: #2f6db5; } .emp-c1 { --emp: #b8643a; } .emp-c2 { --emp: #4f8a3a; } .emp-c3 { --emp: #8a4fb5; }
.emp-c4 { --emp: #c0392b; } .emp-c5 { --emp: #138d90; } .emp-c6 { --emp: #a17a12; } .emp-c7 { --emp: #5d6d7e; }
.cal-entry[class*="emp-c"] { border-left: 4px solid var(--emp); }
.cal-people { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 0.8rem; color: var(--muted); margin: 0 0 10px; }
.emp-tag { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); }
.emp-tag::before { content: ''; width: 10px; height: 10px; border-radius: 3px; background: var(--emp); }

/* ---------- Reports ---------- */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 14px; }
.filters .field { margin-bottom: 12px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: auto; }
tr.lvl-0 td { font-weight: 700; background: #faf7f1; }
tr.lvl-1 td:first-child { padding-left: 28px; }
tr.lvl-2 td:first-child { padding-left: 48px; }
tr.detail td { font-size: 0.85rem; color: var(--muted); }
tr.detail td:first-child { padding-left: 64px; }
.card details summary { cursor: pointer; font-weight: 600; color: var(--forest); margin: 4px 0 10px; }

/* ---------- Collapsible sections (start minimized) ---------- */
details.fold { border-radius: var(--radius); margin-bottom: 14px; }
details.fold > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: var(--radius); }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: '▸'; display: inline-block; transition: transform 0.15s; color: var(--muted); }
details.fold[open] > summary::before { transform: rotate(90deg); }
details.fold.notes-panel { padding: 0; }
details.fold.notes-panel > summary { color: #6b4e0f; }
details.fold.notes-panel[open] { padding-bottom: 12px; }
details.fold.notes-panel .note { margin: 0 18px 10px; }
details.fold.totals-panel { background: var(--white); border: 1px solid var(--line); }
details.fold.totals-panel > summary { color: var(--forest); }
details.fold.totals-panel .stats { margin: 0; padding: 0 14px 14px; }
.period-bar { margin-bottom: 14px; }

/* ---------- Paper-style sheet (timesheet & expenses) ---------- */
.sheet { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 28px 28px 20px; margin-bottom: 24px; box-shadow: 0 2px 10px rgba(30, 40, 30, 0.06); position: relative; }
.sheet-tools { position: absolute; top: 14px; right: 14px; display: flex; gap: 6px; }
.sheet-company { text-align: center; font-weight: 700; font-size: 1.15rem; margin-bottom: 14px; color: var(--ink); }
.sheet-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 14px 28px; margin-bottom: 18px; }
.sheet-meta .meta { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.meta-label { font-weight: 700; padding-top: 2px; }
.meta-field { display: inline-flex; flex-direction: column; align-items: center; min-width: 120px; }
.meta-line { border-bottom: 1.5px solid var(--ink); width: 100%; text-align: center; padding: 0 8px 2px; font-size: 1.05rem; color: #1b3a8c; }
.meta-cap { font-size: 0.72rem; color: var(--muted); min-height: 1em; }
.sheet-table { width: 100%; border-collapse: collapse; table-layout: fixed; border: 1.5px solid #333; }
.sheet-table th { background: #fff; color: var(--ink); font-size: 0.78rem; text-transform: none; letter-spacing: 0; font-weight: 700; text-align: center; border: 1px solid #555; padding: 6px 4px; white-space: normal; }
.sheet-table td { border: 1px solid #888; padding: 0; height: 34px; vertical-align: middle; }
.sheet-table td input, .sheet-table td select { border: 0; border-radius: 0; background: transparent; padding: 6px 6px; height: 34px; font-size: 0.92rem; color: #1b3a8c; }
.sheet-table td input:focus, .sheet-table td select:focus { outline: 2px solid var(--moss); outline-offset: -2px; background: #f6faf2; }
.sheet-table td .auto { display: block; padding: 6px; font-size: 0.9rem; color: #1b3a8c; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-table .c-day { width: 9%; } .sheet-table .c-date { width: 12%; } .sheet-table .c-loc { width: 21%; }
.sheet-table .c-addr { width: 14%; } .sheet-table .c-type { width: 10%; } .sheet-table .c-hours { width: 7%; }
.sheet-table .c-desc { width: auto; } .sheet-table .c-act { width: 52px; text-align: center; white-space: nowrap; }
.sheet-table .c-hours input { text-align: center; }
.row-status { display: inline-block; width: 18px; font-weight: 700; }
tr.is-saved .row-status { color: var(--moss); }
tr.is-saving .row-status { color: var(--muted); }
tr.is-error .row-status, tr.is-incomplete .row-status { color: var(--danger); }
tr.is-incomplete td, tr.is-error td { background: #fff7f5; }
.row-del { border: 0; background: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 2px 4px; }
.row-del:hover { color: var(--danger); }
.sheet-total { display: flex; justify-content: center; align-items: center; gap: 10px; margin: 18px 0 6px; font-weight: 700; }
.total-box { border: 1.5px solid #333; min-width: 72px; padding: 4px 12px; text-align: center; font-size: 1.15rem; color: #1b3a8c; }
.sheet-hint { text-align: center; color: var(--muted); font-size: 0.8rem; margin: 6px 0 0; }
.expense-table td { padding: 6px; font-size: 0.9rem; color: #1b3a8c; overflow-wrap: anywhere; }
.expense-table tr.clickable { cursor: pointer; }
@media (hover: hover) { .expense-table tr.clickable:hover td { background: #f6faf2; } }
.thumbs { display: flex; gap: 4px; align-items: center; }
.thumbs img { width: 34px; height: 34px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); }
.thumbs .more { font-size: 0.75rem; color: var(--muted); }

/* ---------- Receipt photos in the expense dialog ---------- */
.field .label { font-weight: 600; font-size: 0.88rem; }
.photo-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.photo { position: relative; width: 84px; height: 84px; }
.photo img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.photo.new img { border-color: var(--moss); }
.photo-del { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--danger); color: #fff; cursor: pointer; line-height: 1; }
.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.photo-actions .btn { cursor: pointer; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; }

/* ---------- Phones: each sheet line becomes a card ---------- */
@media (max-width: 760px) {
  .main { padding: 16px 12px; }
  .page-head h1 { font-size: 1.5rem; }
  .sheet { padding: 18px 12px 14px; }
  .sheet-tools { position: static; justify-content: flex-end; margin-bottom: 6px; }
  .sheet-table, .sheet-table tbody { display: block; border: 0; }
  .sheet-table thead { display: none; }
  .sheet-table tr { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid #999; border-radius: 8px; margin-bottom: 10px; padding: 4px 0; position: relative; background: #fff; }
  .sheet-table td { display: block; border: 0; height: auto; width: auto !important; padding: 0 8px; }
  .sheet-table td::before { content: attr(data-label); display: block; font-size: 0.7rem; color: var(--muted); padding-top: 4px; }
  .sheet-table td.c-loc, .sheet-table td.c-addr, .sheet-table td.c-desc { grid-column: 1 / -1; }
  .sheet-table td input, .sheet-table td select { border-bottom: 1px solid var(--line); padding: 4px 0; font-size: 16px; }
  .sheet-table td.c-act { position: absolute; top: 2px; right: 2px; width: auto; }
  .sheet-table td.c-act::before { content: none; }
  .sheet-table tr.blank:not(.first-blank) { display: none; }
  .sheet-table tr.blank.first-blank::after { content: 'New line'; position: absolute; top: -9px; left: 10px; background: var(--moss); color: #fff; font-size: 0.7rem; padding: 1px 8px; border-radius: 999px; }
  .expense-table td { padding: 2px 8px; }
  .expense-table td.empty { grid-column: 1 / -1; }
  .expense-table td.empty::before { content: none; }
  .meta-field { min-width: 90px; }
}

@media print {
  .sheet { border: 0; box-shadow: none; padding: 0; }
  .sheet-table td input, .sheet-table td select { color: #000; -webkit-appearance: none; appearance: none; }
  .row-status, .row-del, .sheet-hint { display: none !important; }
  details.fold { display: none; }
}
