:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --ink: #1c2420;
  --muted: #657169;
  --line: #dce4de;
  --brand: #276749;
  --brand-strong: #174832;
  --accent: #c77528;
  --danger: #b73535;
  --pending: #946200;
  --ok-bg: #e7f4ed;
  --warn-bg: #fff2d8;
  --bad-bg: #fbe4e4;
  --shadow: 0 16px 40px rgba(25, 38, 31, 0.08);
}

* {
  box-sizing: border-box;
}

html:not(.app-ready) body > * {
  visibility: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(18px, 4vw, 44px);
  background: rgba(244, 246, 243, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.topbar__brand {
  display: flex;
  align-items: flex-end;
  gap: 24px;
  flex: 0 0 auto;
}

.topbar__identity {
  flex: 0 0 auto;
}

.topbar__logos {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex: 0 0 auto;
  padding-bottom: 0;
  line-height: 0;
}

.topbar__logos img {
  display: block;
  flex: 0 0 auto;
  width: auto;
  height: 34px;
  max-width: 120px;
  object-fit: contain;
  align-self: flex-end;
}

.topbar__logos img:first-child {
  width: 98px;
  transform: translateY(-3px);
}

.topbar__logos img:last-child {
  width: 46px;
  height: 42px;
}

@media (min-width: 861px) {
  .topbar > .nav {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
  }
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.05;
}

h2 {
  font-size: clamp(22px, 2.4vw, 30px);
}

h3 {
  font-size: 18px;
}

.eyebrow {
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.session-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.session-bar span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.nav__item,
.ghost,
.primary,
.inline-form button,
.request-card button,
.table-action {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 800;
}

.nav__item {
  background: transparent;
  color: var(--muted);
}

.nav__item.active {
  background: var(--brand);
  color: white;
}

main {
  padding: 28px clamp(16px, 4vw, 44px) 48px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

#view-operativa,
#view-storico {
  width: 100%;
  max-width: none;
  margin-inline: 0;
}

#view-operativa {
  font-size: 19px;
}

#view-operativa .eyebrow,
#view-operativa .ops-stat span,
#view-operativa .line-card__line-label,
#view-operativa .line-card__active-count > span,
#view-operativa .line-queue__title,
#view-operativa .line-request__meta,
#view-operativa th {
  font-size: 15px;
}

#view-operativa h2 {
  font-size: clamp(25px, calc(2.4vw + 3px), 33px);
}

#view-operativa .ops-stat strong {
  font-size: 35px;
}

#view-operativa .line-card__line-name {
  font-size: clamp(26px, calc(2.2vw + 3px), 33px);
}

#view-operativa .line-card strong.count {
  font-size: 43px;
}

#view-operativa .line-queue__title strong,
#view-operativa .line-request__queue,
#view-operativa .queue-inline,
#view-operativa .badge,
#view-operativa .status {
  font-size: 15px;
}

#view-operativa .line-request__summary,
#view-operativa .line-request__code,
#view-operativa .status-reason {
  font-size: 16px;
}

#view-storico {
  font-size: 19px;
}

#view-storico h2 {
  font-size: clamp(25px, calc(2.4vw + 3px), 33px);
}

#view-storico .ops-stat span {
  font-size: 15px;
}

#view-storico .ops-stat strong {
  font-size: 35px;
}

#view-storico .history-toolbar {
  padding: 14px;
}

#view-storico .history-ranges span,
#view-storico .history-limit {
  font-size: 15px;
}

#view-storico .history-ranges button,
#view-storico .history-toolbar input,
#view-storico .history-toolbar select,
#view-storico .history-toolbar button {
  font-size: 16px;
}

#view-storico .history-table th {
  font-size: 15px;
}

#view-storico .history-table td {
  font-size: 19px;
}

#view-storico .history-main strong,
#view-storico .history-stack strong {
  font-size: 17px;
}

#view-storico .history-main span,
#view-storico .history-stack span,
#view-storico .history-times span,
#view-storico .status-reason {
  font-size: 15px;
}

#view-storico .history-times strong {
  font-size: 14px;
}

.auth-panel {
  max-width: 460px;
  margin: 48px auto 0;
}

.auth-link {
  width: 100%;
  margin-top: 14px;
}

.portal-view .panel:first-child {
  border-top: 5px solid var(--brand);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  gap: 18px;
  align-items: start;
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.compact {
  box-shadow: none;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.section-head.wide {
  align-items: center;
}

.badge,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 10px;
  background: #eef4ef;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.form,
.inline-form {
  display: grid;
  gap: 14px;
}

.form label,
.window-setting {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select {
  min-height: 44px;
  width: 100%;
  border: 1px solid #cad5cd;
  border-radius: 8px;
  padding: 0 12px;
  background: white;
  color: var(--ink);
}

.primary,
.inline-form button,
.request-card button {
  background: var(--brand);
  color: white;
}

.primary:disabled,
.inline-form button:disabled,
.request-card button:disabled,
.table-action:disabled {
  cursor: default;
  background: #d7e1da;
  color: var(--muted);
}

.ghost {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.ghost:disabled {
  cursor: default;
  border-color: #b8c9bf;
  background: #eef4ef;
  color: var(--brand-strong);
}

.muted {
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.5;
}

.hint {
  margin-top: 18px;
  padding: 14px;
  border-radius: 8px;
  background: #f7faf7;
  border: 1px dashed #b7c6bc;
  color: var(--muted);
  line-height: 1.45;
}

.request-card {
  margin-top: 18px;
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: 8px;
  background: #f7faf7;
  border: 1px solid var(--line);
}

.driver-panel {
  max-width: 820px;
  margin: 0 auto;
}

.driver-status {
  display: grid;
  gap: 16px;
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: #f7faf7;
}

.driver-status.is-called,
.driver-status.is-approved {
  border-color: #98c7aa;
  background: var(--ok-bg);
}

.driver-status.is-in_progress {
  border-color: #9bbbd8;
  background: #f2f7fb;
}

.driver-status.is-expired,
.driver-status.is-rejected {
  border-color: #e7b6b6;
  background: #fff7f7;
}

.driver-status__main {
  display: grid;
  gap: 8px;
}

.driver-panel #driver-enable-alerts {
  margin-top: 12px;
  border: 1px solid #a52b2b;
  background: var(--danger);
  color: white;
}

.driver-panel #driver-enable-alerts:hover:not(:disabled),
.driver-panel #driver-enable-alerts:focus-visible:not(:disabled) {
  border-color: #8f2020;
  background: #8f2020;
}

.driver-panel #driver-enable-alerts.is-enabled {
  border-color: #1f633f;
  background: var(--brand);
  color: white;
}

.driver-panel #driver-enable-alerts.is-enabled:hover:not(:disabled),
.driver-panel #driver-enable-alerts.is-enabled:focus-visible:not(:disabled) {
  border-color: var(--brand-strong);
  background: var(--brand-strong);
}

.driver-status__title {
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 900;
  line-height: 1.1;
}

.driver-status__details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.driver-status__details div {
  min-width: 0;
  min-height: 66px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: white;
}

.driver-status__details span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.driver-status__details strong {
  display: block;
  margin-top: 4px;
}

.access-grant {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(180px, 0.8fr);
  gap: 12px;
}

.access-grant__code,
.access-grant__timer {
  min-width: 0;
  min-height: 126px;
  border: 1px solid #a9ceb7;
  border-radius: 8px;
  padding: 16px;
  background: white;
}

.access-grant span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.access-grant__code strong,
.access-grant__timer strong {
  display: block;
  margin-top: 8px;
  color: var(--brand-strong);
  font-weight: 950;
  line-height: 1;
}

.access-grant__code strong {
  font-size: clamp(44px, 9vw, 82px);
}

.access-grant__timer strong {
  font-size: clamp(38px, 7vw, 64px);
  font-variant-numeric: tabular-nums;
}

.queue-position {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-height: 150px;
  border: 1px solid #efcd8f;
  border-radius: 8px;
  padding: 18px;
  background: #fff8e8;
  text-align: center;
}

.queue-position span,
.queue-position small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.queue-position strong {
  color: var(--pending);
  font-size: clamp(64px, 12vw, 118px);
  font-weight: 950;
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
}

.driver-line-assigned {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 84px;
  border: 1px solid #c8d6cc;
  border-radius: 8px;
  padding: 14px 18px;
  background: white;
  text-align: center;
}

.driver-line-assigned span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.driver-line-assigned strong {
  max-width: 100%;
  color: var(--brand-strong);
  font-size: clamp(18px, 3vw, 28px);
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.hidden {
  display: none;
}

.line-board-shell {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  margin-bottom: 20px;
}

.line-board {
  display: flex;
  flex-wrap: nowrap;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  align-items: stretch;
  gap: 14px;
  overflow-x: auto;
  padding: 0 2px 10px;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.line-board-nav {
  display: inline-grid;
  place-items: center;
  position: absolute;
  top: 50%;
  width: 44px;
  min-width: 44px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--brand-strong);
  font-size: 36px;
  font-weight: 400;
  line-height: 1;
  transform: translateY(-50%);
  z-index: 2;
}

.line-board-nav:first-child {
  left: -56px;
}

.line-board-nav:last-child {
  right: -56px;
}

.line-board-nav:hover:not(:disabled),
.line-board-nav:focus-visible:not(:disabled) {
  border-color: var(--brand);
  background: #eef4ef;
}

.line-board-nav:disabled {
  cursor: default;
  opacity: 0.35;
}

.line-board-nav.has-alert {
  border-color: var(--pending);
  background: var(--warn-bg);
  color: var(--pending);
}

.line-board-nav__count {
  position: absolute;
  top: -8px;
  right: -7px;
  display: grid;
  place-items: center;
  min-width: 21px;
  height: 21px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--pending);
  color: white;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}

.line-board-nav__count[hidden] {
  display: none;
}

.line-board > .line-card {
  flex: 0 0 clamp(370px, 38vw, 480px);
  align-self: stretch;
  min-width: 0;
}

.ops-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.ops-stat {
  min-height: 102px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: white;
  box-shadow: var(--shadow);
}

.ops-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.ops-stat strong {
  display: block;
  margin-top: 7px;
  font-size: 32px;
  line-height: 1;
}

.ops-stat.is-warning {
  border-color: #efcd8f;
  background: #fffaf0;
}

.dashboard-filters {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(150px, 0.8fr) minmax(190px, 1fr) minmax(170px, 0.9fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.dashboard-filters label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.history-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.history-ranges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.history-ranges span,
.history-limit {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.history-ranges button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #f7faf7;
  color: var(--ink);
  font-weight: 800;
}

.history-ranges button.active {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
}

.history-limit {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-limit select {
  min-width: 96px;
}

.history-filters {
  grid-template-columns:
    minmax(220px, 1.4fr)
    minmax(150px, 0.8fr)
    minmax(180px, 1fr)
    minmax(130px, 0.7fr)
    minmax(130px, 0.7fr)
    minmax(170px, 0.9fr)
    auto;
}

.line-card {
  min-width: 0;
  min-height: 350px;
  border: 1px solid #c8d6cc;
  border-radius: 12px;
  padding: 24px;
  background: white;
  box-shadow: 0 10px 24px rgba(25, 38, 31, 0.07);
}

.line-card--detailed {
  display: grid;
  gap: 14px;
  align-content: start;
}

.line-card__head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
}

.line-card__line-heading {
  min-width: 0;
}

.line-card__line-label,
.line-card__active-count > span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.line-card__line-name {
  display: block;
  margin: 6px 0 12px;
  color: var(--brand-strong);
  font-size: clamp(23px, 2.2vw, 30px);
  font-weight: 950;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

@media (min-width: 861px) {
  .line-card {
    min-height: 430px;
  }

  .line-card--detailed {
    grid-template-rows: auto 1fr;
  }

  .line-card--detailed .line-queues {
    grid-template-rows: repeat(3, minmax(72px, 1fr));
    min-height: 300px;
  }
}

.line-card__active-count {
  flex: 0 0 auto;
  min-width: 48px;
  padding: 0;
  text-align: center;
}

.line-card strong.count {
  display: block;
  margin: 5px 0 0;
  color: var(--brand);
  font-size: 40px;
  line-height: 1;
}

.line-card .count {
  font-weight: 900;
}

.line-queues {
  display: grid;
  grid-template-rows: none;
  gap: 0;
  min-height: 0;
}

.line-queue {
  display: grid;
  align-content: start;
  gap: 7px;
  min-height: 58px;
  padding: 10px 0 12px;
  border-top: 1px solid var(--line);
}

.line-queue__title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.line-queue__title strong {
  min-width: 28px;
  min-height: 24px;
  margin: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #eef4ef;
  color: var(--brand-strong);
  font-size: 12px;
}

.line-queue__items {
  display: grid;
  gap: 8px;
}

.line-request {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbf9;
}

.line-request.is-expiring {
  border-color: #efcd8f;
  background: #fff8e8;
}

.line-request__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.line-request__summary {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
}

.line-request__code {
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 900;
}

.line-request__queue,
.queue-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  min-height: 24px;
  margin-right: 6px;
  border-radius: 999px;
  background: var(--warn-bg);
  color: var(--pending);
  font-size: 12px;
  font-weight: 950;
}

.line-request__actions {
  margin-top: 2px;
}

.line-empty,
.line-more {
  color: var(--muted);
  font-size: 13px;
}

.line-more {
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

.operator-requests-table {
  min-width: 900px;
  table-layout: fixed;
}

.operator-requests-table th:nth-child(1),
.operator-requests-table td:nth-child(1) {
  width: 15%;
}

.operator-requests-table th:nth-child(2),
.operator-requests-table td:nth-child(2) {
  width: 10%;
}

.operator-requests-table th:nth-child(3),
.operator-requests-table td:nth-child(3) {
  width: 37%;
}

.operator-requests-table th:nth-child(4),
.operator-requests-table td:nth-child(4) {
  width: 20%;
}

.operator-requests-table th:nth-child(5),
.operator-requests-table td:nth-child(5) {
  width: 18%;
}

.history-table {
  min-width: 1120px;
}

.admin-config-table-wrap {
  margin-top: 18px;
  overflow-x: hidden;
  box-shadow: none;
}

.admin-config-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

.admin-config-table th:last-child,
.admin-config-table td:last-child {
  width: 210px;
}

.admin-config-table td {
  vertical-align: middle;
}

#cer-form {
  grid-template-columns: minmax(150px, 0.7fr) minmax(240px, 1.3fr) auto;
  align-items: end;
}

#line-form {
  grid-template-columns: minmax(200px, 1fr) minmax(130px, 180px) auto;
  align-items: end;
}

#view-admin [data-admin-panel="cer"] h3 {
  font-size: 21px;
}

#view-admin [data-admin-panel="cer"] #cer-form input,
#view-admin [data-admin-panel="cer"] #cer-form button {
  font-size: 17px;
}

#view-admin #city-form > button,
#view-admin #cer-form > button {
  width: 112px;
  min-width: 112px;
  height: 44px;
  min-height: 44px;
  padding: 0 14px;
  align-self: end;
  font-size: 17px;
}

#view-admin [data-admin-panel] h3 {
  font-size: 21px;
  line-height: 1.15;
}

#view-admin .admin-section-nav__item {
  font-size: 17px;
}

#view-admin [data-admin-panel] .section-head .eyebrow {
  font-size: 12px;
  line-height: 1.2;
}

#view-admin [data-admin-panel] input,
#view-admin [data-admin-panel] select,
#view-admin [data-admin-panel] button,
#view-admin [data-admin-panel] .admin-config-table td,
#view-admin [data-admin-panel] .admin-config-table .table-action {
  font-size: 17px;
}

#view-admin [data-admin-panel] .admin-config-table th {
  font-size: 15px;
}

.admin-config-table th {
  font-size: 15px;
}

.admin-config-table td {
  font-size: 17px;
}

.admin-config-table .table-action {
  font-size: 16px;
}

.admin-config-table .actions {
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.admin-config-table .table-action {
  min-height: 34px;
  padding: 0 9px;
  font-size: 16px;
  white-space: nowrap;
}

.admin-anagraphic-actions {
  flex-wrap: nowrap;
  white-space: nowrap;
}

.admin-table-list-item {
  display: block;
}

.admin-table-muted {
  color: var(--muted);
}

.admin-table-action-group {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  background: #f7faf7;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.request-datetime {
  white-space: nowrap;
}

.request-datetime > span {
  display: block;
}

.request-datetime small {
  display: inline-block;
  min-width: 34px;
  margin-right: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

tr.is-expiring td {
  background: #fff8e8;
}

.urgent {
  display: block;
  margin-top: 4px;
  color: var(--pending);
  font-size: 12px;
  font-weight: 900;
}

.status-reason {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.history-main,
.history-stack,
.history-times {
  display: grid;
  gap: 5px;
}

.history-main strong,
.history-stack strong {
  color: var(--ink);
  font-size: 14px;
}

.history-main span,
.history-stack span,
.history-times span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.history-times span {
  display: grid;
  gap: 2px;
}

.history-times strong {
  color: var(--ink);
  font-size: 11px;
  text-transform: uppercase;
}

.status.pending {
  background: var(--warn-bg);
  color: var(--pending);
}

.status.called,
.status.approved,
.status.completed,
.status.used {
  background: var(--ok-bg);
  color: var(--brand-strong);
}

.status.in_progress {
  background: #eef6ff;
  color: #235a8a;
}

.status.rejected,
.status.expired,
.status.cancelled {
  background: var(--bad-bg);
  color: var(--danger);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.table-action {
  min-height: 34px;
  background: #eef4ef;
  color: var(--brand-strong);
}

.table-action.reject {
  background: var(--bad-bg);
  color: var(--danger);
}

.admin-line-overview {
  margin-top: 12px;
}

.admin-line-overview .section-head {
  margin-bottom: 10px;
}

.admin-line-overview__grid {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.admin-line-summary {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #f9fbf9;
}

.admin-line-summary__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.admin-line-summary__head strong {
  display: block;
  margin-top: 4px;
  color: var(--brand-strong);
  font-size: 21px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.admin-line-summary__label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.admin-line-summary__groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.admin-line-summary__group {
  min-width: 0;
  border-top: 1px solid var(--line);
  padding-top: 9px;
}

.admin-line-summary__group h4 {
  margin: 0;
  color: var(--brand-strong);
  font-size: 15px;
  font-weight: 950;
  text-transform: uppercase;
}

.admin-line-summary__details {
  display: grid;
  gap: 4px;
  margin: 8px 0 0;
}

.admin-line-summary__details div {
  display: grid;
  grid-template-columns: minmax(72px, auto) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.admin-line-summary__details dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.admin-line-summary__details dd {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.admin-section-nav {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.admin-section-nav__item {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 12px;
  background: white;
  color: var(--brand-strong);
  font-weight: 900;
}

.admin-section-nav__item:hover,
.admin-section-nav__item:focus-visible,
.admin-section-nav__item.is-active {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
}

.admin-sections {
  margin-top: 18px;
}

.admin-section-help {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.admin-line-management .section-head {
  margin-bottom: 14px;
}

.admin-line-management #line-form {
  max-width: 860px;
}

.admin-line-management #line-form button {
  min-height: 44px;
}

.admin-line-management #lines-list {
  display: table-row-group;
  margin-top: 18px;
}

.admin-line-management #lines-list tr {
  display: table-row;
}

.admin-line-management #lines-list td {
  display: table-cell;
  vertical-align: middle;
}

.admin-back-overview {
  min-height: 38px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: white;
  color: var(--brand-strong);
  font-weight: 800;
}

.admin-back-overview:hover,
.admin-back-overview:focus-visible {
  border-color: var(--brand);
  background: #eef4ef;
}

.admin-section > .panel,
.admin-rules-section {
  margin-top: 0;
}

.admin-rules-section {
  margin-top: 18px;
}

.admin-grid,
.rules-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.inline-form {
  grid-template-columns: minmax(120px, 1fr) auto;
}

.inline-form input:nth-child(2),
.inline-form select:nth-child(2) {
  min-width: 150px;
}

.inline-form.three {
  grid-template-columns: repeat(3, minmax(120px, 1fr)) auto;
}

#private-rule-form {
  grid-template-columns: repeat(4, minmax(120px, 1fr)) auto;
}

.chips,
.rules-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.chip,
.rule-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  border-radius: 8px;
  padding: 6px 10px;
  background: #f7faf7;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
}

.chip__actions,
.rule-row__actions {
  display: inline-flex;
  gap: 6px;
}

.chip button,
.rule-row button {
  min-width: 24px;
  height: 24px;
  border-radius: 6px;
  padding: 0 7px;
  font-size: 12px;
  font-weight: 900;
}

.chip button[data-edit],
.rule-row button[data-rule-edit] {
  background: #e7f4ed;
  color: var(--brand-strong);
}

.chip button[data-remove],
.rule-row button[data-rule-delete] {
  background: #f0dddd;
  color: var(--danger);
}

.window-setting {
  grid-template-columns: auto 80px auto;
  align-items: center;
}

.modal {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(28, 36, 32, 0.36);
}

.modal__content {
  padding: 22px;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  border-radius: 8px;
  padding: 13px 15px;
  background: var(--ink);
  color: white;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media print {
  @page {
    margin: 12mm;
  }

  body {
    background: white;
  }

  .topbar,
  .dashboard-filters,
  .history-toolbar,
  #view-storico .section-head .actions,
  .toast,
  .modal {
    display: none !important;
  }

  main {
    padding: 0;
  }

  #view-storico.view.active {
    display: block;
  }

  #view-storico .section-head {
    margin-bottom: 14px;
  }

  .ops-summary {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 12px;
  }

  .ops-stat,
  .table-wrap {
    border: 1px solid #cfd8d2;
    box-shadow: none;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  .history-table {
    min-width: 0;
    font-size: 10px;
  }

  th,
  td {
    padding: 7px 8px;
  }
}

@media (max-width: 860px) {
  .topbar,
  .section-head,
  .section-head.wide {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar > .nav {
    position: static;
    transform: none;
  }

  .topbar__logos {
    margin-inline: 0;
  }

  .topbar__brand {
    align-items: flex-end;
    gap: 10px;
    max-width: 100%;
  }

  .topbar__logos {
    gap: 8px;
    padding-bottom: 0;
  }

  .topbar__logos img {
    height: 26px;
  }

  .topbar__logos img:first-child {
    width: 76px;
  }

  .topbar__logos img:last-child {
    width: 30px;
    height: 30px;
  }

  .history-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .split,
  .admin-grid,
  .rules-grid,
  .portal-grid,
  .ops-summary,
  .dashboard-filters {
    grid-template-columns: 1fr;
  }

  .admin-section-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-line-summary__groups {
    grid-template-columns: 1fr;
  }

  .line-board-shell {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
  }

  .line-board-nav {
    position: relative;
    top: auto;
    transform: none;
  }

  .line-board-nav:first-child,
  .line-board-nav:last-child {
    left: auto;
    right: auto;
  }

  .inline-form,
  .inline-form.three,
  #cer-form,
  #line-form,
  #private-rule-form,
  .driver-status__details,
  .access-grant {
    grid-template-columns: 1fr;
  }

  .line-board > .line-card {
    flex-basis: 100%;
    width: 100%;
  }

  .line-card {
    min-height: 248px;
    padding: 20px;
  }

  .line-board-nav {
    width: 46px;
    min-width: 46px;
  }

  .window-setting {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .window-setting input {
    grid-column: 1;
  }

  .form > button,
  .inline-form > button,
  .modal__actions button,
  .actions .table-action {
    min-height: 44px;
  }

  .modal__content {
    padding: 18px;
  }

  .nav__item {
    flex: 1 1 120px;
  }

}

@media (max-width: 480px) {
  main {
    padding: 18px 12px 32px;
  }

  .topbar {
    gap: 14px;
    padding: 14px 12px;
  }

  .panel {
    padding: 16px;
  }

  .section-head {
    gap: 12px;
    margin-bottom: 16px;
  }

  .line-board-shell {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 5px;
    align-items: center;
  }

  .line-board-nav {
    position: relative;
    top: auto;
    width: 42px;
    min-width: 42px;
    height: 48px;
    transform: none;
  }

  .line-board-nav:first-child {
    left: auto;
  }

  .line-board-nav:last-child {
    right: auto;
  }

  .line-board > .line-card {
    flex-basis: 100%;
  }

  .line-card__head {
    gap: 12px;
  }

  .line-card__active-count {
    min-width: 42px;
  }

  .history-ranges,
  .modal__actions {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-section-nav {
    grid-template-columns: 1fr;
  }

  .history-ranges button,
  .modal__actions button {
    width: 100%;
  }

  .session-bar,
  .nav {
    width: 100%;
  }

  .session-bar {
    justify-content: space-between;
  }

  .nav__item {
    flex: 1 1 100%;
  }
}

/* iPhone/iPad WebKit refinements. Keep these out of the shared Android rules. */
@supports (-webkit-touch-callout: none) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    min-height: 100dvh;
    overflow-x: hidden;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .topbar {
    padding-top: calc(18px + env(safe-area-inset-top));
  }

  main {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
    padding-bottom: calc(48px + env(safe-area-inset-bottom));
  }

  @media (max-width: 480px) {
    main {
      padding-bottom: calc(32px + env(safe-area-inset-bottom));
    }

    .topbar {
      padding-top: calc(14px + env(safe-area-inset-top));
    }

    .driver-panel {
      width: 100%;
      max-width: 100%;
      min-width: 0;
      padding: 14px;
      overflow: hidden;
    }

    #view-autista,
    #view-autista.view.active {
      width: 100%;
      max-width: 100%;
      min-width: 0;
      overflow-x: hidden;
    }

    .driver-panel .section-head > div,
    .driver-status,
    .driver-status__main,
    .driver-status__details,
    .driver-status__details div {
      min-width: 0;
      max-width: 100%;
    }

    .driver-panel .status {
      align-self: flex-start;
    }

    .driver-panel #driver-enable-alerts,
    .driver-panel #driver-new-request {
      width: 100%;
      min-height: 44px;
    }

    .driver-status {
      min-height: 200px;
      gap: 14px;
      padding: 16px;
    }

    .driver-status__details {
      gap: 8px;
    }

    .driver-status__details strong {
      overflow-wrap: anywhere;
      word-break: break-word;
    }

    .access-grant__code,
    .access-grant__timer {
      min-height: 112px;
      padding: 14px;
    }
  }
}
