:root {
  /* Lets the browser render native widgets (the date picker, scrollbars,
     etc.) in the matching theme instead of forcing them light. */
  color-scheme: light dark;

  --paper: #f0e6d3;
  --surface: #fffcf5;
  --ink: #2a1e15;
  --ink-muted: #5c4c3a;
  --line: #d9c7a3;
  --accent: #a8442c;
  --accent-ink: #fff8f0;
  --status-open: #b5791e;
  --status-open-bg: #f0dcb2;
  --status-open-ink: #5c3b0e;
  --status-done-bg: #d9e3cc;
  --status-done-ink: #33402a;
  --error-ink: #55300c;
  --input-bg: #fff;
  --backdrop: rgba(42, 30, 21, 0.5);
  --shadow: rgba(42, 30, 21, 0.12);
}

/* Auto (no data-theme attribute) follows the OS/browser preference; the
   theme toggle in app.js can pin it to light/dark instead by setting
   data-theme, which these two selectors take priority over. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #17110c;
    --surface: #2f251d;
    --ink: #f8f0e4;
    --ink-muted: #c7b79f;
    --line: #5c4b37;
    --accent: #e8875f;
    --accent-ink: #201007;
    --status-open: #e8ad4c;
    --status-open-bg: #513a17;
    --status-open-ink: #f6d087;
    --status-done-bg: #303f28;
    --status-done-ink: #c7deb5;
    --error-ink: #f8e0b3;
    --input-bg: #201810;
    --backdrop: rgba(0, 0, 0, 0.65);
    --shadow: rgba(0, 0, 0, 0.45);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #17110c;
  --surface: #2f251d;
  --ink: #f8f0e4;
  --ink-muted: #c7b79f;
  --line: #5c4b37;
  --accent: #e8875f;
  --accent-ink: #201007;
  --status-open: #e8ad4c;
  --status-open-bg: #513a17;
  --status-open-ink: #f6d087;
  --status-done-bg: #303f28;
  --status-done-ink: #c7deb5;
  --error-ink: #f8e0b3;
  --input-bg: #201810;
  --backdrop: rgba(0, 0, 0, 0.65);
  --shadow: rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

/* An element's own `display` rule (e.g. .icon-button's inline-flex) has the
   same specificity as the UA stylesheet's `[hidden]{display:none}` and,
   being an author rule, wins — so hidden buttons stayed visible. */
[hidden] {
  display: none !important;
}

body {
  font-family: "Karla", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  margin: 0;
  padding: 1.5rem 1rem 3rem;
}

main {
  max-width: 820px;
  margin: 0 auto;
}

.page-header {
  max-width: 820px;
  margin: 0 auto 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.theme-toggle {
  border-radius: 0.4rem;
}

.add-button {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: none;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
}

.intro {
  color: var(--ink-muted);
  max-width: 40ch;
}

a {
  color: var(--accent);
}

.button {
  display: inline-block;
  padding: 0.6rem 1.1rem;
  border-radius: 0.4rem;
  border: none;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}

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

.button-quiet {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.button-quiet:hover {
  border-color: var(--ink-muted);
}

.logout-link {
  display: inline-block;
  margin-top: 1.25rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.greeting {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  color: var(--ink-muted);
}

.error {
  background: var(--status-open-bg);
  color: var(--error-ink);
  border: 1px solid var(--status-open);
  border-radius: 0.4rem;
  padding: 0.75rem 1rem;
  margin: 0 0 1rem;
}

.list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.list-header,
.row {
  /* The actions column is a fixed width, not auto: auto-sizing is computed
     independently per grid box, and the header's empty actions cell would
     collapse to ~0 while a row's icon buttons need ~8rem, silently pulling
     every column out of alignment between the header and the rows. */
  display: grid;
  grid-template-columns: minmax(10rem, 1fr) 5.5rem 8rem;
  grid-template-areas: "anliegen status actions";
  gap: 0.25rem 0.75rem;
  align-items: center;
  padding: 0.85rem 1rem;
}

.list-header {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-muted);
  border-bottom: 1px solid var(--line);
}

.row {
  border-bottom: 1px solid var(--line);
}

.row:last-child {
  border-bottom: none;
}

.done-section {
  border-top: 1px solid var(--line);
}

.done-section summary {
  cursor: pointer;
  padding: 0.6rem 1rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink-muted);
  background: var(--paper);
}

.done-section summary:hover {
  color: var(--ink);
}

.cell-anliegen { grid-area: anliegen; min-width: 0; }
.cell-status { grid-area: status; }
.cell-actions {
  grid-area: actions;
  display: flex;
  justify-content: flex-end;
}

.cell-anliegen {
  overflow-wrap: break-word;
}

.anliegen-text {
  line-height: 1.35;
}

.cell-meta {
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin-top: 0.2rem;
}

.button-group {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  overflow: hidden;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--ink-muted);
}

.button-group .icon-button {
  border-right: 1px solid var(--line);
}

.button-group .icon-button:last-child {
  border-right: none;
}

.icon-button:hover {
  background: var(--paper);
  color: var(--ink);
}

.icon-button-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.icon-button-primary:hover {
  background: var(--accent);
  color: var(--accent-ink);
  filter: brightness(1.08);
}

.status-pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 1rem;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
}

.status-pill.status-offen {
  background: var(--status-open-bg);
  color: var(--status-open-ink);
}

.status-pill.status-erledigt {
  background: var(--status-done-bg);
  color: var(--status-done-ink);
}

.row.status-erledigt .anliegen-text {
  color: var(--ink-muted);
}

button {
  cursor: pointer;
}

.anliegen-dialog {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  width: min(30rem, calc(100vw - 2rem));
}

.anliegen-dialog::backdrop {
  background: var(--backdrop);
}

.anliegen-form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1.25rem;
}

.anliegen-form h2 {
  margin: 0;
  font-size: 1.15rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.field input,
.field textarea {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--input-bg);
  color: var(--ink);
}

.field textarea {
  resize: vertical;
  min-height: 6rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

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

@media (max-width: 640px) {
  .list {
    background: transparent;
    border: none;
    overflow: visible;
  }

  .list-header {
    display: none;
  }

  .row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "anliegen anliegen"
      "status actions";
    gap: 0.5rem 0.75rem;
    padding: 0.9rem 1rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 0.4rem;
    margin-bottom: 0.6rem;
    box-shadow: 0 1px 3px var(--shadow);
  }

  .row:last-child {
    margin-bottom: 0;
  }

  .done-section {
    border-top: none;
    margin-top: 0.2rem;
  }

  .done-section summary {
    background: transparent;
    padding: 0 0.25rem 0.6rem;
  }

  .anliegen-text {
    font-weight: 500;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
