:root {
    color-scheme: light;
    --bg: #eef1f2;
    --surface: #fff;
    --surface-soft: #f6f8f8;
    --ink: #20282c;
    --muted: #66747a;
    --line: #d8dfe1;
    --brand: #33464e;
    --accent: #146c67;
    --accent-dark: #0f5551;
    --ok: #24764d;
    --warn: #9b6408;
    --bad: #a33b3b;
    --info: #326a91;
    --shadow: 0 18px 55px rgba(25, 36, 41, .2);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font-family: Arial, Helvetica, sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
    min-height: 68px;
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
    align-items: center;
    gap: 24px;
    padding: 10px 24px;
    background: #29373d;
    color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; width: max-content; color: inherit; text-decoration: none; }
.brand img { width: 38px; height: 38px; object-fit: contain; }
.brand strong, .brand small { display: block; letter-spacing: 0; }
.brand strong { font-size: 13px; }
.brand small { margin-top: 2px; color: #cdd7da; font-size: 11px; }
.title { text-align: center; }
.title h1 { margin: 0; font-size: 19px; letter-spacing: 0; }
.title p { margin: 3px 0 0; color: #cdd7da; font-size: 12px; }
.usuario { justify-self: end; color: #dce4e6; font-size: 13px; }

main { width: min(1120px, calc(100% - 32px)); margin: 22px auto 40px; }
.overview, .workspace { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.overview { display: flex; align-items: center; justify-content: space-between; gap: 28px; padding: 18px 20px; }
.progress-block { display: grid; grid-template-columns: auto minmax(180px, 360px) 54px; align-items: center; gap: 18px; min-width: 0; }
.progress-copy span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.progress-copy strong { white-space: nowrap; font-size: 18px; }
.progress-track { height: 9px; overflow: hidden; border-radius: 5px; background: #dfe6e7; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .2s ease; }
.percent { color: var(--accent-dark); font-size: 18px; }
.compact-totals { display: flex; gap: 18px; padding-left: 24px; border-left: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.compact-totals strong { display: block; color: var(--ink); font-size: 18px; }

.workspace { margin-top: 14px; overflow: hidden; }
.toolbar, .modal-tools { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.search-label { flex: 1; }
input, select, textarea { width: 100%; border: 1px solid #c9d2d5; border-radius: 6px; background: #fff; color: var(--ink); }
input, select { height: 38px; padding: 0 10px; }
textarea { padding: 10px; line-height: 1.45; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(20, 108, 103, .2); border-color: var(--accent); }
.toolbar select { width: 185px; }
.button { min-height: 38px; border: 1px solid var(--accent-dark); border-radius: 6px; padding: 0 14px; background: var(--accent); color: #fff; font-weight: 700; }
.button:hover { background: var(--accent-dark); }
.button.secondary { border-color: #bcc8cb; background: #fff; color: #34484f; }
.button.secondary:hover { background: #f1f5f5; }
.button:disabled { cursor: not-allowed; opacity: .55; }
.message { min-height: 0; padding: 0 14px; color: var(--bad); font-size: 13px; }
.message:not(:empty) { padding-top: 10px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid #e3e8e9; text-align: left; font-size: 13px; }
th { background: var(--surface-soft); color: var(--muted); font-size: 11px; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f8fafa; }
.municipio-button { border: 0; padding: 0; background: transparent; color: var(--ink); font-weight: 700; text-align: left; }
.municipio-button:hover { color: var(--accent-dark); text-decoration: underline; }
.number { width: 90px; text-align: right; }
.action-col { width: 112px; text-align: right; }
.status-line { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.mini-track { width: 100%; max-width: 170px; height: 6px; overflow: hidden; border-radius: 3px; background: #e2e7e8; }
.mini-track span { display: block; height: 100%; background: var(--accent); }
.status-line small { min-width: 42px; color: var(--muted); }
.status-badge { display: inline-flex; align-items: center; min-height: 24px; border-radius: 12px; padding: 3px 8px; font-size: 11px; font-weight: 700; }
.status-badge.ok { background: #e6f3eb; color: var(--ok); }
.status-badge.warn { background: #fff2dc; color: var(--warn); }
.status-badge.bad { background: #fbe9e9; color: var(--bad); }
.status-badge.info { background: #e8f1f7; color: var(--info); }

.modal { width: min(860px, calc(100% - 24px)); max-height: calc(100vh - 32px); margin: auto; padding: 0; overflow: hidden; border: 0; border-radius: 8px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(25, 34, 38, .56); }
.rota-modal { width: min(760px, calc(100% - 24px)); z-index: 20; }
.rota-modal::backdrop { background: rgba(25, 34, 38, .38); }
.modal-shell { display: flex; max-height: calc(100vh - 32px); flex-direction: column; margin: 0; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-header p { margin: 0 0 4px; color: var(--accent-dark); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.modal-header h2 { margin: 0; font-size: 20px; letter-spacing: 0; }
.modal-subtitle { display: block; max-width: 680px; margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.icon-button { flex: 0 0 36px; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 50%; background: #fff; color: #415158; font-size: 25px; line-height: 1; }
.icon-button:hover { background: var(--surface-soft); }
.modal-tools input { flex: 1; }
.modal-tools select { width: 180px; }

.route-list { min-height: 150px; overflow-y: auto; padding: 0 20px 16px; }
.route-row { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 18px; padding: 14px 2px; border: 0; border-bottom: 1px solid #e4e9ea; background: #fff; color: inherit; text-align: left; }
.route-row:hover { background: #f8fafa; }
.route-row strong { display: block; overflow-wrap: anywhere; font-size: 13px; }
.route-row small { display: block; margin-top: 4px; color: var(--muted); }
.route-numbers { white-space: nowrap; color: var(--muted); font-size: 12px; }

.route-summary { display: flex; gap: 20px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--surface-soft); color: var(--muted); font-size: 12px; }
.route-summary span:last-child { margin-left: auto; }
.points-section { overflow-y: auto; padding: 16px 20px 4px; }
.points-section h3 { margin: 0 0 8px; font-size: 13px; }
.points-list { border: 1px solid var(--line); border-radius: 6px; }
.point-row { display: grid; grid-template-columns: 1fr auto; gap: 16px; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.point-row:last-child { border-bottom: 0; }
.point-row span:last-child { white-space: nowrap; font-weight: 700; }
.point-row small { display: block; margin-top: 3px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 240px 1fr; gap: 12px; padding: 16px 20px; }
.form-grid label { color: var(--muted); font-size: 12px; font-weight: 700; }
.form-grid select, .form-grid textarea { margin-top: 5px; color: var(--ink); font-weight: 400; }
.form-grid .wide { grid-column: 2; }
.modal-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); }
.modal-actions span { flex: 1; color: var(--muted); font-size: 12px; }
.resposta-modal { width: min(650px, calc(100% - 24px)); }
.resposta-modal textarea { width: auto; margin: 18px 20px; }
.empty { padding: 30px; color: var(--muted); text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

@media (max-width: 760px) {
    .topbar { grid-template-columns: 1fr auto; padding: 10px 14px; }
    .title { display: none; }
    .usuario { font-size: 11px; }
    main { width: min(100% - 20px, 1120px); margin-top: 10px; }
    .overview { align-items: stretch; flex-direction: column; gap: 14px; padding: 14px; }
    .progress-block { grid-template-columns: 1fr 46px; gap: 10px; }
    .progress-copy { grid-column: 1 / -1; }
    .compact-totals { justify-content: space-between; padding: 12px 0 0; border-top: 1px solid var(--line); border-left: 0; }
    .toolbar { display: grid; grid-template-columns: 1fr 1fr; }
    .search-label, .toolbar select { width: 100%; grid-column: 1 / -1; }
    .optional { display: none; }
    th, td { padding: 11px 10px; }
    .action-col { width: 84px; }
    .status-line { min-width: 100px; }
    .mini-track { display: none; }
    .modal { width: 100%; max-height: 100vh; border-radius: 0; }
    .modal-shell { max-height: 100vh; }
    .modal-tools { flex-direction: column; }
    .modal-tools select { width: 100%; }
    .route-list { padding: 0 14px 12px; }
    .route-row { grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
    .route-row .status-badge { grid-column: 1; width: max-content; }
    .route-numbers { grid-column: 2; grid-row: 1 / span 2; }
    .route-summary { flex-wrap: wrap; padding: 10px 14px; }
    .route-summary span:last-child { width: 100%; margin-left: 0; }
    .points-section { padding: 14px; }
    .form-grid { display: block; padding: 14px; }
    .form-grid label { display: block; margin-bottom: 12px; }
    .modal-actions { padding: 10px 14px; }
}
