:root {
    color-scheme: light;
    --bg: #F3F5F4;
    --surface: #FFFFFF;
    --elevated: #E7ECE9;
    --text: #17211D;
    --muted: #52605A;
    --subtle: #6D7973;
    --border: #CBD4CF;
    --accent: #B94313;
    --accent-hover: color-mix(in srgb, var(--accent) 88%, var(--text));
    --success: #256D4A;
    --warning: #9A5B00;
    --danger: #B3261E;
    --info: #1C5D85;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --shadow: 0 8px 24px rgb(23 33 29 / 8%);
    --motion: 240ms cubic-bezier(0.16, 1, 0.3, 1);
    font-family: Barlow, "Segoe UI", sans-serif;
    font-size: 16px;
}

* { box-sizing: border-box; }
html { background: var(--bg); scroll-behavior: smooth; }
body { min-width: 320px; margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; }
body, button, input, select, textarea { font-family: Barlow, "Segoe UI", sans-serif; }
img, svg { max-width: 100%; }
a { color: var(--info); text-underline-offset: 3px; }
a:hover { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

h1, h2, h3, .brand, .metric strong {
    font-family: "Barlow Semi Condensed", "Arial Narrow", sans-serif;
    font-weight: 700;
    letter-spacing: -.015em;
    line-height: 1.12;
}
h1 { margin: 0 0 12px; font-size: clamp(1.75rem, 6vw, 2.25rem); }
h2 { margin: 32px 0 12px; font-size: 1.375rem; }
h3 { margin: 24px 0 8px; font-size: 1.125rem; }
p { max-width: 70ch; }
small { color: var(--subtle); font-size: .875rem; }

.skip-link { position: fixed; z-index: 80; top: 8px; left: 8px; padding: 12px 16px; transform: translateY(-160%); border-radius: var(--radius-md); background: var(--text); color: #fff; }
.skip-link:focus { transform: translateY(0); }

.app-header { position: sticky; z-index: 30; top: 0; border-bottom: 1px solid var(--border); background: rgb(255 255 255 / 96%); }
.app-header__inner { display: flex; min-height: 64px; align-items: center; justify-content: space-between; gap: 16px; width: min(100% - 32px, 1180px); margin: auto; padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: 1.375rem; text-decoration: none; }
.brand__mark { display: grid; width: 32px; height: 32px; place-items: center; border-radius: var(--radius-sm); background: var(--text); color: #fff; font-size: 1.125rem; }
.app-menu summary { display: grid; min-width: 48px; min-height: 48px; place-items: center; cursor: pointer; font-weight: 600; list-style: none; }
.app-menu summary::-webkit-details-marker { display: none; }
.app-menu__panel { position: fixed; z-index: 40; top: 64px; right: 0; left: 0; max-height: calc(100dvh - 64px); overflow: auto; padding: 16px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); border-bottom: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow); }
.app-menu:not([open]) .app-menu__panel { display: none; }
.nav-group { display: grid; gap: 2px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.nav-group summary { display: flex; min-height: 48px; align-items: center; justify-content: space-between; padding: 8px 12px; color: var(--subtle); font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; cursor: pointer; }
.nav-group:not([open]) > a { display: none; }
.nav-group a, .nav-logout { display: flex; min-height: 48px; align-items: center; padding: 8px 12px; border-radius: var(--radius-md); color: var(--text); font-weight: 500; text-decoration: none; }
.nav-group a[aria-current="page"] { background: var(--elevated); font-weight: 700; }
.nav-logout { margin-top: 12px; color: var(--danger); }
.operator-nav { display: flex; align-items: center; gap: 8px; }
.operator-nav a { display: grid; min-height: 48px; place-items: center; padding: 8px; color: var(--text); font-size: .875rem; font-weight: 600; }
.operator-nav__identity { display: none; color: var(--subtle); font-size: .875rem; }

.shell, .worker-shell { width: min(100% - 32px, 780px); margin: 0 auto; padding: 32px 0 64px; }
.shell--wide { width: min(100% - 32px, 1180px); }
.worker-shell { width: min(100% - 32px, 640px); padding-top: 20px; padding-bottom: calc(128px + env(safe-area-inset-bottom)); }
.app-public .shell { width: min(100% - 32px, 440px); padding-top: clamp(40px, 12vh, 96px); }
.app-public .shell > :first-child { margin-top: 0; }
.eyebrow { margin: 0 0 8px; color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.page-header { display: flex; flex-direction: column; gap: 16px; margin-bottom: 32px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.page-header p { margin: 0; color: var(--muted); }
.page-header__actions { display: flex; flex-wrap: wrap; gap: 8px; }

form:not(.inline-form), .form-stack { display: grid; gap: 20px; }
label { display: grid; gap: 8px; color: var(--text); font-weight: 600; }
input, select, textarea { width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text); font-size: 1rem; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 3px solid rgb(185 67 19 / 24%); outline-offset: 0; }
input[type="checkbox"], input[type="radio"] { width: 24px; min-height: 24px; margin: 0; accent-color: var(--accent); }
label:has(> input[type="checkbox"]), label:has(> input[type="radio"]) { display: flex; min-height: 48px; align-items: center; gap: 12px; font-weight: 500; }
fieldset { display: grid; gap: 8px; min-width: 0; margin: 0; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); }
legend { padding: 0 8px; font-weight: 700; }

button, .button { display: inline-flex; min-height: 48px; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border: 1px solid transparent; border-radius: var(--radius-md); background: var(--elevated); color: var(--text); font: inherit; font-weight: 700; line-height: 1.2; text-align: center; text-decoration: none; cursor: pointer; transition: background var(--motion), transform 120ms ease; }
button:hover, .button:hover { border-color: var(--border); background: #fff; color: var(--text); }
button:active, .button:active { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: .55; }
.button--primary, button[type="submit"] { background: var(--accent); color: #fff; }
.button--primary:hover, button[type="submit"]:hover { border-color: var(--accent); background: var(--accent-hover); color: #fff; }
.button--secondary, button.button--secondary, .worker-action--secondary, button.worker-action--secondary { border-color: var(--border); background: var(--surface); color: var(--text); }
.button--secondary:hover, button.button--secondary:hover, .worker-action--secondary:hover, button.worker-action--secondary:hover { border-color: var(--border); background: var(--elevated); color: var(--text); }
.button--quiet { background: transparent; color: var(--info); }
.button--danger { background: var(--danger); color: #fff; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions form { display: inline-flex; margin: 0; }

.notice, [role="alert"], .connectivity-status, .operation-status:not(:empty) { margin: 16px 0; padding: 12px 16px; border-left: 4px solid var(--info); border-radius: var(--radius-sm); background: #EEF5F8; }
[role="alert"], .notice--danger { border-left-color: var(--danger); background: #FAEFEE; color: #721B16; }
.notice--success { border-left-color: var(--success); background: #EEF6F2; }
.connectivity-status { border-left-color: var(--warning); background: #FBF4E8; color: #653C00; }
.operation-status:empty { display: none; }

.status-badge { display: inline-flex; min-height: 28px; align-items: center; padding: 2px 8px; border: 1px solid currentColor; border-radius: 9999px; background: #EEF5F8; color: var(--info); font-size: .8125rem; font-weight: 700; white-space: nowrap; }
.status-badge--finished, .status-badge--finalized, .status-badge--active, .status-badge--available, .status-badge--exported { background: #EEF6F2; color: var(--success); }
.status-badge--paused, .status-badge--pending, .status-badge--reviewed, .status-badge--planned { background: #FBF4E8; color: var(--warning); }
.status-badge--cancelled, .status-badge--inactive, .status-badge--urgent { background: #FAEFEE; color: var(--danger); }

.operation-list, .directory-list, .evidence-list { display: grid; margin: 0; padding: 0; border-top: 1px solid var(--border); list-style: none; }
.operation-row, .directory-row { position: relative; display: grid; min-height: 56px; gap: 4px; padding: 12px 12px 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; }
.operation-row::before { position: absolute; top: 0; bottom: 0; left: 0; width: 4px; background: var(--info); content: ""; }
.operation-row--urgent::before, .operation-row--overdue::before, .operation-row--cancelled::before { background: var(--danger); }
.operation-row--in_progress::before, .operation-row--finished::before { background: var(--success); }
.operation-row--paused::before, .operation-row--planned::before { background: var(--warning); }
.operation-row:hover, .directory-row:hover { background: var(--elevated); color: var(--text); }
.operation-row__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.operation-row__meta { color: var(--muted); }
.directory-row { grid-template-columns: minmax(0, 1fr) auto; align-items: center; padding-left: 12px; }
.empty-state, .mobile-empty { margin: 0; padding: 24px 16px; border: 1px dashed var(--border); border-radius: var(--radius-lg); color: var(--muted); text-align: left; }
.empty-state p { margin: 4px 0 0; }

.data-list, .worker-summary { display: grid; margin: 20px 0 32px; }
.data-list > div, .worker-summary > div { display: grid; gap: 4px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.data-list dt, .worker-summary dt { color: var(--subtle); font-size: .8125rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.data-list dd, .worker-summary dd { margin: 0; overflow-wrap: anywhere; }

.filters { margin: 20px 0 32px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--elevated); }
.filters summary { min-height: 48px; font-weight: 700; cursor: pointer; }
.filters__body, .dispatch-filters { display: grid; gap: 16px; align-items: end; }
.filters__actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.dispatch-indicators { display: grid; grid-template-columns: repeat(2, 1fr); margin: 24px 0 40px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.dispatch-indicators p, .metric { min-width: 0; margin: 0; padding: 16px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.dispatch-indicators strong, .metric strong { display: block; font-size: 1.75rem; }
.operations-dashboard { display: grid; gap: 32px; }
.operations-dashboard section { min-width: 0; }
.operations-dashboard section h2 { padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.timeline { margin: 0; padding: 0; list-style: none; }
.timeline li { padding: 12px 0; border-bottom: 1px solid var(--border); }

.responsive-table, .dispatch-table { width: 100%; margin-top: 24px; border-collapse: collapse; background: var(--surface); }
.responsive-table caption, .dispatch-table caption { padding: 8px 0; font-weight: 700; text-align: left; }
.responsive-table th, .responsive-table td, .dispatch-table th, .dispatch-table td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.responsive-table th, .dispatch-table th { color: var(--muted); font-size: .8125rem; }
.dispatch-table .is-overdue { border-left: 4px solid var(--danger); background: #FAEFEE; }
.table-cell-label { display: none; color: var(--subtle); font-size: .75rem; font-weight: 700; text-transform: uppercase; }

.worker-header { margin-bottom: 32px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.worker-header p:last-child { margin-bottom: 0; color: var(--muted); }
.mobile-job-list { display: grid; border-top: 1px solid var(--border); }
.mobile-job-card { min-height: 88px; padding: 16px 12px 16px 20px; }
.mobile-job-card strong { font-size: 1.125rem; }
.worker-back { margin: 0 0 16px; }
.worker-back a { display: inline-flex; min-height: 48px; align-items: center; font-weight: 700; }
.mobile-job-detail { position: relative; padding-left: 16px; border-left: 4px solid var(--info); }
.mobile-job-detail.status-in_progress, .mobile-job-detail.status-finished { border-left-color: var(--success); }
.mobile-job-detail.status-paused { border-left-color: var(--warning); }
.worker-job-type { margin: 0; color: var(--muted); font-size: 1.125rem; }
.mobile-actions { display: grid; gap: 8px; margin: 20px 0; }
.mobile-actions form { display: block; margin: 0; }
.worker-action { width: 100%; min-height: 56px; }
.work-report-entry { margin-top: 32px; padding-top: 8px; border-top: 1px solid var(--border); }
.work-report-entry form { padding: 20px 0; border-bottom: 1px solid var(--border); }
.work-evidence { margin-top: 32px; }
.bottom-action-bar { position: fixed; z-index: 40; right: 0; bottom: 0; left: 0; padding: 12px max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); border-top: 1px solid var(--border); background: rgb(255 255 255 / 96%); box-shadow: var(--shadow); }
.bottom-action-bar form { width: min(100%, 640px); margin: auto; }

@media (max-width: 767px) {
    .app-manager .dispatch-table thead, .app-manager .responsive-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .app-manager .dispatch-table, .app-manager .dispatch-table tbody, .app-manager .dispatch-table tr, .app-manager .dispatch-table td,
    .app-manager .responsive-table, .app-manager .responsive-table tbody, .app-manager .responsive-table tr, .app-manager .responsive-table td { display: block; width: 100%; }
    .app-manager .dispatch-table tr, .app-manager .responsive-table tr { padding: 12px 0; border-bottom: 1px solid var(--border); }
    .app-manager .dispatch-table td, .app-manager .responsive-table td { display: grid; grid-template-columns: minmax(96px, 35%) 1fr; gap: 8px; padding: 6px 12px; border: 0; }
    .table-cell-label { display: block; }
}

@media (min-width: 640px) {
    .operator-nav__identity { display: inline; }
    .dispatch-indicators { grid-template-columns: repeat(3, 1fr); }
    .data-list > div { grid-template-columns: 160px 1fr; gap: 16px; }
}

@media (min-width: 768px) {
    .app-header__inner { min-height: 72px; }
    .app-menu > summary { display: none; }
    .app-menu:not([open]) > .app-menu__panel, .app-menu__panel { position: static; display: flex !important; max-height: none; overflow: visible; align-items: center; gap: 2px; padding: 0; border: 0; box-shadow: none; }
    .nav-group { position: relative; display: block; padding: 0; border: 0; }
    .nav-group summary { display: flex; min-height: 40px; align-items: center; padding: 8px 10px; border-radius: var(--radius-md); color: var(--text); font-size: .875rem; letter-spacing: 0; text-transform: none; }
    .nav-group a { position: absolute; top: 40px; left: 0; display: none; width: max-content; min-width: 180px; border: 1px solid var(--border); border-radius: 0; background: var(--surface); box-shadow: var(--shadow); }
    .nav-group a + a { top: 88px; }
    .nav-group[open] > a { display: flex; }
    .nav-logout { min-height: 40px; margin: 0 0 0 4px; }
    .shell, .worker-shell { padding-top: 48px; }
    .page-header { flex-direction: row; align-items: flex-end; justify-content: space-between; }
    .page-header__actions { justify-content: flex-end; }
    .filters > summary { display: none; }
    .filters:not([open]) .filters__body, .filters__body, .dispatch-filters { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); }
    button, .button { min-height: 40px; }
    .worker-shell button, .worker-shell .button, .worker-shell input, .worker-shell select { min-height: 48px; }
    .bottom-action-bar { position: static; padding: 20px 0; border-top: 1px solid var(--border); box-shadow: none; }
    .worker-shell { padding-bottom: 80px; }
    .operations-dashboard { grid-template-columns: minmax(0, 2fr) minmax(240px, 1fr); }
    .operations-dashboard .dashboard-primary { grid-row: span 3; }
}

@media (min-width: 1024px) {
    .dispatch-indicators { grid-template-columns: repeat(6, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

@media (prefers-contrast: more) {
    input, select, textarea, fieldset, .operation-row, .directory-row { border-width: 2px; }
}
