:root {
  color-scheme: light dark;

  &:has(> head > meta[name="color-scheme"][content="dark"]) {
    color-scheme: dark;
  }
  &:has(> head > meta[name="color-scheme"][content="light"]) {
    color-scheme: light;
  }

  --bg: light-dark(#f1f5f9, #0b1220);
  --surface: light-dark(#ffffff, #111b2e);
  --surface-alt: light-dark(#f8fafc, #162238);
  --border: light-dark(#dbe3ee, #24344f);
  --text: light-dark(#0f172a, #e2e8f0);
  --muted: light-dark(#526277, #94a3b8);
  --primary: light-dark(#0369a1, #38bdf8);
  --primary-fg: light-dark(#ffffff, #082f49);
  --primary-hover: light-dark(#075985, #7dd3fc);
  --accent: light-dark(#0f766e, #2dd4bf);
  --danger: light-dark(#b91c1c, #f87171);
  --danger-bg: light-dark(#fef2f2, #3b1219);
  --warn-bg: light-dark(#fff7ed, #3a200d);
  --warn-fg: light-dark(#c2410c, #fdba74);
  --ok-bg: light-dark(#ecfdf5, #0c3329);
  --ok-fg: light-dark(#047857, #6ee7b7);
  --club-bg: light-dark(#eef2ff, #1e1b4b);
  --club-fg: light-dark(#4338ca, #a5b4fc);
  --shadow: 0 1px 3px rgb(15 23 42 / 0.08), 0 4px 12px rgb(15 23 42 / 0.05);
  --radius: 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.topbar-inner {
  max-width: 1380px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.25rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-icon {
  font-size: 1.75rem;
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.main-tabs {
  display: flex;
  gap: 0.35rem;
  background: var(--surface-alt);
  padding: 0.25rem;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.tab-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow);
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  padding: 0.05rem 0.42rem;
  font-size: 0.75rem;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-fg);
}

/* Container & Cards */
.container {
  max-width: 1380px;
  margin: 0 auto;
  padding: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.banner {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.9rem;
  font-weight: 500;
}

.banner.ok {
  background: var(--ok-bg);
  color: var(--ok-fg);
  border-color: transparent;
}

.banner.error {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: transparent;
}

/* KPIs */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.kpi-highlight {
  border-color: var(--accent);
}

.kpi-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}

.kpi-value {
  font-size: 1.55rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

.kpi-highlight .kpi-value {
  color: var(--accent);
}

.kpi-sub {
  font-size: 0.8rem;
  color: var(--muted);
}

/* Filters */
.filter-bar {
  padding: 1rem;
  margin-bottom: 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 0.75rem;
  align-items: end;
}

.filter-search {
  grid-column: span 2;
}

@media (max-width: 700px) {
  .filter-search {
    grid-column: span 1;
  }
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.filter-group label,
.field > label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.filter-toggles {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding-top: 0.25rem;
}

/* Inputs & Buttons */
input[type="text"],
input[type="search"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="password"],
select {
  width: 100%;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible,
.table-wrapper:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Validate input after interaction */
.hint {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 0.25rem;
}

.error-msg {
  display: none;
  color: var(--danger);
  font-size: 0.82rem;
  margin-top: 0.25rem;
}

:is(:user-invalid, .user-invalid-fallback) {
  border-color: var(--danger) !important;
  background-color: var(--danger-bg) !important;
}

:is(:user-invalid, .user-invalid-fallback) + .error-msg {
  display: block;
}

input:user-valid {
  border-color: var(--accent);
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.52rem 0.95rem;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-fg);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--primary);
}

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

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-alt);
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.36rem 0.65rem;
}

.checkbox-pill,
.radio-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 0.84rem;
  cursor: pointer;
  user-select: none;
}

.checkbox-pill:has(input:checked),
.radio-pill:has(input:checked) {
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

/* Responsive Data Table (modern-web-guidance: responsive-table) */
.table-card {
  overflow: hidden;
}

.table-toolbar {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.85rem;
}

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

.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(680px, 74vh);
  container-type: inline-size;
}

#offers-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  --label-1: "Cruzeiro";
  --label-2: "Embarque";
  --label-3: "Cabine & Ocupação";
  --label-4: "Tarifa & Sinais";
  --label-5: "Por Pessoa";
  --label-6: "Total / Noite";
  --label-7: "Ação";
}

#offers-table thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
}

#offers-table thead th {
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: left;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

#offers-table thead th.num,
#offers-table tbody td.num {
  text-align: right;
}

#offers-table tbody th,
#offers-table tbody td {
  padding: 0.8rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 0.88rem;
}

#offers-table tbody th {
  position: sticky;
  inset-inline-start: 0;
  z-index: 1;
  background: var(--surface);
  text-align: left;
  font-weight: 600;
  min-width: 230px;
}

#offers-table tbody tr.row-exceptional th,
#offers-table tbody tr.row-exceptional td {
  background: color-mix(in srgb, var(--ok-bg) 55%, var(--surface));
}

#offers-table tbody tr:hover th,
#offers-table tbody tr:hover td {
  background: var(--surface-alt);
}

.empty-cell {
  text-align: center;
  padding: 2.5rem 1rem !important;
  color: var(--muted);
}

/* Badges & Cell Typography */
.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.3rem;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.12rem 0.45rem;
  border-radius: 5px;
  letter-spacing: 0.02em;
}

.badge-deal {
  background: var(--ok-bg);
  color: var(--ok-fg);
}

.badge-lm {
  background: var(--warn-bg);
  color: var(--warn-fg);
}

.badge-club {
  background: var(--club-bg);
  color: var(--club-fg);
}

.badge-drinks {
  background: color-mix(in srgb, var(--primary) 15%, transparent);
  color: var(--primary);
}

.ship-title {
  font-size: 0.95rem;
  font-weight: 700;
}

.ports-line {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 400;
  margin-top: 0.15rem;
}

.price-main {
  font-size: 1.08rem;
  font-weight: 800;
  color: var(--accent);
  white-space: nowrap;
}

.price-sub {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}

.reasons-list {
  margin: 0.25rem 0 0;
  padding-left: 1rem;
  font-size: 0.77rem;
  color: var(--muted);
}

.action-stack {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: flex-end;
}

/* Container Query Stacked Card Layout (responsive-table) */
@container (width < 820px) {
  #offers-table,
  #offers-table thead,
  #offers-table tbody,
  #offers-table tr,
  #offers-table th,
  #offers-table td {
    display: block;
  }

  #offers-table thead {
    display: none;
  }

  #offers-table tbody tr {
    margin: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
  }

  #offers-table tbody th {
    position: sticky;
    inset-block-start: 0;
    inset-inline-start: auto;
    z-index: 2;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
  }

  #offers-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    text-align: right;
  }

  #offers-table tbody td::before {
    font-weight: 600;
    color: var(--muted);
    font-size: 0.78rem;
    text-align: left;
    flex-shrink: 0;
  }

  #offers-table tbody td:nth-child(2)::before { content: var(--label-2) ": "; }
  #offers-table tbody td:nth-child(3)::before { content: var(--label-3) ": "; }
  #offers-table tbody td:nth-child(4)::before { content: var(--label-4) ": "; }
  #offers-table tbody td:nth-child(5)::before { content: var(--label-5) ": "; }
  #offers-table tbody td:nth-child(6)::before { content: var(--label-6) ": "; }
  #offers-table tbody td:nth-child(7)::before { content: var(--label-7) ": "; }

  .action-stack {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}

/* Settings */
.settings-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.settings-card {
  padding: 1.25rem;
}

.settings-card h2 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
}

.card-desc {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.form-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field-row-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.9rem;
}

.field-row-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.9rem;
}

.dual-input {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.chips-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.switch-row {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  cursor: pointer;
}

.field-check-inline {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.15rem 0;
}

.notif-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 1rem;
}

.notif-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.notif-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.theme-segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.settings-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: flex-end;
}

.mt-sm { margin-top: 0.55rem; }
.mt-md { margin-top: 1rem; }

/* Activity */
.activity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1rem;
}

.activity-grid .card {
  padding: 1.15rem;
}

.activity-grid h2 {
  margin: 0 0 0.85rem;
  font-size: 1.05rem;
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.log-item {
  padding: 0.7rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 0.84rem;
}

.log-item-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

/* Native Modal Dialog (modern-web-guidance: dialog) */
dialog {
  width: min(720px, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgb(0 0 0 / 0.35);
}

dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgb(15 23 42 / 0.6);
  backdrop-filter: blur(2px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.dialog-body {
  padding: 1.15rem 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.dialog-footer {
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.65rem;
}

.detail-stat {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
}

.detail-stat span {
  display: block;
  font-size: 0.74rem;
  color: var(--muted);
}

.detail-stat strong {
  font-size: 1rem;
}

.booking-guide {
  background: var(--ok-bg);
  color: var(--ok-fg);
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  font-size: 0.85rem;
}

.chart-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
}

.chart-box svg {
  width: 100%;
  height: 150px;
  display: block;
}
