:root {
  color-scheme: light;
  --bg: #f7faf9;
  --surface: #ffffff;
  --surface-strong: #eef7f4;
  --ink: #13201f;
  --muted: #667370;
  --line: #d7e2df;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --gold: #b7791f;
  --red: #b42318;
  --red-soft: #fff1f0;
  --green-soft: #e9f8ef;
  --shadow: 0 16px 36px rgba(18, 32, 31, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

input,
select {
  font-size: 16px;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) 14px calc(env(safe-area-inset-bottom) + 22px);
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--teal-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 1.85rem;
  line-height: 1.05;
}

h2 {
  margin-bottom: 0;
  font-size: 1.2rem;
  line-height: 1.2;
}

.profile-switcher {
  min-width: 148px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.tabs {
  position: sticky;
  top: env(safe-area-inset-top);
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  padding: 5px;
  backdrop-filter: blur(18px);
}

.tab {
  display: flex;
  flex-direction: column;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 780;
}

.tab .icon {
  display: flex;
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
}

.tab .icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.25;
}

.tab span:last-child {
  display: block;
  line-height: 1;
}

.tab.is-active {
  background: var(--teal);
  color: white;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.dashboard-date-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  width: min(100%, 430px);
  justify-self: end;
}

.dashboard-date-control label {
  min-width: 0;
}

.dashboard-date-control input,
.dashboard-date-control button {
  max-width: 100%;
  min-width: 0;
}

#todayButton {
  width: 100%;
}

.dashboard-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: end;
}

.primary-button,
.secondary-button,
.danger-button,
.danger-outline-button,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 8px;
  padding: 10px 14px;
  border: 1px solid transparent;
  font-weight: 800;
  font-family: inherit;
  font-size: 16px;
  text-align: center;
  white-space: nowrap;
}

.primary-button {
  background: var(--teal);
  color: white;
}

.secondary-button,
.file-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.danger-button {
  background: var(--red);
  color: white;
}

.danger-outline-button {
  width: 100%;
  border-color: #f2b8b3;
  background: var(--red-soft);
  color: var(--red);
}

.danger-outline-button:disabled {
  cursor: not-allowed;
  border-color: var(--line);
  background: #f3f6f5;
  color: var(--muted);
}

.rule-results,
.list,
.violations {
  display: grid;
  gap: 8px;
}

.dashboard-summary {
  margin-bottom: 12px;
}

.insight-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px;
}

.summary-top {
  display: grid;
  gap: 10px;
  align-items: start;
}

.summary-copy {
  min-width: 0;
}

.summary-copy h3 {
  margin: 8px 0 4px;
  font-size: 1.05rem;
  line-height: 1.2;
}

.context-chips {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 6px;
}

.context-chips span {
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 780;
  line-height: 1.25;
  padding: 9px 10px;
}

.context-chips strong {
  display: block;
  margin-top: 2px;
  color: var(--ink);
}

.result-card,
.list-card,
.settings-panel,
.editor-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.result-card,
.list-card,
.settings-panel {
  padding: 12px;
}

.editor-panel {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
}

.route-fields,
.travel-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.travel-type-control {
  max-width: 360px;
}

.return-fields {
  margin-top: -4px;
}

.date-field {
  gap: 7px;
  min-width: 0;
}

.date-entry {
  display: grid;
  grid-template-columns: minmax(76px, 1fr) minmax(68px, 0.75fr) minmax(82px, 0.9fr);
  gap: 6px;
}

.date-entry input,
.date-entry select {
  min-height: 44px;
  padding-inline: 10px;
}

.date-entry input.is-invalid,
.date-entry select.is-invalid {
  border-color: var(--red);
  background: var(--red-soft);
}

.date-entry input.is-invalid:focus,
.date-entry select.is-invalid:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.16);
}

.date-error {
  min-height: 16px;
  color: var(--red);
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1.2;
}

.dashboard-date-field .date-error:empty {
  display: none;
}

.date-stepper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.compact-button {
  min-height: 36px;
  padding: 7px 9px;
  font-size: 0.78rem;
}

.result-card {
  display: grid;
  gap: 10px;
}

.card-title-row,
.list-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title-row h3,
.list-title-row h3 {
  margin: 0;
  font-size: 1rem;
}

.status-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 0.72rem;
  font-weight: 850;
}

.status-safe {
  background: var(--green-soft);
  color: #11613a;
}

.status-warning {
  background: #fff8e6;
  color: var(--gold);
}

.status-violation {
  background: var(--red-soft);
  color: var(--red);
}

.meter {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: #e7eeec;
}

.meter-fill {
  height: 100%;
  width: var(--value);
  border-radius: inherit;
  background: var(--teal);
}

.meter-fill.warning {
  background: var(--gold);
}

.meter-fill.violation {
  background: var(--red);
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.metric {
  min-height: 56px;
  border-radius: 8px;
  background: var(--surface-strong);
  padding: 9px 10px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
}

.metric strong {
  display: block;
  margin-top: 3px;
  font-size: 0.94rem;
  line-height: 1.2;
}

.list-card {
  display: grid;
  gap: 7px;
}

.alert-summary-list {
  display: grid;
  gap: 6px;
}

.alert-summary-block {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.alert-summary-block h4 {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
}

.alert-summary-item {
  display: grid;
  grid-template-columns: minmax(130px, 0.55fr) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid #f6c7c2;
  border-radius: 7px;
  background: #fffafa;
  padding: 9px 10px;
}

.alert-summary-item strong {
  display: block;
  font-size: 0.84rem;
  line-height: 1.2;
}

.alert-summary-item span {
  display: block;
  margin-top: 2px;
  color: var(--red);
  font-size: 0.76rem;
  font-weight: 780;
  line-height: 1.25;
}

.alert-summary-item p {
  margin: 0;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 750;
  line-height: 1.3;
}

.meta {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.rule-explain {
  margin-bottom: 0;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 720;
  line-height: 1.35;
}

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

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 900;
}

.field-row,
.form-actions,
.backup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  border-radius: 8px;
  background: #e7eeec;
  padding: 5px;
}

.segmented-control label {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 850;
}

.segmented-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segmented-control span {
  display: block;
  min-height: 40px;
  border-radius: 7px;
  padding: 10px;
  text-align: center;
}

.segmented-control input:checked + span {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(18, 32, 31, 0.08);
}

.settings-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-heading {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.2;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

dialog {
  width: min(calc(100% - 32px), 390px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(18, 32, 31, 0.22);
}

dialog::backdrop {
  background: rgba(18, 32, 31, 0.38);
}

dialog form {
  display: grid;
  gap: 10px;
  padding: 16px;
}

dialog h2 {
  font-size: 1.1rem;
}

dialog p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

@media (max-width: 520px) {
  .app-shell {
    padding-inline: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .profile-switcher {
    min-width: 0;
  }

  .section-header {
    align-items: stretch;
    flex-direction: column;
  }

  .dashboard-header {
    gap: 10px;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .dashboard-date-control {
    grid-template-columns: minmax(0, 1fr);
    justify-self: stretch;
    width: 100%;
  }

  .dashboard-date-control label {
    width: 100%;
  }

  .insight-panel,
  .metric-row {
    grid-template-columns: 1fr;
  }

  .context-chips {
    grid-template-columns: 1fr;
  }

  .alert-summary-item {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .field-row,
  .route-fields,
  .travel-fields,
  .form-actions,
  .backup-actions {
    grid-template-columns: 1fr;
  }

  .date-entry {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr) minmax(0, 1fr);
  }
}
