/* Mobile-first. Single column; the layout never splits — wider screens just
   get more breathing room. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --border-strong: #c9cdd3;
  --text: #1c2128;
  --muted: #626c77;
  --error: #c4302f;
  --error-bg: #fcf1f1;
  --ok: #1a7f37;
  --accent: #3556c8;
  --accent-hover: #2a46a8;
  --accent-soft: #eef1fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 33, 40, 0.06), 0 4px 12px rgba(28, 33, 40, 0.04);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0 auto;
  max-width: 42rem;
  padding: 1rem 1rem 6.5rem; /* room for the sticky action bar */
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* --- header ------------------------------------------------------------- */

header {
  margin: 0.5rem 0 1rem;
}

header h1 {
  font-size: 1.35rem;
  letter-spacing: -0.01em;
  margin: 0;
}

#repo-banner {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.15rem 0 0;
}

/* --- warnings ------------------------------------------------------------ */

#warnings {
  background: #fff8e1;
  border: 1px solid #e6c65c;
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

#warnings p {
  margin: 0.2rem 0;
}

/* --- repo picker ---------------------------------------------------------- */

#repo-picker {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

#repo-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

@media (min-width: 30rem) {
  #repo-form {
    flex-direction: row;
  }

  #repo-form input {
    flex: 1;
  }
}

/* --- mode / profile bar ------------------------------------------------- */

#mode {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.mode-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.mode-toggle label {
  position: relative;
}

.mode-toggle input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.mode-toggle span {
  display: inline-block;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  font-size: 0.9rem;
  color: var(--muted);
}

.mode-toggle input:checked + span {
  background: var(--accent);
  color: #fff;
}

.mode-toggle input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.profile-switch {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.profile-switch select {
  min-height: 2.1rem;
  padding: 0.25rem 1.9rem 0.25rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background-color: var(--surface);
  background-position: right 0.6rem center;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.profile-switch select:hover {
  border-color: var(--accent);
}

.profile-switch select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* --- event combobox ----------------------------------------------------- */

.combo {
  position: relative;
  flex: 1;
  min-width: 12rem;
}

.combo input {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font: inherit;
  background: var(--surface);
  transition: border-color 0.12s, box-shadow 0.12s;
}

.combo input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.combo input:disabled {
  background: var(--bg);
  color: var(--muted);
}

.combo ul {
  position: absolute;
  z-index: 600;
  left: 0;
  right: 0;
  margin: 0.25rem 0 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 16rem;
  overflow-y: auto;
}

.combo ul button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  min-height: 0;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 400;
  cursor: pointer;
}

.combo ul button:hover {
  background: var(--accent-soft);
}

/* --- form sections ---------------------------------------------------------- */

#event-form details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.25rem 1rem;
  margin-bottom: 0.9rem;
}

#event-form summary {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 0.7rem 0;
  list-style: none; /* the native marker misaligns; we draw our own */
  user-select: none;
}

#event-form summary::-webkit-details-marker {
  display: none;
}

#event-form summary::before {
  content: "";
  flex: none;
  width: 0.42rem;
  height: 0.42rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); /* ▸ closed */
  transition: transform 0.15s;
}

#event-form details[open] summary::before {
  transform: rotate(45deg); /* ▾ open */
}

#event-form details[open] summary {
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.35rem;
}

/* --- fields ---------------------------------------------------------------- */

.field {
  margin: 0.85rem 0;
}

.field label {
  display: block;
  font-weight: 500;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

.field .req {
  color: var(--error);
}

.field input[type="text"],
.field input[type="url"],
.field input[type="date"],
.field input[type="time"],
.field textarea,
.field select {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font: inherit;
  background: var(--surface);
  color: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}

/* Custom caret, vertically centered — the native one drifts with our
   padding/min-height. Shared by every select in the app. */
select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="8" viewBox="0 0 12 8"><path d="M1 1.5 6 6.5 11 1.5" fill="none" stroke="%23626c77" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>');
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  padding-right: 2.1rem;
}

.field input:focus-visible,
.field textarea:focus-visible,
.field select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
}

.field .note {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0.25rem 0 0;
}

.field-error {
  color: var(--error);
  font-size: 0.82rem;
  margin: 0.25rem 0 0;
}

.field-error:not(:empty) {
  background: var(--error-bg);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
}

.field.pair {
  display: flex;
  gap: 0.6rem;
  margin: 0;
}

.field.pair > div {
  flex: 1;
}

.field.pair label {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--muted);
}

.info {
  cursor: help;
  color: var(--accent);
  font-weight: 400;
}

/* --- languages chips ------------------------------------------------------- */

.chips {
  position: relative;
}

.chips-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  min-height: 2.5rem;
  padding: 0.3rem 0.45rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
}

.chips-list:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.15rem 0.3rem 0.15rem 0.6rem;
  font-size: 0.82rem;
  font-weight: 500;
}

.chip-remove {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 1rem;
  line-height: 1;
  padding: 0.1rem 0.3rem;
  border-radius: 999px;
  cursor: pointer;
}

.chip-remove:hover {
  background: rgba(53, 86, 200, 0.15);
}

.chips-input {
  flex: 1;
  min-width: 8rem;
  border: none !important;
  box-shadow: none !important;
  min-height: 1.8rem !important;
  padding: 0.1rem !important;
}

.chips-input:focus-visible {
  outline: none;
}

.chips-suggest {
  position: absolute;
  z-index: 500;
  left: 0;
  right: 0;
  margin: 0.25rem 0 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 14rem;
  overflow-y: auto;
}

.chips-suggest button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}

.chips-suggest button:hover {
  background: var(--accent-soft);
}

/* --- combobox (timezone) ---------------------------------------------------- */

.combo-field {
  position: relative;
}

.combo-suggest {
  position: absolute;
  z-index: 500;
  left: 0;
  right: 0;
  margin: 0.25rem 0 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 14rem;
  overflow-y: auto;
}

.combo-suggest button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  min-height: 0;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 400;
  cursor: pointer;
}

.combo-suggest button:hover {
  background: var(--accent-soft);
}

/* --- Leaflet location picker ------------------------------------------------ */

.geo-search {
  display: flex;
  gap: 0.5rem;
  margin: 0.4rem 0;
}

.geo-search input {
  flex: 1;
}

.geo-results {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.geo-results li {
  padding: 0;
}

.geo-results button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}

.geo-results button:hover {
  background: var(--accent-soft);
}

.geo-map {
  height: 14rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 0.25rem;
}

@media (min-width: 40rem) {
  .geo-map {
    height: 17rem;
  }
}

.geo-pin {
  width: 18px;
  height: 18px;
  border-radius: 50% 50% 50% 0;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  transform: rotate(-45deg);
  cursor: grab;
}

/* geo: hint sits between the map and the coordinate inputs */
[data-field-id="geo"] .note {
  margin: 0.35rem 0;
}

/* Venue and its map are one block: the geo field nests under the venue
   input (ui/form.ts renders it inside), visually a continuation. */
[data-field-id="venue"] [data-field-id="geo"] {
  margin: 0.6rem 0 0.25rem;
}

[data-field-id="venue"] [data-field-id="geo"] > label {
  font-weight: 400;
  font-size: 0.82rem;
  color: var(--muted);
}

/* --- document errors ---------------------------------------------------------- */

#document-errors {
  color: var(--error);
  background: var(--error-bg);
  border: 1px solid #eccfcf;
  border-radius: var(--radius);
  font-size: 0.88rem;
  margin: 0 0 1rem;
  padding: 0.6rem 0.85rem 0.6rem 2rem;
}

/* --- action bar ------------------------------------------------------------- */

#action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem max(1rem, env(safe-area-inset-right)) max(0.75rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}

#action-bar > * {
  flex: 0 0 auto;
}

#valid-badge {
  margin-right: auto;
  font-size: 0.85rem;
  font-weight: 600;
}

#valid-badge.ok {
  color: var(--ok);
}

#valid-badge.invalid {
  color: var(--muted);
}

@media (min-width: 46rem) {
  #action-bar {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 42rem;
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
  }
}

/* --- buttons -------------------------------------------------------------- */

button {
  font: inherit;
  font-weight: 500;
  min-height: 2.5rem;
  padding: 0.45rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-hover);
}

button.secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

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

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- review dialog ------------------------------------------------------------ */

#review {
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(28, 33, 40, 0.25);
  padding: 1.25rem;
  width: min(34rem, calc(100vw - 2rem));
}

#review::backdrop {
  background: rgba(28, 33, 40, 0.45);
}

#review h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

#review-json {
  background: #22272e;
  color: #adbac7;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  line-height: 1.55;
  max-height: 50vh;
  margin: 0 0 0.5rem;
}

/* JSON syntax highlight (tokens from lib/highlight.ts) */
.j-key {
  color: #6cb6ff;
}

.j-string {
  color: #96d0a0;
}

.j-number {
  color: #daaa7d;
}

.j-literal {
  color: #dcbdfb;
}

#review .actions {
  justify-content: flex-end;
}

/* --- "new event" source toolbar -------------------------------------------------- */

#new-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: -0.25rem 0 1rem;
}

/* --- detected-events list (shared by both import dialogs) ------------------------ */

#jsonld-warnings {
  background: #fff8e1;
  border: 1px solid #e6c65c;
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}

#jsonld-warnings p {
  margin: 0.2rem 0;
}

#jsonld-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 14rem;
  overflow-y: auto;
}

#jsonld-list label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}

#jsonld-list label:hover {
  background: var(--accent-soft);
}

#jsonld-list input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
}

#jsonld-dialog .actions {
  justify-content: flex-end;
}

#jsonld-fallback .actions {
  justify-content: flex-start;
}

/* --- feedback footer -------------------------------------------------------------- */

footer {
  margin-top: 2rem;
  text-align: center;
}

#feedback-link {
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: none;
}

#feedback-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* --- ICS import ----------------------------------------------------------------- */

#import-dialog,
#jsonld-dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(28, 33, 40, 0.25);
  padding: 1.25rem;
  width: min(34rem, calc(100vw - 2rem));
}

#import-dialog::backdrop,
#jsonld-dialog::backdrop {
  background: rgba(28, 33, 40, 0.45);
}

#import-dialog h2,
#jsonld-dialog h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.import-sources {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin: 0.75rem 0;
}

#import-url-form {
  display: flex;
  gap: 0.5rem;
}

#import-url-form input,
#jsonld-url-form input {
  flex: 1;
  min-height: 2.5rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font: inherit;
}

#jsonld-url-form {
  display: flex;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

#jsonld-fallback {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.85rem;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}

#jsonld-fallback p {
  margin: 0 0 0.5rem;
}

#jsonld-fallback textarea {
  width: 100%;
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 0.5rem;
}

#import-warnings {
  background: #fff8e1;
  border: 1px solid #e6c65c;
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}

#import-warnings p {
  margin: 0.2rem 0;
}

#import-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 14rem;
  overflow-y: auto;
}

#import-list label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
}

#import-list label:hover {
  background: var(--accent-soft);
}

#import-list input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
}

.import-past {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
}

#import-dialog .actions {
  justify-content: flex-end;
}

#import-banner {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

#import-banner p {
  margin: 0;
  font-weight: 500;
}

#import-banner ul {
  margin: 0.4rem 0 0;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.84rem;
}

#import-banner .actions {
  flex-wrap: wrap;
}

#import-submitted {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  margin-top: 0.6rem;
}

#import-submitted p {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.85rem;
}

#import-check-result:not(:empty) {
  font-size: 0.84rem;
}

/* Fields the imported ICS did not carry (markImportGaps in ui/form.ts). */
.field.import-gap input,
.field.import-gap textarea,
.field.import-gap select,
.field.import-gap .chips-list {
  border-color: #e6c65c;
  background: #fffdf4;
}

.import-gap-tag {
  color: #8a6d1a;
  font-size: 0.82rem;
  margin: 0.25rem 0 0;
}

.import-gap-tag::before {
  content: "⚠ ";
}

/* --- shared bits --------------------------------------------------------------- */

.actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin: 0.75rem 0 0;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
}

#fallback {
  background: #fff8e1;
  border: 1px solid #e6c65c;
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1rem;
}

#fallback h3 {
  margin-top: 0;
}

#fallback textarea {
  width: 100%;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 0.5rem;
}
