:root {
  --bg: #f7f2ea;
  --card: #fffdfa;
  --ink: #2c2016;
  --muted: #7a6c5c;
  --accent: #a8451e;
  --accent-dark: #7e3115;
  --border: #e6dbc9;
  --gray-bg: #e7e2d8;
  --gray-text: #8c8474;
  --radius: 10px;
  --fab-size: 56px;
  --row-h: 46px;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body.scroll-locked {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
}

input, textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

body {
  padding-bottom: 24px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}

.topbar-title {
  margin: 0;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
  font-family: "Playfair Display", Georgia, "Times New Roman", serif;
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--accent-dark);
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 10px 12px 100px;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.empty-hint {
  color: var(--muted);
  text-align: center;
  padding: 20px 8px;
  font-size: 0.92rem;
}

/* Service rows */
.service-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--row-h);
  padding: 0 10px 0 6px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(44, 32, 22, 0.04);
  cursor: pointer;
}

.service-row:active { background: #f5efe4; }

.service-row.armed, .service-row.dragging {
  box-shadow: 0 4px 12px rgba(44, 32, 22, 0.18);
}

.service-row.dragging {
  position: relative;
  z-index: 30;
  background: #fffef9;
  box-shadow: 0 10px 24px rgba(44, 32, 22, 0.22);
}

.service-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-bg);
  font-size: 1.05rem;
  line-height: 1;
}

.service-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.service-icon.default-icon {
  color: var(--muted);
}

.service-icon.default-icon svg {
  width: 16px;
  height: 16px;
}

.service-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 0.94rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.service-ideas-badge {
  flex-shrink: 0;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--gray-bg);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.service-open-btn {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.service-open-btn svg {
  width: 15px;
  height: 15px;
}

.service-open-btn:active { color: var(--accent); }

.service-open-btn.no-url { opacity: 0.35; }

.drag-handle {
  touch-action: none;
  width: 20px;
  height: var(--row-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: grab;
  margin-left: -2px;
  margin-right: -2px;
}

.drag-handle svg {
  width: 15px;
  height: 15px;
}

.service-row.dragging .drag-handle {
  color: var(--accent);
}

/* Floating add button (FAB) */
.fab {
  position: fixed;
  right: max(18px, calc(50% - 320px + 18px));
  bottom: calc(22px + env(safe-area-inset-bottom));
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fdf7ee;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(126, 49, 21, 0.35);
  z-index: 15;
  cursor: pointer;
}

.fab:active { background: var(--accent-dark); }

.fab svg {
  width: 26px;
  height: 26px;
}

/* Sheet (bottom modal) */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 8, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 20;
}

.sheet-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 10px 18px 24px;
  transform: translateY(110%);
  transition: transform 0.25s ease;
  z-index: 21;
  max-width: 640px;
  margin: 0 auto;
  max-height: 85vh;
  overflow-y: auto;
}

.sheet.show {
  transform: translateY(0);
}

.sheet-close-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--gray-bg);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}

.sheet-close-btn svg {
  width: 15px;
  height: 15px;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 6px auto 14px;
  touch-action: none;
}

.sheet h2 {
  margin: 0 0 14px;
  font-size: 1.1rem;
  font-family: "Playfair Display", Georgia, serif;
  touch-action: none;
}

.sheet label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  margin: 12px 0 6px;
  touch-action: none;
}

.sheet input[type="text"] {
  width: 100%;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  font-size: 1rem;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.sheet-actions-3 { justify-content: space-between; }

.sheet-actions button {
  flex: 1;
  padding: 12px;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  font-size: 0.95rem;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: #fdf7ee;
}

.btn-secondary {
  background: var(--gray-bg);
  color: var(--ink);
}

.btn-compact {
  flex: 0 0 auto !important;
  padding: 10px 12px !important;
}

.btn-danger {
  background: #f3ded8;
  color: #8a2f14;
}

.sheet-actions-slim button {
  padding: 8px;
  font-size: 0.88rem;
}

/* The service sheet is a fixed-height flex column so the ideas list scrolls
   internally while the composer (toolbar + input) always stays pinned to the
   bottom of the sheet, regardless of how many ideas there are. */
#service-sheet {
  display: flex;
  flex-direction: column;
  height: 80vh;
  overflow: hidden;
}

#service-sheet .service-sheet-header,
#service-sheet .service-edit-panel {
  flex-shrink: 0;
}

/* Service sheet header (collapsible edit toggle) */
.service-sheet-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 34px 4px 2px;
  cursor: pointer;
}

.service-sheet-icon {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-bg);
  font-size: 1.3rem;
  color: var(--muted);
}

.service-sheet-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.service-sheet-name {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  font-size: 1.05rem;
  font-family: "Playfair Display", Georgia, serif;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.service-sheet-chevron {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: var(--muted);
  transition: transform 0.2s ease;
}

.service-sheet-header.expanded .service-sheet-chevron {
  transform: rotate(90deg);
}

.service-edit-panel {
  padding-top: 4px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 10px;
}

.icon-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-picker-preview {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 9px;
  border: 1.5px solid var(--border);
  background: var(--gray-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: var(--muted);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
}

.icon-picker-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin-top: 10px;
  max-height: 160px;
  overflow-y: auto;
}

.emoji-option {
  border: none;
  background: var(--gray-bg);
  border-radius: 7px;
  font-size: 1.15rem;
  padding: 6px 0;
  cursor: pointer;
}

.emoji-option.selected {
  background: var(--accent);
}

/* Ideas section - a scrollable list with a composer pinned to the bottom */
.ideas-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.ideas-list-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 6px;
}

.ideas-bottom-bar {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.ideas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 2px 2px 8px;
}

.ideas-count {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}

.ideas-toolbar-btn {
  border: none;
  background: none;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 4px;
  cursor: pointer;
}

.ideas-toolbar-btn-danger {
  color: #b3301a;
}

.ideas-toolbar-btn-copy {
  color: #2f8f3d;
}

.ideas-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ideas-add-row input[type="text"] {
  flex: 1;
}

.idea-add-btn {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  border: none;
  background: #509159;
  color: #fdf7ee;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.idea-add-btn:active { background: #3f7a48; }

.idea-add-btn svg {
  width: 20px;
  height: 20px;
}

.ideas-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.idea-row {
  display: flex;
  flex-direction: column;
  padding: 6px 12px 10px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.idea-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -4px 2px;
}

.idea-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.idea-save-btn {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: #509159;
  color: #fdf7ee;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.idea-save-btn svg {
  width: 12px;
  height: 12px;
}

.idea-label-btn {
  border: none;
  background: none;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px;
  cursor: pointer;
}

.idea-delete-label {
  color: #b3301a;
}

.idea-copy-label {
  color: #2f8f3d;
}

.idea-text {
  min-width: 0;
  font-size: 0.9rem;
  line-height: 1.35;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  padding-top: 1px;
  cursor: text;
}

.idea-text:focus {
  outline: none;
}

/* Delete confirmation dialog - a small centered card above everything else,
   including an already-open sheet, so any destructive action asks first. */
.confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 8, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 40;
}

.confirm-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.confirm-dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  width: min(320px, calc(100vw - 48px));
  background: var(--card);
  border-radius: 14px;
  padding: 20px 18px 16px;
  box-shadow: 0 12px 32px rgba(44, 32, 22, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 41;
}

.confirm-dialog.show {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.confirm-text {
  font-size: 0.96rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 16px;
  text-align: center;
}

.btn-danger-solid {
  background: #b3301a;
  color: #fdf7ee;
}

.btn-danger-solid:active { background: #8f2513; }
