:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #dfe3e8;
    --text: #1c2430;
    --muted: #6b7684;
    --primary: #1f6f4a;
    --primary-ink: #ffffff;
    --danger: #b3261e;
    --ok: #1f6f4a;
    --warn: #b7791f;
    --radius: 8px;
    color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
}
a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
code { background: #eef1f4; padding: .1rem .35rem; border-radius: 4px; font-size: .95em; }
.muted { color: var(--muted); }

/* Shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
    background: #14281e; color: #d7e4dc;
    display: flex; flex-direction: column; padding: 1rem .75rem; gap: 1rem;
}
.sidebar .brand { color: #fff; font-weight: 700; font-size: 1.15rem; text-decoration: none; padding: .25rem .5rem; }
.sidebar nav { display: flex; flex-direction: column; gap: .15rem; }
.sidebar nav a {
    color: #d7e4dc; text-decoration: none; padding: .5rem .6rem; border-radius: 6px;
}
.sidebar nav a:hover { background: rgba(255,255,255,.08); }
.sidebar nav a.active { background: rgba(255,255,255,.16); color: #fff; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: .5rem; padding: 0 .5rem; }
.sidebar-foot .who { display: flex; flex-direction: column; font-size: .9rem; }
.sidebar-foot .who span { color: #9fb5a8; }
.sidebar-foot .btn-ghost { color: #d7e4dc; padding-left: 0; }
.content { padding: 1.5rem 2rem; max-width: 1100px; width: 100%; }

@media (max-width: 800px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; }
    .sidebar nav { flex-direction: row; flex-wrap: wrap; }
    .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
    .content { padding: 1rem; }
}

/* Auth */
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card {
    width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.5rem;
}
.auth-card .brand { font-weight: 700; font-size: 1.3rem; color: var(--primary); margin-bottom: .75rem; }

/* Cards, tables */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem 1.25rem; margin-bottom: 1.25rem;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }
td.actions { white-space: nowrap; text-align: right; }
.empty { padding: 2rem; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }

/* Forms */
label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--muted); margin-bottom: .75rem; }
input, select, textarea {
    font: inherit; color: var(--text); padding: .5rem .6rem; border: 1px solid var(--border);
    border-radius: 6px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 1rem; }
.validation-message { color: var(--danger); font-size: .85rem; }
.invalid { border-color: var(--danger); }

/* Buttons, badges, alerts */
.btn {
    display: inline-block; font: inherit; padding: .5rem .9rem; border-radius: 6px; border: 1px solid var(--border);
    background: #fff; color: var(--text); cursor: pointer; text-decoration: none;
}
.btn:hover { background: #f0f2f4; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #185a3c; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: default; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.badge-ok { background: #e2f3ea; color: var(--ok); }
.badge-off { background: #eceff2; color: var(--muted); }
.badge-warn { background: #fbefd6; color: var(--warn); }
.alert { padding: .75rem 1rem; border-radius: 6px; margin: .75rem 0; }
.alert-error { background: #fbe9e7; color: var(--danger); }
.alert-success { background: #e2f3ea; color: #164d33; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: .5rem 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* Blazor error bar */
#blazor-error-ui {
    display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
    background: #fff4ce; color: #3b2f00; padding: .6rem 1.25rem; box-shadow: 0 -1px 0 #e6d9a2;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

/* Page furniture */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { margin-bottom: .25rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.page-head .actions, .section-head .actions, .form-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.form-actions { margin-top: .5rem; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .5rem; }
.section-head h2 { margin: 0; }
.crumbs { margin: 0 0 .25rem; font-size: .85rem; }
.toolbar { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 360px; }
label.inline { flex-direction: row; align-items: center; gap: .4rem; margin: 0; color: var(--text); }
label.inline input { width: auto; }
.narrow { max-width: 640px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 1rem; }
.grid-2.top { align-items: start; }
.prewrap { white-space: pre-wrap; }
.card-table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-table th:first-child, .card-table td:first-child { padding-left: 1rem; }
tr.archived td { color: var(--muted); }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
.badge-info { background: #e3ecf7; color: #1f4b8f; }
.badge-danger { background: #fbe9e7; color: var(--danger); }
.alert-warn { background: #fbefd6; color: #6b4a0f; }

/* Dashboard cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.project-card {
    display: flex; flex-direction: column; gap: .35rem; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem; color: var(--text); text-decoration: none;
}
.project-card:hover { border-color: var(--primary); }
.project-card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.project-card-title { font-size: 1.05rem; }
.project-card-foot { display: flex; gap: .75rem; flex-wrap: wrap; font-size: .85rem; margin-top: .25rem; }

/* Week schedule */
.week-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .5rem; margin-bottom: 1.25rem; }
.day {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .5rem; min-height: 8rem; display: flex; flex-direction: column; gap: .4rem;
}
.day.today { border-color: var(--primary); box-shadow: inset 0 2px 0 var(--primary); }
.day-head { display: flex; justify-content: space-between; align-items: baseline; gap: .25rem; font-size: .85rem; }
.day-empty { margin: 0; }
.visit-chip {
    border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: 6px;
    padding: .35rem .45rem; font-size: .85rem; display: flex; flex-direction: column; gap: .1rem;
    background: #fbfcfd; overflow-wrap: anywhere;
}
.visit-time { font-weight: 600; }
.visit-crew { color: var(--muted); }
.visit-form { border-bottom: 1px solid var(--border); padding-bottom: .75rem; margin-bottom: .75rem; }

@media (max-width: 1000px) {
    .week-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .day { min-height: 0; }
}
@media (max-width: 800px) {
    .week-grid { grid-template-columns: 1fr; }
}

/* Crew chips */
.chip-row { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem; }
.chip-toggle {
    flex-direction: row; align-items: center; gap: .35rem; margin: 0; color: var(--text);
    border: 1px solid var(--border); border-radius: 999px; padding: .3rem .7rem; background: #fff; cursor: pointer;
}
.chip-toggle input { width: auto; }
.chip-toggle.on { border-color: var(--primary); background: #e2f3ea; }

/* Line tables and money */
.line-table th.num, .line-table td.num, th.num, td.num { text-align: right; white-space: nowrap; }
.line-table input, .line-table select { padding: .3rem .4rem; }
.line-table td.num input { text-align: right; min-width: 5rem; }
.line-table td { vertical-align: middle; }
tr.past td { color: var(--muted); }
.totals { display: grid; grid-template-columns: 1fr max-content; gap: .2rem 1rem; margin: .75rem 0 0; max-width: 22rem; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; }
.totals .grand { font-weight: 700; color: var(--text); border-top: 1px solid var(--border); padding-top: .3rem; }

/* Client link */
.link-box { display: flex; align-items: flex-end; gap: .5rem; flex-wrap: wrap; }
.link-box label { flex: 1 1 20rem; margin: 0; }
.link-box input { background: #f7f8f9; }

/* Client-facing pages */
.public-shell { min-height: 100%; padding: 1.5rem 1rem 2rem; display: flex; flex-direction: column; align-items: center; }
.public-card {
    width: 100%; max-width: 720px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.5rem;
}
.public-card h1 { font-size: 1.35rem; }
.public-card h2 { margin-top: 1.5rem; }
.public-company { font-weight: 700; color: var(--primary); margin: 0 0 .5rem; }
.public-foot { margin: 1rem 0 0; font-size: .85rem; }
.alert-neutral { background: #eceff2; color: var(--text); }
.addons { list-style: none; margin: .5rem 0; padding: 0; }
.addons li {
    display: flex; justify-content: space-between; align-items: center; gap: .75rem;
    border-bottom: 1px solid var(--border); padding: .5rem 0;
}

@media (max-width: 480px) {
    .public-shell { padding: .75rem .5rem 1.5rem; }
    .public-card { padding: 1rem; }
    .line-table th, .line-table td { padding: .4rem .25rem; }
}

/* Crew invites */
.invite { display: flex; gap: 1.25rem; align-items: flex-start; flex-wrap: wrap; margin-bottom: 1rem; }
.invite-link { flex: 1 1 22rem; min-width: 0; }
.invite-link p { margin: .35rem 0 0; }
.qr { display: block; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; padding: .4rem; }

/* Field activity */
.totals-row { margin-bottom: 1rem; }
.stat {
    display: flex; flex-direction: column; gap: .15rem;
    border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .8rem; background: #fbfcfd;
}
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 1.4rem; font-weight: 700; }

.timeline { list-style: none; margin: .5rem 0 0; padding: 0; }
.timeline-item {
    display: grid; grid-template-columns: 11rem 1fr; gap: .25rem 1rem;
    padding: .6rem 0; border-bottom: 1px solid var(--border);
}
.timeline-item:last-child { border-bottom: 0; }
.timeline-when { display: flex; flex-direction: column; font-size: .85rem; }
.timeline-body { display: flex; flex-direction: column; gap: .35rem; align-items: flex-start; }
.timeline-body .badge { align-self: flex-start; }
.thumb {
    max-width: 200px; max-height: 200px; border-radius: 6px; border: 1px solid var(--border); display: block;
}

@media (max-width: 640px) {
    .timeline-item { grid-template-columns: 1fr; }
    .timeline-when { flex-direction: row; gap: .5rem; }
}

.auth-alt { margin: 1rem 0 0; text-align: center; font-size: .9rem; }
