:root {
  --navy: #1F3864;
  --accent: #1F3864;
  --accent-text: #ffffff;
  --bg: #f3f4f7;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #5d6472;
  --border: #d9dde4;
  --danger: #b3261e;
  --ok: #1e6b35;
  --warn-bg: #fff4d6;
  --warn-text: #6b4e00;
  --radius: 12px;
  --tabs-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #8fa9e0;
    --accent-text: #0d1526;
    --bg: #0f1218;
    --surface: #1a1e27;
    --text: #e9ecf2;
    --muted: #9aa3b2;
    --border: #2e3442;
    --danger: #f2b8b5;
    --ok: #8fd19e;
    --warn-bg: #3a3011;
    --warn-text: #f3dc8a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
}
.hidden { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--navy); color: #fff;
}
.topbar h1 { margin: 0; font-size: 1.2rem; font-weight: 600; }
.link { background: none; border: 0; color: inherit; font: inherit; font-size: .95rem; padding: 8px; min-height: 44px; }

main { padding: 16px; max-width: 40rem; margin: 0 auto; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 1.05rem; }

label { display: block; font-weight: 600; font-size: .95rem; margin: 14px 0 6px; }
label:first-child { margin-top: 0; }
input, select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  display: block; width: 100%; min-height: 52px; margin-top: 18px;
  font: inherit; font-weight: 600; color: var(--accent-text); background: var(--accent);
  border: 0; border-radius: 12px; cursor: pointer;
}
.btn:disabled { opacity: .55; }
.btn.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }

.error { color: var(--danger); margin: 10px 0 0; }
.muted { color: var(--muted); }
.warn { background: var(--warn-bg); color: var(--warn-text); padding: 10px 12px; border-radius: 10px; margin: 12px 0 0; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row2.tight { gap: 6px; }
.row2.tight select { padding: 10px 6px; }
.steppers .btn { margin-top: 12px; min-height: 44px; }
@media (max-width: 420px) { .card > .row2:first-child { grid-template-columns: 1fr; } }

/* Summary table */
.sumtable { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.sumtable th, .sumtable td { padding: 10px 6px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.sumtable th:first-child, .sumtable td:first-child { text-align: left; }
.sumtable th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.sumtable tr.zero td { color: var(--muted); }
.sumtable tr.clickable { cursor: pointer; }
.sumtable tr.sel td { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.sumtable tfoot td { font-weight: 700; border-bottom: 0; }
.detail dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0; font-variant-numeric: tabular-nums; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; text-align: right; }
.detail dd.total { font-weight: 700; }

/* Bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabs button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: 0; font: inherit; font-size: .75rem; color: var(--muted);
}
.tabs .ico { font-size: 1.25rem; line-height: 1; font-weight: 700; }
.tabs button[aria-current="page"] { color: var(--accent); font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px;
  background: #16181d; color: #fff; font-weight: 600; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Entry form */
.ferr { color: var(--danger); font-size: .9rem; margin: 4px 0 0; }
.ferr:empty { display: none; }
.hint { color: var(--muted); margin: 14px 0 0; min-height: 1.4em; font-variant-numeric: tabular-nums; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chips:empty { display: none; }
.chips button {
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-height: 36px; padding: 6px 12px; font: inherit; font-size: .9rem;
  color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 18px;
}
.hoursrow { display: grid; grid-template-columns: 56px 1fr 56px; gap: 8px; }
.hoursrow input { text-align: center; font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.step { min-height: 48px; font-size: 1.5rem; font-weight: 600; color: var(--accent); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.quick { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 10px; }
.quick button {
  min-height: 48px; padding: 0; font: inherit; font-size: .95rem; font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--accent); background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.quick button.on { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }
@media (max-width: 360px) { .quick { grid-template-columns: repeat(4, 1fr); } }

/* Entries list */
.month { padding: 8px 0 0; overflow: hidden; }
.month h2 { display: flex; justify-content: space-between; padding: 4px 16px 8px; margin: 0; }
.month h2 span { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.entry {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; width: 100%;
  padding: 12px 16px; text-align: left; font: inherit; color: var(--text);
  background: none; border: 0; border-top: 1px solid var(--border); cursor: pointer;
}
.entry:active { background: var(--bg); }
.entry .when { font-size: .85rem; color: var(--muted); }
.entry .hrs { grid-row: span 2; align-self: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.entry .what { overflow-wrap: anywhere; }
.entry .rate { grid-column: 1; font-size: .85rem; color: var(--muted); }

/* More: lists and company/rate forms */
.list { padding: 8px 0 16px; overflow: hidden; }
.list h2 { padding: 4px 16px 8px; margin: 0; }
.list .btn { width: calc(100% - 32px); margin: 12px 16px 0; }
.pad { padding: 0 16px; }
.item {
  display: block; width: 100%; padding: 12px 16px; text-align: left; font: inherit; color: var(--text);
  background: none; border: 0; border-top: 1px solid var(--border); cursor: pointer;
}
.item:active { background: var(--bg); }
.item .name { display: block; font-weight: 600; }
.item .sub { display: block; font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.tag { display: inline-block; margin-left: 6px; padding: 1px 8px; font-size: .75rem; font-weight: 600; color: var(--muted); border: 1px solid var(--border); border-radius: 10px; vertical-align: middle; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid var(--accent); border-radius: 10px; overflow: hidden; }
.seg label { margin: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 48px; font-weight: 600; color: var(--accent); cursor: pointer; }
.seg input:checked + span { background: var(--accent); color: var(--accent-text); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -4px; }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 500; margin-top: 18px; }
label.check input { width: 22px; min-height: 22px; height: 22px; flex: none; accent-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }

/* Reports */
.btnrow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btnrow .btn { margin-top: 10px; }
.seg3 { grid-template-columns: repeat(3, 1fr); }
.card p.lead { margin: 0 0 4px; color: var(--muted); font-size: .95rem; }
.brand { display: flex; justify-content: center; margin: 8px 0 20px; }
.brand img { width: 168px; height: auto; padding: 14px; background: #fff; border-radius: 20px; }
