/* polish: drive-cost — see AGENTS.md (v77 polish pass). Loaded after trip.css. */
/* Scope: #carRentalView (租车 / 警讯退税 / 紧急求助) and #budgetView (预算现钞 / 行程记账).
   Layout, spacing and alignment only. Button skins belong to buttons.css. */

/* ==========================================================================
   1. Sub-tab bar + card stack rhythm (both tabs)
   ========================================================================== */
#carRentalView > .subtab-switch,
#budgetView > .subtab-switch {
  margin: 0 0 20px;
}

/* Every top-level card in a sub-panel: 16px between siblings, no stray top margins.
   The view header keeps 20px to the first content block. */
#carRentalView .subtab-panel > *,
#budgetView .subtab-panel > *,
#drivePanelEmergency > div > * {
  margin-top: 0 !important;
  margin-bottom: 16px !important;
}
#carRentalView .subtab-panel > .editorial-view-header,
#budgetView .subtab-panel > .editorial-view-header,
#drivePanelEmergency > div > .editorial-view-header {
  margin-bottom: 20px !important;
}
#carRentalView .subtab-panel > :last-child,
#budgetView .subtab-panel > :last-child,
#drivePanelEmergency > div > :last-child {
  margin-bottom: 0 !important;
}
#drivePanelEmergency > div {
  margin-bottom: 0 !important;
}

/* Card inner padding: 20px (16px on phones) */
#carRentalView .editorial-view-header,
#budgetView .editorial-view-header,
#carRentalView .settlement-card,
#budgetView .settlement-card,
#carRentalView .day-card,
#budgetView .expense-form-card,
#budgetView .expense-history-card {
  padding: 20px;
}

/* Section header inside a card: title → body 16px, divider 12px below the title block */
#carRentalView .settlement-header,
#budgetView .settlement-header {
  margin-bottom: 16px;
  padding-bottom: 12px;
  gap: 12px;
}
#carRentalView .settlement-title-box,
#budgetView .settlement-title-box {
  min-width: 0;
}

/* Small status badges never break inside themselves */
#carRentalView .cat-badge,
#budgetView .cat-badge {
  white-space: nowrap;
  flex-shrink: 0;
}

/* ==========================================================================
   2. 租车取车 panel
   ========================================================================== */

/* Quick-summary bento under the HM header */
#drivePanelCar .editorial-view-header > div[style*="padding: 14px 18px"] {
  padding: 16px !important;
}
#drivePanelCar .editorial-view-header > div[style*="padding: 14px 18px"] > div {
  gap: 12px 16px !important;
}

/* Card title + badge rows: title takes the space, badge pinned top-right */
#drivePanelCar div[style*="justify-content:space-between"]:has(> div[style*="font-weight:700"]) {
  align-items: flex-start !important;
  gap: 8px 12px;
}
#drivePanelCar div[style*="justify-content:space-between"]:has(> div[style*="font-weight:700"]) > div {
  min-width: 0;
  flex: 1 1 auto;
}
#drivePanelCar div[style*="justify-content:space-between"]:has(> div[style*="font-weight:700"]) > .cat-badge {
  margin-top: 2px;
}

/* 4 documents: inner cards 16px gap; 2 × 2 on wide screens instead of 3 + orphan */
#drivePanelCar .settlement-card > div[style*="display:grid"] {
  gap: 16px !important;
}
@media (min-width: 720px) {
  #drivePanelCar .settlement-card > div[style*="display:grid"]:has(> div[style*="border-top:3px solid var(--jp-shu)"]) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}
#drivePanelCar .settlement-card > div[style*="display:grid"] > div[style*="border-top:3px"] {
  padding: 16px !important;
}
#drivePanelCar .settlement-card ul {
  margin: 0;
}

/* Booking bento + snow/cash notices: sibling cards 16px apart */
#drivePanelCar > div[style*="display:grid"] {
  gap: 16px !important;
}
#drivePanelCar .day-card h4 {
  margin-bottom: 12px !important;
}
#drivePanelCar .day-card > div > div[style*="margin-bottom:6px"] {
  margin-bottom: 8px !important;
}
#drivePanelCar .day-card > div > div[style*="margin-bottom:6px"]:last-child {
  margin-bottom: 0 !important;
}
#drivePanelCar .day-card > div[style*="border-top:1px dashed"] {
  margin-top: 16px !important;
  padding-top: 12px !important;
  gap: 12px !important;
}
#drivePanelCar > div[style*="display:grid"] > .day-warning-box,
#drivePanelCar > div[style*="display:grid"] > div[style*="border-left:4px"] {
  padding: 16px !important;
  margin: 0 !important;
  gap: 12px;
}
#drivePanelCar > div[style*="display:grid"] > .day-warning-box > span:first-child {
  line-height: 1.2;
}

/* Fuel guide + MY vs JP guide: shared inner rhythm */
#drivePanelCar .settlement-card > div[style*="border-left:4px"],
#drivePanelCar .settlement-card > div[style*="background:var(--jp-subtle)"] {
  padding: 12px 16px !important;
  margin-bottom: 16px !important;
}
#drivePanelCar .settlement-card > div[style*="margin-bottom:18px"] {
  margin-bottom: 20px !important;
}
#drivePanelCar .settlement-card h4 {
  margin-bottom: 12px !important;
}
#drivePanelCar .settlement-card h4 + p {
  margin: -4px 0 12px !important;
}

/* Fuel-type cards, phrase cards, self-service steps, rule cards: one gap, one padding */
#drivePanelCar .settlement-card div[style*="display:grid"] {
  gap: 12px !important;
}
#drivePanelCar .settlement-card div[style*="display:grid"] > div[style*="padding:12px 14px"],
#drivePanelCar .settlement-card div[style*="display:grid"] > div[style*="padding:14px"],
#drivePanelCar .settlement-card div[style*="display:grid"] > div[style*="padding:10px 12px"] {
  padding: 16px !important;
}
#drivePanelCar .settlement-card div[style*="display:grid"] > div[style*="padding:10px 12px"] > div:first-child {
  margin-bottom: 8px !important;
}

/* Phrase card header: badge left, 发音/复制 right, wraps cleanly when the badge is long */
#drivePanelCar div[style*="justify-content:space-between"]:has(> div > .btn-share) {
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px !important;
}
#drivePanelCar div[style*="justify-content:space-between"]:has(> div > .btn-share) > div {
  display: flex;
  gap: 8px !important;
  flex-shrink: 0;
}
#drivePanelCar div[style*="justify-content:space-between"]:has(> div > .btn-share) > .cat-badge {
  white-space: normal;
  flex-shrink: 1;
  min-width: 0;
}

/* Receipt card: fills the rest of its row instead of leaving a hole */
@media (min-width: 720px) {
  #drivePanelCar div[style*="grid-column: span 1 / -1"] {
    grid-column: auto / span 2 !important;
  }
}

/* ==========================================================================
   3. 警讯退税 panel
   ========================================================================== */
#drivePanelTax .step-flow {
  margin: 0;
  gap: 16px;
}
#drivePanelTax .step-card {
  padding: 20px;
}
#drivePanelTax .step-num-badge {
  margin-bottom: 12px;
}
#drivePanelTax .settlement-card > .day-warning-box {
  margin-top: 16px !important;
}
#generalWarningsList > * {
  margin-top: 0;
  margin-bottom: 12px;
}
#generalWarningsList > :last-child {
  margin-bottom: 0;
}
#drivePanelTax .settlement-card > div[style*="margin-top:16px"] p {
  margin-top: 8px !important;
}

/* ==========================================================================
   4. 紧急求助 panel
   ========================================================================== */
#drivePanelEmergency .day-card h3 {
  margin-bottom: 12px !important;
}
#drivePanelEmergency .day-card h3 + p {
  margin: -4px 0 12px !important;
}
#drivePanelEmergency .emg-dial-grid {
  gap: 12px;
}
#drivePanelEmergency .emg-dial {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px 12px;
}
#drivePanelEmergency .emg-dial .emg-label {
  margin-top: 0;
  line-height: 1.35;
}
#drivePanelEmergency .emg-hotline,
#drivePanelEmergency .emg-area-card {
  padding: 16px;
  margin-bottom: 12px;
}
#drivePanelEmergency .emg-hotline:last-child,
#drivePanelEmergency .emg-area-card:last-child {
  margin-bottom: 0;
}
#drivePanelEmergency .emg-hotline-head,
#drivePanelEmergency .emg-area-head {
  gap: 4px 12px;
  margin-bottom: 8px;
}
#drivePanelEmergency .emg-hotline-meta,
#drivePanelEmergency .emg-area-facility {
  margin-bottom: 4px;
}
#drivePanelEmergency .emg-verified {
  margin-top: 8px;
}
#drivePanelEmergency .emg-note-item:first-child {
  padding-top: 0;
}
#drivePanelEmergency .emg-note-item:last-child {
  padding-bottom: 0;
}
#drivePanelEmergency .emg-note-icon {
  flex-shrink: 0;
  width: 24px;
  line-height: 1.3;
}

/* ==========================================================================
   5. 预算现钞 panel
   ========================================================================== */
#budgetView .expense-stats-grid {
  gap: 16px;
}
#budgetView .expense-stat-label {
  gap: 4px 8px;
  margin-bottom: 8px;
}
#budgetView .expense-stat-label > span:last-child {
  white-space: nowrap;
}
#budgetView .expense-stat-value {
  white-space: nowrap;
}
#costPanelBudget .settle-rule-banner {
  margin-bottom: 12px !important;
}
#costPanelBudget .settlement-table td {
  vertical-align: middle;
}
#costPanelBudget .settlement-table td a.btn-share-editorial {
  white-space: nowrap;
}

/* ==========================================================================
   6. 行程记账 panel
   ========================================================================== */
#costPanelExpense .cloud-sync-bar {
  margin-top: 16px;
  padding: 12px 16px;
  gap: 8px 12px;
}
#costPanelExpense .expense-form-card-header,
#costPanelExpense .expense-history-header {
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
}
#costPanelExpense .expense-form-card-header > div:first-child,
#costPanelExpense .expense-history-header > div:first-child {
  gap: 12px !important;
  min-width: 0;
}
#costPanelExpense .expense-form-title,
#costPanelExpense .expense-history-title {
  flex-wrap: wrap;
  row-gap: 4px;
}
#costPanelExpense .expense-form-title > span:first-child,
#costPanelExpense .expense-history-title > span:first-child {
  white-space: nowrap;
}

/* Form rows: label line (label left, helper right) */
#costPanelExpense .form-field-group > div[style*="justify-content:space-between"] {
  gap: 4px 12px !important;
  margin-bottom: 8px !important;
}
#expenseSelectedDayLabel {
  min-width: 0;
  overflow-wrap: anywhere;
}
#expenseQuickLocChips {
  gap: 6px !important;
  align-items: center;
}
#costPanelExpense .form-field-group > div[style*="align-items:flex-start"] {
  gap: 8px !important;
}
/* "当日推荐" label sits on the first chip row's centre line */
#costPanelExpense .form-field-group > div[style*="align-items:flex-start"] > span {
  padding-top: 0 !important;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
}

/* Expense history day navigation */
#costPanelExpense .expense-day-nav-banner {
  padding: 8px 12px;
  gap: 8px 12px;
  margin-bottom: 16px;
}
#costPanelExpense .expense-day-footer-nav {
  margin-top: 16px;
  padding: 12px 0 0;
  gap: 12px;
}
#costPanelExpense .expense-day-empty-inner {
  padding: 32px 20px !important;
}

/* Settlement card */
#costPanelExpense .settlement-table-wrap {
  margin-bottom: 20px;
}

/* ==========================================================================
   7. Phones
   ========================================================================== */
@media (max-width: 480px) {
  /* 3-way / 2-way sub-tab bar fits one row */
  #carRentalView > .subtab-switch,
  #budgetView > .subtab-switch {
    width: 100%;
    flex-wrap: nowrap;
    gap: 4px;
    padding: 4px;
  }
  #carRentalView > .subtab-switch > .subtab-btn,
  #budgetView > .subtab-switch > .subtab-btn {
    flex: 1 1 0;
    min-width: 0;
    justify-content: center;
  }

  #carRentalView .editorial-view-header,
  #budgetView .editorial-view-header,
  #carRentalView .settlement-card,
  #budgetView .settlement-card,
  #carRentalView .day-card,
  #budgetView .expense-form-card,
  #budgetView .expense-history-card {
    padding: 16px;
  }

  /* Header action groups: buttons share the row, full width */
  #carRentalView .editorial-view-actions > .btn-share-editorial,
  #budgetView .editorial-view-actions > .btn-share-editorial {
    flex: 1 1 auto;
  }

  /* Settlement header extras (badge / copy button) drop under the title, left edge aligned */
  #carRentalView .settlement-header > :not(.settlement-title-box),
  #budgetView .settlement-header > :not(.settlement-title-box),
  #costPanelExpense .expense-form-card-header > :not(:first-child),
  #costPanelExpense .expense-history-header > :not(:first-child) {
    margin-left: 46px;
  }

  #drivePanelCar .settlement-card > div[style*="display:grid"] > div[style*="border-top:3px"],
  #drivePanelCar .settlement-card div[style*="display:grid"] > div[style*="padding:12px 14px"],
  #drivePanelCar .settlement-card div[style*="display:grid"] > div[style*="padding:14px"] {
    padding: 16px !important;
  }

  #drivePanelTax .step-card {
    padding: 16px;
  }

  /* Emergency dials: three across */
  #drivePanelEmergency .emg-dial-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
  #drivePanelEmergency .emg-dial {
    padding: 12px 4px;
    min-height: 88px;
  }
  #drivePanelEmergency .emg-dial .emg-num {
    font-size: 1.4rem;
  }
  #drivePanelEmergency .emg-dial .emg-label {
    font-size: 0.7rem;
  }
  #drivePanelEmergency .emg-hotline,
  #drivePanelEmergency .emg-area-card {
    padding: 12px 16px;
  }

  /* Budget stats: one per row so label + tag + amount sit on clean lines */
  #costPanelBudget .expense-stats-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Expense stats (4 cards, 2 × 2): stack the label and its tag, keep amounts on one line */
  #costPanelExpense .expense-stats-grid {
    gap: 12px;
  }
  #costPanelExpense .expense-stat-card {
    padding: 12px;
  }
  #costPanelExpense .expense-stat-label {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
  }
  #costPanelExpense .expense-stat-value {
    font-size: 1.3rem;
  }

  /* Accommodation table → stacked rows: name, then SGD | MYR | 查看凭证 */
  #costPanelBudget .settlement-table thead {
    display: none;
  }
  #costPanelBudget .settlement-table,
  #costPanelBudget .settlement-table tbody {
    display: block;
  }
  #costPanelBudget .settlement-table tr {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 4px 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-washi-3);
  }
  #costPanelBudget .settlement-table tr:last-child {
    border-bottom: 0;
  }
  #costPanelBudget .settlement-table td {
    padding: 0 !important;
    border-bottom: 0;
  }
  #costPanelBudget .settlement-table td:first-child {
    grid-column: 1 / -1;
  }
  #costPanelBudget .settlement-table td:nth-child(3) {
    color: var(--color-sumi-600) !important;
    font-weight: 600 !important;
  }

  /* Member settlement table scrolls sideways instead of wrapping every cell */
  #costPanelExpense .settlement-table th,
  #costPanelExpense .settlement-table td {
    white-space: nowrap;
    padding: 10px 12px;
  }

  /* Day nav banner: title row, then ‹ / › side by side */
  #costPanelExpense .expense-day-nav-banner {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 8px;
  }
  #costPanelExpense .expense-day-nav-banner .expense-day-nav-title {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
  #costPanelExpense .expense-day-nav-banner .btn-day-step {
    justify-content: center;
  }
  #costPanelExpense .expense-day-footer-nav {
    gap: 8px;
  }

  /* Expense row: icon | title | amount + delete, tags run the full width below */
  #costPanelExpense .expense-card-item {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    column-gap: 12px;
    row-gap: 8px;
    align-items: center;
  }
  #costPanelExpense .expense-card-item .expense-item-left,
  #costPanelExpense .expense-card-item .expense-item-details {
    display: contents;
  }
  #costPanelExpense .expense-card-item .expense-item-icon-box {
    grid-column: 1;
    grid-row: 1;
  }
  #costPanelExpense .expense-card-item .expense-item-title {
    grid-column: 2;
    grid-row: 1;
    margin-bottom: 0;
  }
  #costPanelExpense .expense-card-item .expense-item-right {
    grid-column: 3;
    grid-row: 1;
    gap: 8px;
  }
  #costPanelExpense .expense-card-item .expense-item-tags {
    grid-column: 2 / -1;
    grid-row: 2;
  }
}

/* ==========================================================================
   8. Dark mode — only structural overrides above use theme tokens already;
      the stacked accommodation rows need the dark row divider.
   ========================================================================== */
@media (max-width: 480px) {
  :root[data-theme="dark"] #costPanelBudget .settlement-table tr {
    border-bottom-color: rgba(255, 255, 255, 0.08);
  }
}

/* 年末年始 plan button: trip.css inverts it to a pure-white block in dark mode,
   which breaks the "no white boxes in dark" rule. Use the dark primary (active sub-tab) fill. */
:root[data-theme="dark"] #drivePanelTax .shutdown-plan-btn {
  background: #2C4778;
  color: #F2F7FF;
  border-color: #2C4778;
}
#drivePanelTax .shutdown-plan-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ≤480px: inline auto-fit grids (minmax(240–320px, 1fr)) overflow a 320px screen.
   Clamp the column minimum to the available width. */
@media (max-width: 480px) {
  #carRentalView [style*="auto-fit"][style*="minmax("],
  #carRentalView [style*="auto-fill"][style*="minmax("],
  #budgetView [style*="auto-fit"][style*="minmax("],
  #budgetView [style*="auto-fill"][style*="minmax("] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}
