:root {
  --bg: #f7faf9;
  --surface: #ffffff;
  --surface-alt: #eef6f5;
  --surface-alt-2: #f3f8f7;
  --text: #0f172a;
  --muted: #5f6b7a;
  --border: #d9e3e1;
  --border-strong: #bfd0cc;

  --primary: #0f766e;
  --primary-hover: #0d5e58;
  --primary-soft: rgba(15, 118, 110, 0.10);

  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: rgba(220, 38, 38, 0.10);

  --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 6px 18px rgba(15, 23, 42, 0.06);

  --radius: 16px;
  --radius-sm: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #111827;
    --surface-alt: #0f172a;
    --surface-alt-2: #101a2d;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #243041;
    --border-strong: #334155;

    --primary: #2aa198;
    --primary-hover: #1d837c;
    --primary-soft: rgba(42, 161, 152, 0.16);

    --danger: #f87171;
    --danger-hover: #ef4444;
    --danger-soft: rgba(248, 113, 113, 0.14);

    --shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
    --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.22);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  overflow-x: hidden;
}

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

.container {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px 18px;
  background: linear-gradient(to bottom, var(--surface), var(--surface-alt));
  border-bottom: 1px solid var(--border);
}

h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}


.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

h3,
h4 {
  margin: 0;
  color: var(--text);
  letter-spacing: -0.01em;
}

h3 {
  font-size: 1rem;
  font-weight: 700;
}

h4 {
  font-size: 0.92rem;
  font-weight: 650;
  color: var(--muted);
  margin-top: 4px;
}

.tabs {
  display: inline-flex;
  gap: 8px;
  padding: 4px;
  background: var(--surface-alt-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.tab-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.tab-btn:hover {
  background: rgba(95, 107, 122, 0.10);
  color: var(--text);
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.22);
}

.panel-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: 78vh;
}

.left-column {
  min-width: 0;
  padding: 18px;
  border-right: 1px solid var(--border);
  background: var(--surface-alt);
}

.right-column {
  min-width: 0;
  padding: 22px;
  overflow-y: auto;
  background: var(--surface);
}

.left-tools {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.hidden {
  display: none !important;
}

label {
  display: block;
  font-size: 0.93rem;
  font-weight: 650;
  margin: 12px 0 7px;
  color: var(--text);
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 12px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

textarea {
  resize: vertical;
  min-height: 52px;
}

.inline-actions,
.button-container {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.inline-actions {
  margin: 14px 0;
}

.button-container {
  margin-top: 18px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

button {
  appearance: none;
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease, opacity 0.18s ease, color 0.18s ease;
}

button:hover {
  background: var(--surface-alt);
  border-color: var(--border-strong);
}

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

/* Left-panel utility actions */
.inline-actions > button {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.inline-actions > button:hover {
  background: var(--surface-alt);
  border-color: var(--border-strong);
}

/* Copy actions */
#copyAdviceBtn {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.16);
}

#copyAdviceBtn:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

#copyBookingOfficeBtn,
#copyLeafletTitleUrlBtn {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}

#copyBookingOfficeBtn:hover,
#copyLeafletTitleUrlBtn:hover {
  background: var(--surface-alt-2);
  border-color: var(--border-strong);
}

/* Save actions = only strong primary emphasis */
#saveTemplateBtn,
#saveLeafletBtn {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.16);
}

#saveTemplateBtn:hover,
#saveLeafletBtn:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

/* New actions = softer, clearly not primary */
#newTemplateBtn,
#newLeafletBtn {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

#newTemplateBtn:hover,
#newLeafletBtn:hover {
  background: var(--surface-alt);
  border-color: var(--border-strong);
}

/* Delete = separated and clearly destructive */
#deleteTemplateBtn,
#deleteLeafletBtn {
  background: var(--danger-soft);
  border-color: rgba(220, 38, 38, 0.22);
  color: var(--danger);
}

#deleteTemplateBtn:hover,
#deleteLeafletBtn:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.settings-group {
  position: relative;
}

.settings-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-color: var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.settings-btn:hover {
  background: var(--surface-alt-2);
  border-color: var(--border-strong);
  color: var(--text);
}

.settings-btn:focus-visible {
  background: var(--surface);
  border-color: var(--primary);
  color: var(--text);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.settings-icon {
  width: 16px;
  height: 16px;
  display: block;
  fill: currentColor;
}

.settings-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  padding: 10px;
  z-index: 30;
}

.settings-section + .settings-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.settings-label {
  margin: 0 0 8px;
  font-size: 0.86rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.settings-option {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 0.92rem;
  font-weight: 500;
}

.settings-option input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
}

.settings-actions button {
  width: 100%;
  margin-bottom: 6px;
  text-align: left;
}

.settings-actions button:last-child {
  margin-bottom: 0;
}

.label-with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}

.label-with-action label {
  margin: 0;
}

.inline-copy-btn {
  padding: 5px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border-color: var(--border);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.inline-copy-btn:hover {
  background: var(--surface-alt);
  border-color: var(--border-strong);
}

.copy-icon {
  position: relative;
  width: 14px;
  height: 14px;
}

.copy-icon::before,
.copy-icon::after {
  content: '';
  position: absolute;
  border: 1.5px solid var(--muted);
  border-radius: 3px;
  width: 10px;
  height: 10px;
}

.copy-icon::before {
  top: 0;
  left: 4px;
}

.copy-icon::after {
  top: 4px;
  left: 0;
  background: var(--surface);
}

.toast-container {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  box-shadow: var(--shadow-soft);
  font-size: 0.88rem;
  opacity: 0;
  transform: translateY(6px);
  animation: toast-in 0.2s ease forwards;
}

@keyframes toast-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.title-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 8px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.category-header {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 6px 0 4px;
  padding: 8px 8px 6px;
  background: linear-gradient(to bottom, var(--surface), var(--surface));
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.title-list-item {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.title-list-item:hover {
  background: var(--surface-alt);
  border-color: var(--border);
}

.title-list-item.selected {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.item-sub {
  display: block;
  margin-top: 3px;
  font-size: 0.82rem;
  color: var(--muted);
}

#templatesEditor,
#leafletsEditor {
  display: flex;
  flex-direction: column;
  gap: 0;
}

#templatesEditor > label:first-of-type,
#leafletsEditor > label:first-of-type {
  margin-top: 0;
}

.leaflet-link-panel {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-alt);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.leaflet-link-panel h3 {
  margin-bottom: 4px;
}

.leaflet-selector {
  max-height: 220px;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  padding: 8px;
  margin-top: 4px;
}

.selector-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 8px 8px;
  border-radius: 10px;
  cursor: pointer;
  min-width: 0;
}

.selector-item:hover {
  background: var(--surface-alt);
}

.selector-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--primary);
  flex: 0 0 auto;
}

.selector-item span {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.35;
  color: var(--text);
  font-size: 0.92rem;
}

#templateLeafletSelector,
#templateLeafletSelector .selector-item,
#templateLeafletSelector .selector-item span {
  min-width: 0;
  max-width: 100%;
}

.linked-leaflets {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  min-height: 48px;
  overflow: hidden;
}

.linked-leaflet-item {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.linked-leaflet-item.is-dragging {
  opacity: 0.7;
}

.linked-leaflet-item:last-child {
  border-bottom: none;
}

.drag-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1;
  user-select: none;
}

.linked-leaflet-text {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.35;
  font-size: 0.92rem;
}

.linked-leaflet-controls {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-self: end;
}

.reorder-linked-btn,
.remove-linked-btn {
  width: 28px;
  min-width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 999px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.reorder-linked-btn {
  font-size: 0.86rem;
}

.reorder-linked-btn:hover:not(:disabled),
.reorder-linked-btn:focus-visible:not(:disabled) {
  border-color: var(--border);
  background: var(--surface-alt);
  color: var(--text);
}

.reorder-linked-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.remove-linked-btn {
  font-size: 1.2rem;
  font-weight: 500;
}

.remove-linked-btn:hover,
.remove-linked-btn:focus-visible {
  border-color: rgba(220, 38, 38, 0.25);
  background: var(--danger-soft);
  color: var(--danger);
}


@media (pointer: coarse) {
  .reorder-linked-btn {
    display: inline-flex;
  }
}

.checkbox-row {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 12px;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
}

@media (max-width: 1100px) {
  .panel-layout {
    grid-template-columns: 300px minmax(0, 1fr);
  }
}

@media (max-width: 980px) {
  body {
    padding: 10px;
  }

  .container {
    border-radius: 16px;
  }

  .panel-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .left-column {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .right-column {
    padding: 18px;
  }
}

@media (max-width: 640px) {
  body {
    padding: 8px;
  }

  .page-header {
    padding: 16px;
    align-items: stretch;
  }

  h1 {
    font-size: 1.25rem;
  }

  .tabs {
    width: 100%;
    justify-content: stretch;
  }

  .tab-btn {
    flex: 1 1 0;
    text-align: center;
    padding: 10px 12px;
  }

  .left-column,
  .right-column {
    padding: 14px;
  }

  .inline-actions,
  .button-container {
    gap: 8px;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .settings-group {
    width: 100%;
    display: flex;
    justify-content: flex-end;
  }

  .inline-actions > button,
  .button-container > button {
    width: 100%;
  }

  .settings-menu {
    left: 0;
    right: 0;
    min-width: 0;
    width: 100%;
  }

  .selector-item {
    grid-template-columns: 16px minmax(0, 1fr);
    gap: 8px;
    padding: 8px 6px;
  }

  .selector-item input[type="checkbox"] {
    width: 14px;
    height: 14px;
    margin-top: 3px;
  }

  .selector-item span {
    font-size: 0.9rem;
  }

  .linked-leaflet-item {
    grid-template-columns: 18px minmax(0, 1fr) auto;
    gap: 8px;
    padding: 8px 10px;
  }

  .linked-leaflet-controls {
    gap: 3px;
  }

  .reorder-linked-btn,
  .remove-linked-btn {
    width: 32px;
    min-width: 32px;
    height: 32px;
  }
}
