:root {
  --bg: #f7f5f0;
  --card: #fff;
  --accent: #2f855a;
  --text: #222;
  --muted: #666;
  --border: #e0ded7;
  --logo-color: #154122;
  --radius: 8px;
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  --font:
    "informapro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-header: "pinecone-mvb", sans-serif;
  --font-header-condensed: "pinecone-mvb-condensed", sans-serif;
  --font-header-wide: "pinecone-mvb-wide", sans-serif;
  --padding-sm: 0.75rem;
  --padding-md: 1rem;
  --padding-lg: 1.5rem;
}

:root.dark {
  --bg: #1a1a1a;
  --card: #262626;
  --accent: #48bb78;
  --text: #f0f0f0;
  --muted: #a0a0a0;
  --border: #404040;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --logo-color: #9ae6b4;
}

/* For system preference - only when theme isn't explicitly set */
@media (prefers-color-scheme: dark) {
  :root:not(.light):not(.dark) {
    --bg: #1a1a1a;
    --card: #262626;
    --accent: #48bb78;
    --text: #f0f0f0;
    --muted: #a0a0a0;
    --border: #404040;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --logo-color: #9ae6b4;
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-weight: 400;
  font-style: normal;
  font-size: 16px;
}

body {
  margin: 0 auto;
  max-width: 1280px;
  padding: var(--padding-md);
}

h1 {
  font-size: clamp(1.5rem, 4vw, 3rem);
  margin-bottom: 1rem;
  font-family: var(--font-header-wide);
  line-height: 1.1;
}

h2 {
  display: flex;
  align-items: center;
  font-family: var(--font-header);
  font-size: clamp(1.1rem, 3vw, 1.25rem);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0;
  margin-bottom: 0.5rem;
  -webkit-user-select: none;
  user-select: none;
  color: var(--logo-color);
}

/* Dialog styling */
dialog {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1rem, 5vw, 2rem);
  width: min(95%, 500px);
  box-shadow: var(--shadow);
  margin: auto;
}

dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.5);
}

dialog h3 {
  margin-bottom: 1rem;
}

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

dialog input[type="text"],
dialog input[type="url"],
dialog input[type="date"],
dialog textarea,
dialog select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--bg);
  color: var(--text);
  font-size: 16px; /* Prevents zoom on iOS */
}

dialog textarea {
  resize: vertical;
  min-height: 5rem;
}

dialog menu {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0;
}

.logo {
  width: auto;
  height: clamp(40px, 10vw, 70px);
  margin-right: 1.5rem;
  margin-left: 0.5rem;
}

/* Meta section */
.meta-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1rem;
  align-items: baseline;
}

.meta-grid .label {
  font-weight: bold;
}

.row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.row > label {
  flex: 1 1 200px;
}

/* Labels in forms */
label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* Buttons */
menu button,
button {
  padding: 0.5rem 1rem;
  background-color: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: bold;
  min-height: 44px; /* Better tap target */
  touch-action: manipulation;
}

button:hover {
  opacity: 0.9;
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  background-color: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Main layout & card styling */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.main-content h1 {
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  color: var(--logo-color);
}

.list-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background-color: var(--card);
  border-radius: var(--radius);
  padding: var(--padding-md);
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

/* Checklist styling */
.sectionHandle {
  cursor: grab;
  visibility: hidden;
  width: 0;
  opacity: 0.4;
  transition: all 0.2s ease-in-out;
}

h2:hover .sectionHandle {
  width: auto;
  margin-right: 0.5rem;
  visibility: visible;
}

.btnEditSection,
.btnDeleteSection {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.2s ease-in-out;
  padding: 0;
  font-size: 16px;
  width: 36px; /* Larger tap target */
  height: 36px; /* Larger tap target */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.25rem;
  min-height: auto;
}

.btnEditSection:hover,
.btnDeleteSection:hover {
  opacity: 1;
  color: var(--text);
}

.btnDeleteSection:hover {
  color: #e53e3e;
}

/* Positioning for section controls */
h2 {
  position: relative;
}

.btnEditSection,
.btnDeleteSection {
  position: relative;
  opacity: 0.35;
}

h2:focus-within .btnEditSection,
h2:focus-within .btnDeleteSection,
.btnEditSection:focus-visible,
.btnDeleteSection:focus-visible {
  opacity: 1;
}

.chevron {
  margin-left: auto;
  cursor: pointer;
  transition: transform 0.2s ease-in-out;
  min-width: 24px;
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

h2:hover .btnEditSection,
h2:hover .btnDeleteSection {
  opacity: 1;
}

#map {
  height: 100%;
}

.checklist {
  list-style-type: none;
  margin: 0;
  padding: 0;
  transition: max-height 0.3s ease-in-out;
  max-height: 2000px; /* Large enough for most lists */
  overflow: hidden;
}

.checklist.collapsed {
  max-height: 0;
}

.checklist li.item {
  display: flex;
  align-items: flex-start;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--border);
  position: relative;
  transition: background-color 0.2s ease;
}

.checklist li.item:last-child {
  border-bottom: none;
}

.checklist li.item:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

.checklist li.item .handle {
  cursor: grab;
  visibility: hidden;
  width: 0;
  opacity: 0.5;
  transition: all 0.2s ease-in-out;
}

li.item:hover .handle {
  width: auto;
  margin-right: 0.5rem;
  visibility: visible;
}

.checklist li.item input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 0.1875rem;
  min-width: 20px;
  min-height: 20px;
}

.checklist li.item label {
  flex-grow: 1;
  cursor: pointer;
  padding-left: 0.5rem;
  display: block;
  width: 100%;
  margin-bottom: 0; /* Needed to override previous label styles */
}

.checklist li.item.checked label {
  text-decoration: line-through;
  opacity: 0.6;
}

.actions {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
  opacity: 0;
  transition: opacity 0.2s ease-in-out;
}

li.item:hover .actions,
li.item:focus-within .actions {
  opacity: 1;
}

.actions button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  margin: 0;
  padding: 0.25rem;
  font-size: 0.875rem;
  transition: color 0.2s ease;
  min-height: 36px; /* Larger tap target */
  min-width: 36px; /* Larger tap target */
}

.actions button:hover {
  color: var(--text);
}

.btnDel:hover {
  color: #e53e3e;
}

/* Section & Item dragging styles */
.dragging {
  opacity: 0.5;
}

li.item-over {
  border-top: 2px solid var(--accent);
}

.section-dragging {
  opacity: 0.5;
}

.section-over {
  box-shadow: 0 0 0 2px var(--accent);
}

/* Drag ghost element (for previewing drags) */
.drag-ghost {
  position: absolute;
  top: -1000px; /* Hidden but rendered for drag image */
  background-color: var(--accent);
  color: white;
  padding: 0.5rem;
  border-radius: var(--radius);
  pointer-events: none;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.875rem;
}

/* Form Styling */
.addItem {
  display: flex;
  margin-top: 0.5rem;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.addItem input[type="text"] {
  flex-grow: 1;
  flex-basis: 65%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px; /* Prevents zoom on iOS */
  background-color: var(--bg);
  color: var(--text);
  min-height: 44px; /* Better tap target */
}

.addItem button {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

.addSection {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.addSection input[type="text"] {
  flex-grow: 1;
  flex-basis: 65%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px; /* Prevents zoom on iOS */
  background-color: var(--bg);
  color: var(--text);
  min-height: 44px; /* Better tap target */
}

.addSection button {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

/* Sidebar styling */
.sidebar-section {
  background-color: var(--card);
  border-radius: var(--radius);
  padding: var(--padding-md);
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.sidebar-section h3 {
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
  color: var(--logo-color);
  font-family: var(--font-header-condensed);
}

/* Controls section */
.controls {
  background-color: var(--card);
  border-radius: var(--radius);
  padding: var(--padding-md);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.controls-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* Item notes styling */
.details-note {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--muted);
  background-color: rgba(0, 0, 0, 0.02);
  border-radius: var(--radius);
  padding: 0.5rem;
  margin-bottom: 0.25rem;
}

.details-note summary {
  cursor: pointer;
  font-weight: 500;
}

.details-note div {
  margin-top: 0.5rem;
  white-space: pre-wrap;
}

.btnNote.has-note {
  color: #38b2ac;
}

/* Weight badges */
.item-with-weight .btnWeight {
  color: #38a169;
}

.item-with-permit {
  position: relative;
}

.item-with-permit::after {
  content: "!";
  position: absolute;
  top: 2px;
  right: 2px;
  background-color: orange;
  color: white;
  width: 16px;
  height: 16px;
  font-size: 10px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

/* Sidebar toggles */
.weight-sidebar {
  position: relative;
  transition:
    max-height 0.3s ease-in-out,
    opacity 0.3s ease-in-out;
  max-height: 800px;
  opacity: 1;
}

.weight-sidebar.collapsed {
  max-height: 40px;
  overflow: hidden;
  opacity: 0.8;
}

.toggle-sidebar {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
  opacity: 0.6;
  transition: opacity 0.2s ease;
  min-height: 36px;
  min-width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toggle-sidebar:hover {
  opacity: 1;
}

/* Weight breakdown display */
.weight-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
}

.weight-unit-selector {
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.weight-total,
.weight-packed {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.weight-sections {
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

.weight-section {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
}

.weight-section-title {
  font-weight: 500;
}

.weight-section-value {
  text-align: right;
  display: flex;
  flex-direction: column;
  color: var(--muted);
}

/* Toast notifications */
#toastContainer {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(24rem, 90vw);
}

.toast {
  background-color: var(--card);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  border-left: 4px solid var(--accent);
  opacity: 0;
  transform: translateY(1rem);
  transition:
    opacity 0.3s ease,
    transform 0.3s ease;
  max-width: 100%;
  word-break: break-word;
}

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

.toast.info {
  border-left-color: #3182ce;
}

.toast.success {
  border-left-color: #38a169;
}

.toast.warning {
  border-left-color: #dd6b20;
}

.toast.error {
  border-left-color: #e53e3e;
}

/* Filter styling */
.filter-container {
  position: relative;
  margin-bottom: 1rem;
}

#filterInput {
  width: 100%;
  padding: 0.5rem 2rem 0.5rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px; /* Prevents zoom on iOS */
  background-color: var(--bg);
  color: var(--text);
  min-height: 44px; /* Better tap target */
}

#filterInput::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.clear-btn {
  position: absolute;
  right: 0.5rem;
  top: 4px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  font-size: 1rem;
  min-height: 36px;
  min-width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.clear-btn {
  z-index: 2;
}
.clear-btn[hidden] {
  display: none;
}

.filter-no-results {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--muted);
  font-style: italic;
}

/* Filtered items */
.filtered-out {
  display: none;
}

mark {
  background-color: rgba(255, 213, 0, 0.3);
  padding: 0.1rem 0;
  border-radius: 2px;
}

/* Weight Dialog */
.dialog-item-text {
  font-weight: bold;
  margin-bottom: 1rem;
}

.dialog-row {
  display: flex;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.dialog-row label {
  min-width: 100px;
  flex: 1 0 100px;
  display: inline-block;
  margin-right: 1rem;
}

.dialog-row input[type="number"] {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex: 1;
  font-size: 16px; /* Prevents zoom on iOS */
  min-height: 44px; /* Better tap target */
}

.dialog-row input[type="checkbox"] {
  min-width: 24px;
  min-height: 24px;
}

.dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Cost Section */
.cost-summary {
  margin-bottom: 1rem;
}

.cost-total {
  margin-bottom: 0.5rem;
  font-weight: bold;
}

.cost-section {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
}

.cost-section-title {
  font-weight: 500;
}

.cost-section-value {
  text-align: right;
  color: var(--muted);
}

.cost-input-wrapper {
  position: relative;
  flex: 1;
}

.currency-symbol {
  position: absolute;
  left: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

.cost-row input {
  padding-left: 1.5rem !important;
}

/* Permits & Regulations */
.permits-section {
  margin-bottom: 1rem;
}

.permit-info {
  margin-bottom: 1rem;
}

.permit-info > div {
  margin-bottom: 0.5rem;
  display: flex;
  flex-wrap: wrap;
}

.permit-info > div > span:first-child {
  font-weight: bold;
  margin-right: 0.5rem;
  min-width: 80px;
}

.permit-url-container {
  display: flex;
  flex-wrap: wrap;
}

a.disabled-link {
  color: var(--muted);
  text-decoration: none;
  pointer-events: none;
}

.permit-required-items {
  margin-top: 1rem;
}

.permit-required-items h4 {
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
}

.permit-required-items ul {
  margin-left: 1rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.dialog-section-title {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.fire-rules-text {
  white-space: pre-line;
}

/* Past due styling */
.past-due {
  color: #e53e3e;
  font-weight: bold;
}

/* Icon for warning badge */
.item-with-permit::before {
  content: "⚠️";
  position: absolute;
  top: 0.25rem;
  left: -5px;
  color: orange;
}

/* Permit deadline warning */
.permit-deadline.warning {
  color: #e53e3e;
  font-weight: bold;
}

/* --- Google Maps Autocomplete Styles --- */
.destination-container {
  position: relative;
  width: 100%;
  margin-bottom: 16px;
}

gmp-place-autocomplete {
  width: 100%;
  box-sizing: border-box;
  border-radius: var(--radius);
  margin-top: 4px;
}

.hidden {
  display: none !important;
}
/* --- End Google Maps Autocomplete Styles --- */

/* --- Mobile First Media Queries --- */
@media (min-width: 768px) {
  body {
    padding: var(--padding-lg);
  }

  .main-content {
    flex-direction: row;
  }

  .main-content > *:first-child {
    flex: 2;
  }

  .list-sidebar {
    flex: 1;
    min-width: 240px;
  }

  .dialog-row label {
    min-width: 150px;
  }

  /* Show action buttons on desktop hover */
  .actions {
    opacity: 0;
  }

  li.item:hover .actions {
    opacity: 1;
  }

  /* Make buttons smaller on desktop */
  menu button,
  button,
  .addItem input[type="text"],
  .addSection input[type="text"],
  #filterInput {
    min-height: unset;
  }
}

/* For touch devices, always show actions */
@media (hover: none) {
  .actions {
    opacity: 1;
  }

  h2 .btnEditSection,
  h2 .btnDeleteSection {
    opacity: 0.7;
  }

  li.item .handle,
  h2 .sectionHandle {
    width: auto;
    margin-right: 0.5rem;
    visibility: visible;
  }
}

/* --- Dark mode tweaks --- */
@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --bg: #1a1a1a;
    --card: #262626;
    --accent: #48bb78;
    --text: #f0f0f0;
    --muted: #a0a0a0;
    --border: #404040;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

/* --- Print Styles --- */
@media print {
  body {
    padding: 0;
    background: white;
    color: black;
  }

  .main-content {
    display: block;
  }

  .list-sidebar,
  .controls,
  .actions,
  .addItem,
  .addSection,
  .filter-container,
  .btnDeleteSection,
  .btnEditSection,
  .weight-sidebar,
  .handle,
  .sectionHandle {
    display: none !important;
  }

  .card {
    border: none;
    box-shadow: none !important;
    padding: 0;
    margin-bottom: 0.5rem;
  }

  h1 {
    text-align: center;
    font-size: 1.5rem;
    margin-bottom: 1rem;
    font-family: var(--font-header);
  }

  h2 {
    font-size: 1.2rem;
    margin-top: 1rem;
    page-break-after: avoid;
  }

  .checklist li.item {
    padding: 0.25rem 0;
    border-bottom: none;
  }

  input[type="checkbox"] {
    margin-right: 0.5rem;
  }

  .details-note {
    margin-left: 1.5rem;
    font-size: 0.8rem;
  }

  .checklist li.item.checked label {
    text-decoration: line-through;
  }

  .meta-grid {
    margin-top: 1rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
  }

  @page {
    margin: 2cm;
  }
}

/* =========================================================
   v2 additions: header, lists bar, storage, templates, sponsors, dialogs, a11y
   ========================================================= */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0.5rem;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  z-index: 2000;
}
.skip-link:focus {
  left: 0.5rem;
}

:focus-visible {
  outline: 3px solid #f6ad55;
  outline-offset: 2px;
}

.muted {
  color: var(--muted);
}
.small {
  font-size: 0.875rem;
}
.pre-line {
  white-space: pre-line;
}
.error-text {
  color: #e53e3e;
}
.danger-text {
  color: #c53030;
}
button.danger {
  background-color: #c53030;
  color: #fff;
}
.notice {
  background: rgba(246, 173, 85, 0.15);
  border: 1px solid rgba(246, 173, 85, 0.5);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  margin: 0.5rem 0;
}

/* Header */
.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}
.app-header h1 {
  margin: 0;
  display: flex;
  align-items: center;
  color: var(--logo-color);
}
.app-header .logo {
  height: clamp(40px, 8vw, 64px);
  width: auto;
  margin-right: 0.75rem;
  margin-left: 0;
}
.wordmark .tld {
  font-size: 0.55em;
  opacity: 0.6;
  font-family: var(--font-header);
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.account-button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}
.avatar-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-weight: bold;
  font-size: 0.9rem;
}

/* Lists bar */
.list-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.75rem var(--padding-md);
}
.list-select-label {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  flex: 1 1 220px;
  font-weight: bold;
}
.list-select-label select {
  flex: 1;
  min-width: 0;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-weight: normal;
  min-height: 44px;
}
.list-bar-actions {
  display: flex;
  gap: 0.35rem;
}
.small-button {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  min-height: 36px;
}
.list-bar .storage-status {
  flex-basis: 100%;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Storage panel */
.storage-provider {
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
  margin-top: 0.5rem;
}
.storage-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  align-items: baseline;
}
.storage-status {
  font-size: 0.875rem;
  margin: 0.4rem 0;
}
.storage-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
}
.storage-badge-off {
  color: var(--muted);
}
.storage-connect .storage-status {
  margin-top: 0.25rem;
}
.storage-connect p.small {
  margin: 0.25rem 0 0.5rem;
}
.status-saved {
  color: var(--accent);
}
.status-unsaved,
.status-conflict,
.status-reauth {
  color: #c05621;
}
.status-error {
  color: #e53e3e;
}
.status-working,
.status-offline,
.status-idle {
  color: var(--muted);
}
.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.link-button {
  background: none;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  padding: 0.1rem 0.25rem;
  min-height: auto;
  font-weight: normal;
  font-size: inherit;
}
.link-button:hover {
  opacity: 1;
  color: var(--text);
}
.button-like {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  text-align: center;
}
.upload-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}
.upload-row progress {
  flex: 1;
  min-width: 120px;
}
.pick-list {
  list-style: none;
  margin: 0.5rem 0;
  padding: 0;
  max-height: 50vh;
  overflow: auto;
}
.pick-list li {
  border-bottom: 1px solid var(--border);
}
.pick-row {
  width: 100%;
  text-align: left;
  background: none;
  color: var(--text);
  border: none;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.6rem 0.25rem;
  border-radius: 0;
  font-weight: normal;
}
.pick-row:hover {
  background: rgba(0, 0, 0, 0.04);
}
.pick-title {
  font-weight: bold;
}
.file-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  align-items: baseline;
  padding: 0.5rem 0.25rem;
}
.file-row .pick-title {
  flex: 1 1 200px;
  word-break: break-word;
}
.file-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Items */
.tag {
  display: inline-block;
  font-size: 0.7rem;
  line-height: 1.2;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  vertical-align: middle;
  margin-left: 0.25rem;
  text-decoration: none;
}
.tag-optional {
  background: rgba(0, 0, 0, 0.03);
}
.tag-permit {
  border-color: #dd6b20;
  color: #c05621;
}
.item-optional label {
  color: var(--muted);
}
.section-count {
  margin-left: 0.5rem;
  font-family: var(--font);
  font-weight: normal;
}
h2 .chevron {
  background: none;
  border: none;
  color: var(--text);
  padding: 0;
  min-height: 36px;
  min-width: 36px;
  font-size: 1.1rem;
}
.checklist li.item input[type="checkbox"] {
  accent-color: var(--accent);
}
section.card.filtered-out {
  display: none;
}
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
}
.empty-state button {
  margin-top: 1rem;
}
.map-link {
  font-size: 0.85rem;
}
h2.plain {
  cursor: default;
}

/* Dialogs */
.app-dialog menu {
  flex-wrap: wrap;
}
.app-dialog-message {
  white-space: pre-line;
}
.app-dialog-field {
  margin-top: 0.5rem;
}
.app-dialog-field input {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  min-height: 44px;
}
.wide-dialog {
  width: min(96%, 760px);
  max-height: 90vh;
  overflow: auto;
}
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.dialog-header h3 {
  margin-bottom: 0;
}
.destination-block {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.destination-container:empty {
  display: none;
}

/* Templates */
.template-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin: 0.5rem 0 0.75rem;
}
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}
.tabs button {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.35rem 0.7rem;
  min-height: 36px;
  font-size: 0.85rem;
  font-weight: normal;
}
.tabs button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
#templateSearch {
  flex: 1 1 180px;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  min-height: 40px;
}
.template-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.6rem;
}
.template-card {
  width: 100%;
  height: 100%;
  text-align: left;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: normal;
}
.template-card:hover {
  border-color: var(--accent);
  opacity: 1;
}
.template-card-title {
  font-weight: bold;
  font-family: var(--font-header);
  color: var(--logo-color);
}
.template-card-tagline {
  font-size: 0.9rem;
}
.template-title {
  font-family: var(--font-header);
  font-size: 1.3rem;
  color: var(--logo-color);
  margin: 0.5rem 0;
}
#templateDetail h5 {
  margin: 1rem 0 0.25rem;
}
#templateDetail ul {
  margin-left: 1.2rem;
}
#templateDetail details {
  margin-top: 0.75rem;
}
#templateDetail menu {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0;
}

/* Sponsor / ad slots */
.ad-slot {
  min-height: 0;
  margin: 1rem 0;
}
.ad-slot:empty,
.ad-slot[hidden] {
  display: none;
}
.sponsor-card {
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 0.75rem var(--padding-md);
  min-height: 110px;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.sponsor-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.sponsor-title {
  font-weight: bold;
  color: var(--logo-color);
  text-decoration: none;
}
.sponsor-text {
  font-size: 0.875rem;
  color: var(--muted);
}
.sponsor-cta {
  font-size: 0.875rem;
  color: var(--accent);
}
.ad-slot-footer .sponsor-card {
  margin-top: 1.5rem;
}

/* Links styled like the app's buttons */
.button-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  line-height: 1.2;
}
.button-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.button-link[aria-current="page"] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.button-link.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.button-link.primary:hover {
  filter: brightness(1.08);
}
.button-link.big {
  font-size: 1.1rem;
  padding: 0.7rem 1.3rem;
}

/* Sign-in */
.signin-slot {
  display: flex;
  justify-content: center;
  min-height: 44px;
  margin: 0.75rem 0;
}
/* The flex display above would otherwise override the hidden attribute (unconfigured provider). */
.signin-slot[hidden] {
  display: none;
}
.ms-button {
  width: 260px;
}
.account-area:empty {
  display: none;
}

/* Dark mode tweaks for v2 elements */
:root.dark .template-card,
:root.dark .sponsor-card,
:root.dark .pick-row:hover {
  background: rgba(255, 255, 255, 0.03);
}
@media (prefers-color-scheme: dark) {
  :root:not(.light) .template-card,
  :root:not(.light) .sponsor-card {
    background: rgba(255, 255, 255, 0.03);
  }
}

@media (max-width: 480px) {
  .list-bar-actions {
    width: 100%;
    justify-content: flex-start;
  }
  .header-actions {
    width: 100%;
    justify-content: space-between;
  }
  .ms-button,
  .signin-slot {
    width: 100%;
  }
}

@media print {
  .app-header .header-actions,
  .list-bar,
  .ad-slot,
  .storage-panel,
  .skip-link,
  .tag-optional {
    display: none !important;
  }
}
