:root {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --surface-2: #f0ebe3;
  --text: #24211d;
  --muted: #7a7266;
  --border: #e3dccf;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --danger: #b3412f;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 2px 8px rgb(0 0 0 / 0.04);
  --chip-l: 92%;
  --chip-text-l: 28%;
  --chip-s: 45%;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #211f1c;
    --surface-2: #2a2824;
    --text: #ece7df;
    --muted: #9c9488;
    --border: #36332e;
    --accent: #4fb39a;
    --accent-text: #0f1a17;
    --danger: #e0715f;
    --shadow: none;
    --chip-l: 24%;
    --chip-text-l: 82%;
    --chip-s: 30%;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
h1, h2 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.75rem; }
.muted { color: var(--muted); }

main { max-width: 1440px; margin: 0 auto; padding: 24px 16px 64px; }

/* Header */
.site-header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.site-nav { display: flex; gap: 4px; flex: 1; }
.site-nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); }
.site-nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); font-weight: 600; }

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.button:hover { background: var(--surface-2); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button.primary:hover { filter: brightness(1.08); }
.button.danger { color: var(--danger); }
.button.ghost { border-color: transparent; background: transparent; }

.page-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.page-head p { margin: 0; }

.flash {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
}

/* Chips — colored per tag kind */
.chip {
  --h: 30;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 0.85rem;
  text-decoration: none;
  background: hsl(var(--h) var(--chip-s) var(--chip-l));
  color: hsl(var(--h) 50% var(--chip-text-l));
}
.chip[data-kind="person"] { --h: 210; }
.chip[data-kind="location"] { --h: 150; }
.chip[data-kind="type"] { --h: 30; }
.chip[data-kind="tag"] { --h: 280; }
a.chip:hover { filter: brightness(0.96); }
.chip.removable:not([data-kind]) { --h: 0; --chip-s: 0%; }

.tag-list { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; padding: 0; margin: 0; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; margin-bottom: 12px; }
.search {
  flex: 1 1 240px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
  font: inherit;
}
.filter-menu { position: relative; }
.filter-menu summary {
  list-style: none;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  user-select: none;
}
.filter-menu summary::-webkit-details-marker { display: none; }
.filter-menu summary::after { content: " ▾"; color: var(--muted); }
.filter-menu[open] summary { border-color: var(--accent); }
.filter-menu .count {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.75rem;
  text-align: center;
}
.filter-options {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 5;
  min-width: 200px;
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.12);
}
.filter-options label { display: flex; gap: 8px; align-items: center; padding: 4px 8px; border-radius: 6px; cursor: pointer; }
.filter-options label:hover { background: var(--surface-2); }
.filter-options p { margin: 4px 8px; }

.active-filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 16px; }
.active-filters .clear { font-size: 0.85rem; margin-left: 4px; }

/* Calendar */
.calendar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.cal-row { display: grid; grid-template-columns: 56px repeat(12, minmax(0, 1fr)); }
.cal-row + .cal-row { border-top: 1px solid var(--border); }
.cal-header div {
  padding: 8px 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--surface-2);
}
.cal-year { padding: 10px 8px; font-size: 1rem; font-weight: 700; background: var(--surface-2); }
.cal-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 64px;
  padding: 6px;
  border-left: 1px solid var(--border);
}
.cal-month { display: none; }
.trip-chip {
  display: block;
  padding: 3px 7px;
  border-radius: 6px;
  font-size: 0.8rem;
  line-height: 1.3;
  text-decoration: none;
  color: var(--text);
  background: var(--surface-2);
  border-left: 3px solid var(--muted);
  overflow-wrap: break-word;
  hyphens: auto;
}
.trip-chip.typed {
  background: hsl(var(--hue) var(--chip-s) var(--chip-l));
  border-left-color: hsl(var(--hue) 55% 45%);
  color: hsl(var(--hue) 50% var(--chip-text-l));
}
.trip-chip:hover { filter: brightness(0.95); }

@media (max-width: 1100px) {
  .cal-row { display: block; }
  .cal-row.cal-header { display: none; }
  .cal-year { padding: 10px 12px; }
  .cal-cell { border-left: 0; min-height: 0; padding: 8px 12px; }
  .cal-cell.empty { display: none; }
  .cal-cell + .cal-cell:not(.empty) { border-top: 1px solid var(--border); }
  .cal-month { display: block; font-size: 0.75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; }
}

/* Trip cards */
.trip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; align-items: start; }
.trip-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.trip-card-body { padding: 12px 14px 14px; display: grid; gap: 6px; }
.trip-card h2 { font-size: 1.05rem; }
.trip-card h2 a { color: inherit; text-decoration: none; }
.trip-card h2 a:hover { text-decoration: underline; }
.date { margin: 0; font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

/* Trip detail */
.trip-detail { max-width: 860px; display: grid; gap: 16px; }
.trip-detail h1 { font-size: 2rem; margin-top: -8px; }
.trip-facts { display: grid; gap: 8px; margin: 0; }
.trip-facts > div { display: grid; grid-template-columns: 110px 1fr; gap: 8px; align-items: baseline; }
.trip-facts dt { color: var(--muted); font-size: 0.85rem; }
.trip-facts dd { margin: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.notes { white-space: pre-line; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.actions { display: flex; gap: 8px; align-items: center; }
.actions form { margin: 0; }

/* Form */
.trip-form {
  max-width: 640px;
  display: grid;
  gap: 16px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.field { display: grid; gap: 6px; }
.field > label { font-weight: 600; font-size: 0.9rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field input:not([type="file"]):not([type="checkbox"]), .field select, .field textarea, .tag-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: inherit;
  font: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus, .tag-input:focus-within {
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-color: var(--accent);
}
.tag-input { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 5px 6px; cursor: text; }
.tag-input .chip { padding-right: 4px; }
.tag-input .chip button {
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 999px;
}
.tag-input .chip button:hover { background: rgb(0 0 0 / 0.1); }
.field .tag-input input.tag-entry {
  flex: 1 1 120px;
  border: 0;
  padding: 3px 4px;
  background: transparent;
  outline: none;
}
.hint { margin: -8px 0 0; font-size: 0.85rem; color: var(--muted); }
.errors {
  max-width: 640px;
  margin: 0 0 16px;
  padding: 10px 14px 10px 32px;
  border-radius: var(--radius);
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--border));
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 64px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-state p { margin: 0; font-size: 1.05rem; }

@media (max-width: 600px) {
  .site-header { padding: 10px 16px; gap: 12px; flex-wrap: wrap; }
  .site-nav { order: 3; flex-basis: 100%; }
  .header-actions { margin-left: auto; }
  .field-row { grid-template-columns: 1fr; }
  .trip-form { padding: 16px; }
  .trip-facts > div { grid-template-columns: 1fr; gap: 2px; }
}

/* Quick edit on trip cards */
.button.small { padding: 4px 10px; font-size: 0.85rem; }
.quick-edit { margin-top: 4px; }
.quick-edit summary {
  display: inline-block;
  list-style: none;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.quick-edit summary::-webkit-details-marker { display: none; }
.quick-edit summary::before { content: "✎ "; }
.quick-edit summary:hover { color: var(--accent); }
.quick-edit[open] summary { color: var(--accent); }
.quick-edit-form {
  display: grid;
  gap: 10px;
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.quick-edit-form .field > label { font-size: 0.8rem; }
.trip-card { transition: box-shadow 0.3s, border-color 0.3s; }
.trip-card.just-saved {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

/* Auth */
.header-actions { display: flex; align-items: center; gap: 8px; }
.header-actions form { margin: 0; }
.role-badge {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--surface-2);
}
.login-form {
  max-width: 360px;
  margin: 64px auto 0;
  display: grid;
  gap: 16px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-form .errors { margin: 0; padding-left: 14px; }
