/* Color modes. theme.js sets data-theme="light"|"dark" on <html> before the
   first paint. Without it (script blocked) the system setting applies. */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --bg-elevated: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --on-accent: #0f172a;
  --danger: #f87171;
  --on-danger: #0f172a;
  --success: #4ade80;
  --hover: rgb(255 255 255 / 0.05);
  --backdrop: rgb(0 0 0 / 0.6);
  --shadow: 0 10px 30px rgb(0 0 0 / 0.45);
  --banner-bg: #7c2d12;
  --banner-text: #fed7aa;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --border: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --accent: #0369a1;
  --on-accent: #ffffff;
  --danger: #b91c1c;
  --on-danger: #ffffff;
  --success: #15803d;
  --hover: rgb(15 23 42 / 0.06);
  --backdrop: rgb(15 23 42 / 0.4);
  --shadow: 0 10px 30px rgb(15 23 42 / 0.15);
  --banner-bg: #fed7aa;
  --banner-text: #7c2d12;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    color-scheme: light;
    --bg: #f8fafc;
    --bg-elevated: #ffffff;
    --border: #cbd5e1;
    --text: #0f172a;
    --text-muted: #475569;
    --accent: #0369a1;
    --on-accent: #ffffff;
    --danger: #b91c1c;
    --on-danger: #ffffff;
    --success: #15803d;
    --hover: rgb(15 23 42 / 0.06);
    --backdrop: rgb(15 23 42 / 0.4);
    --shadow: 0 10px 30px rgb(15 23 42 / 0.15);
    --banner-bg: #fed7aa;
    --banner-text: #7c2d12;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.view[hidden] { display: none !important; }

.offline-banner {
  background: var(--banner-bg);
  color: var(--banner-text);
  text-align: center;
  padding: 0.5rem;
  font-size: 0.875rem;
}

.reload-btn {
  margin-left: 0.5rem;
  font: inherit;
  font-weight: 600;
}

/* Login */
#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
  text-align: center;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  color: var(--text);
  font-size: 1rem;
}

button {
  cursor: pointer;
  font: inherit;
}

.login-card button[type="submit"] {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 8px;
  padding: 0.65rem;
  font-weight: 600;
}

.error {
  color: var(--danger);
  font-size: 0.875rem;
  margin: 0;
}

/* App layout */
#app-view {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 1rem;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}

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

.icon-btn {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 8px;
  width: 28px;
  height: 28px;
  font-size: 1.1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.list-group h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 0.5rem;
}

.list-nav {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-height: 4px;
}

.list-nav li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

.list-nav li .list-name { flex: 1; }

.list-nav li:hover { background: var(--hover); }
.list-nav li.active { background: var(--accent); color: var(--on-accent); font-weight: 600; }

.new-list-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: auto;
}

.new-list-form input[type="text"] {
  flex: 1;
  min-width: 0;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  width: 100%;
}

.new-list-form button {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
}

.sync-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0;
}

.link-btn.danger { color: var(--danger); }
.link-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.content {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
}

.empty-state {
  color: var(--text-muted);
  text-align: center;
  margin-top: 4rem;
}

.list-view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.list-view-actions {
  display: flex;
  gap: 1rem;
  flex-shrink: 0;
  white-space: nowrap;
}

/* Copy list and confirmation dialogs */
.copy-dialog,
.confirm-dialog {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  width: min(420px, calc(100vw - 2rem));
}

.copy-dialog::backdrop,
.confirm-dialog::backdrop { background: var(--backdrop); }

.copy-dialog form,
.confirm-dialog form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.copy-dialog h3,
.confirm-dialog h3 { margin: 0; }

.dialog-text {
  margin: 0;
  overflow-wrap: anywhere;
}

.copy-dialog label,
.confirm-dialog .dialog-fields label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.dialog-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

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

.dialog-actions button {
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-weight: 600;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
}

.btn-danger {
  background: var(--danger);
  color: var(--on-danger);
  border: none;
}

.btn-secondary {
  background: none;
  color: var(--text);
  border: 1px solid var(--border);
}

.dialog-actions button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.copy-dialog :focus-visible,
.confirm-dialog :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.list-view-header h2 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.75rem;
  line-height: 1;
  padding: 0 0.25rem;
  flex-shrink: 0;
}

.new-todo-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.new-todo-form input {
  flex: 1;
}

.new-todo-form button {
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 8px;
  padding: 0 1rem;
  font-weight: 600;
}

.todo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.todo-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}

.todo-item .todo-text { flex: 1; }

.todo-item.completed .todo-text {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* Tap on the text edits it inline. */
.todo-item .todo-text.editable {
  cursor: text;
  border-radius: 4px;
  overflow-wrap: anywhere;
}

.todo-item .todo-text.editable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.todo-edit-input {
  flex: 1;
  min-width: 0;
  font: inherit;
  /* At least 16px: iOS zooms into smaller inputs when they get focus. */
  font-size: max(16px, 1em);
  padding: 0.25rem 0.4rem;
  margin: -0.25rem 0;
}

.todo-item.editing { box-shadow: 0 0 0 2px var(--accent); }

.todo-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.completed-heading {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 1.5rem 0 0.5rem;
}

/* Lists with groups (public/group-ui.js): one section per group, "Ohne Gruppe"
   last. The flat lists are hidden then; .todo-list sets display, so [hidden]
   needs its own rule. */
.todo-list[hidden],
.todo-sections[hidden],
.todo-section-body[hidden] { display: none; }

.todo-sections {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.todo-section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.todo-section-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
  /* Large enough to tap. */
  min-height: 44px;
  padding: 0.25rem 0.5rem;
  margin: 0 -0.5rem;
  background: none;
  border: none;
  border-radius: 6px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.todo-section-toggle:hover { background: var(--hover); }

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

.todo-section.ungrouped .todo-section-header { min-height: 44px; }

.todo-section-chevron {
  flex-shrink: 0;
  width: 1em;
  color: var(--text-muted);
}

.todo-section-name {
  overflow-wrap: anywhere;
}

.todo-section-count {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
}

/* Todos of a group are indented under its header. */
.todo-section-body {
  padding-left: 0.75rem;
  border-left: 2px solid var(--border);
  margin-top: 0.25rem;
}

.todo-section-completed-heading {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0.75rem 0 0.5rem;
}

.todo-section-empty {
  margin: 0.25rem 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

@media (max-width: 720px) {
  .todo-section-body { padding-left: 0.5rem; }
}

/* Drop zones while a todo is dragged (UI-8.6). data-drag-kind on
   .todo-sections is set only during a drag (GroupUi.setDropZones), so none of
   this applies to the normal view; hidden is never changed. Only containers
   of the dragged kind; a collapsed group keeps its body hidden
   (.todo-section-body[hidden] is not overridden). The selectors beat
   .todo-list[hidden] (0,2,0). */
.todo-sections[data-drag-kind] > .todo-section.ungrouped[hidden] { display: block; }
.todo-sections[data-drag-kind] .todo-section-empty { display: none; }

.todo-sections[data-drag-kind="open"] .todo-list[data-kind="open"],
.todo-sections[data-drag-kind="completed"] .todo-list[data-kind="completed"] {
  display: flex;
  border-radius: 8px;
}

/* An empty container of the dragged kind: a large enough target. No margin
   of its own, so nothing shifts when the dragged row enters or leaves it. On
   touch the floating copy of the row is appended to <body>
   (ListSort.todoSortableOptions: fallbackOnBody), so a container left empty
   is :empty too. */
.todo-sections[data-drag-kind="open"] .todo-list[data-kind="open"]:empty,
.todo-sections[data-drag-kind="completed"] .todo-list[data-kind="completed"]:empty {
  min-height: 3rem;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
}

.todo-sections[data-drag-kind="open"] .todo-list[data-kind="open"]:empty::before,
.todo-sections[data-drag-kind="completed"] .todo-list[data-kind="completed"]:empty::before {
  content: attr(data-drop-label);
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* The container the dragged row is in now (SortableJS puts it only into
   containers that accept it: same kind, expanded group). Without :has()
   support there is just no highlight. */
.todo-sections[data-drag-kind="open"] .todo-list[data-kind="open"]:has(> .sortable-ghost),
.todo-sections[data-drag-kind="completed"] .todo-list[data-kind="completed"]:has(> .sortable-ghost) {
  background: var(--hover);
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

/* Managing groups (UI-5): "+ Gruppe hinzufügen" and the "⋯" menu of a group,
   next to (never inside) the collapse toggle. */
.add-group-btn {
  align-self: flex-start;
  margin-top: 1rem;
  min-height: 44px;
  padding: 0.5rem 0.9rem;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font: inherit;
  cursor: pointer;
}

.add-group-btn:hover { background: var(--hover); color: var(--text); }

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

.add-group-btn[hidden],
.group-menu-panel[hidden] { display: none; }

.group-menu {
  position: relative;
  flex-shrink: 0;
}

.group-menu-btn {
  min-width: 44px;
  min-height: 44px;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.group-menu-btn:hover,
.group-menu-btn[aria-expanded="true"] {
  background: var(--hover);
  border-color: var(--border);
  color: var(--text);
}

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

/* The panel uses the look of the list menu (.list-menu-panel). */
.group-menu-panel { font-weight: 400; }

/* "+ ToDo hinzufügen" inside a group (UI-6). */
.group-add-todo { margin-top: 0.5rem; }

.group-add-todo-btn {
  min-height: 44px;
  padding: 0.25rem 0.5rem;
  margin-left: -0.5rem;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.group-add-todo-btn:hover { background: var(--hover); color: var(--text); }

.group-add-todo-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.group-add-todo-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.group-add-todo-btn[hidden],
.group-add-todo-form[hidden] { display: none; }

.group-add-todo-input {
  flex: 1;
  min-width: 10rem;
  /* At least 16px: iOS zooms into smaller inputs when they get focus. */
  font-size: max(16px, 1em);
  min-height: 44px;
  padding: 0.4rem 0.6rem;
}

.group-add-todo-form button { min-height: 44px; }

.group-add-todo-form .error { flex-basis: 100%; margin: 0; }

/* "⋯" menu of a todo in a grouped list (UI-7); the panel uses the look of
   the list menu (.list-menu-panel). */
.todo-menu {
  position: relative;
  flex-shrink: 0;
  margin: -0.5rem -0.25rem -0.5rem 0;
}

.todo-menu-btn {
  min-width: 44px;
  min-height: 44px;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.todo-menu-btn:hover,
.todo-menu-btn[aria-expanded="true"] {
  background: var(--hover);
  border-color: var(--border);
  color: var(--text);
}

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

.todo-menu-view {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.todo-menu-view[hidden] { display: none; }

.todo-move-target {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  overflow-wrap: anywhere;
}

.todo-move-check {
  flex-shrink: 0;
  width: 1em;
  color: var(--accent);
}

.todo-move-target.current { font-weight: 600; }

.todo-section-hint {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: var(--danger);
}

.drag-handle {
  flex-shrink: 0;
  cursor: grab;
  color: var(--text-muted);
  touch-action: none;
  padding: 0 0.15rem;
  font-size: 1rem;
  line-height: 1;
  user-select: none;
}

.sortable-ghost {
  opacity: 0.4;
}

.sortable-chosen {
  box-shadow: 0 0 0 2px var(--accent);
}

/* Touch: lists are moved after a long press on the whole row (public/list-sort.js).
   No text selection or callout menu on the long press; vertical scrolling over
   the row (including the handle) stays possible. */
@media (pointer: coarse) {
  .list-nav li {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
  .list-nav .drag-handle { touch-action: auto; }
  .list-nav li.sortable-chosen { background: var(--hover); }
}

/* Touch: a todo handle is hit in a 44 × 44 px area (UI-8.6b), without
   changing the row: the symbol, the row height and the place of the checkbox
   stay. An invisible ::before, centered on the row (a flat row is about 45px
   high), ends at the checkbox (right: minus the .todo-item gap) and reaches a
   few px past the row's left edge. Open menus (z-index 20) stay above it. No
   callout menu on a long press. The handles of the list overview stay as
   they are (long press on the whole row). */
@media (pointer: coarse) {
  .todo-item > .drag-handle {
    position: relative;
    -webkit-touch-callout: none;
  }
  .todo-item > .drag-handle::before {
    content: '';
    position: absolute;
    top: calc(50% - 22px);
    right: -0.75rem;
    width: 44px;
    height: 44px;
  }
}

/* Password dialog */
.dialog-fields {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.dialog-fields[hidden] { display: none; }

.success {
  color: var(--success);
  font-size: 0.875rem;
  margin: 0;
}

/* User menu */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.user-menu {
  position: relative;
  min-width: 0;
}

.user-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 100%;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.3rem 0.5rem 0.3rem 0.35rem;
  color: var(--text);
  font-weight: 600;
}

.user-menu-btn:hover,
.user-menu-btn[aria-expanded="true"] {
  background: var(--hover);
  border-color: var(--border);
}

.user-icon { flex-shrink: 0; }

.user-menu-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-caret {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.user-menu-panel {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  z-index: 20;
  width: min(260px, calc(100vw - 2rem));
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-weight: 400;
}

.user-menu-panel[hidden] { display: none; }

.user-menu-who {
  margin: 0;
  padding: 0.4rem 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.user-menu-who strong { color: var(--text); }

.theme-choice {
  border: none;
  margin: 0;
  padding: 0.4rem 0.5rem 0.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
}

.theme-choice legend {
  padding: 0;
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  float: left;
  width: 100%;
}

.theme-choice label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.875rem;
  cursor: pointer;
}

.menu-item {
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text);
  text-align: left;
  padding: 0.5rem;
  font-size: 0.9rem;
}

.menu-item:hover { background: var(--hover); }

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

/* List settings menu (per list, extensible: add .menu-item buttons) */
.list-menu {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.list-menu[hidden] { display: none; }

.list-menu-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  min-width: 32px;
  height: 28px;
  padding: 0 0.4rem;
}

.list-menu-btn:hover,
.list-menu-btn[aria-expanded="true"] {
  background: var(--hover);
  border-color: var(--border);
  color: var(--text);
}

.list-menu-panel {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 20;
  width: min(240px, calc(100vw - 2rem));
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  white-space: normal;
}

.list-menu-panel[hidden] { display: none; }

.menu-item[hidden] { display: none; }

.menu-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.menu-item:disabled:hover { background: none; }

.menu-item.danger { color: var(--danger); }

.menu-hint {
  margin: 0;
  padding: 0 0.5rem 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

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

.list-action-status {
  margin: -0.75rem 0 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.list-action-status.error { color: var(--danger); }

@media (max-width: 720px) {
  #app-view { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .content { padding: 1rem; }

  /* Nur ein Screen gleichzeitig: Übersicht ODER Listeninhalt */
  .sidebar { display: flex; }
  .content { display: none; }
  #app-view.mobile-detail .sidebar { display: none; }
  #app-view.mobile-detail .content { display: block; }
  .back-btn { display: inline-flex; align-items: center; }

  /* Keep the title and the list menu button on one line. */
  .list-view-header { flex-wrap: nowrap; }
}

/* .icon-btn sets display, so the hidden header button of the image import
   (shown only by ImageImportUi.setAvailable(true)) needs this rule. */
.icon-btn[hidden] { display: none; }

/* Image import dialog ("Liste aus Foto erstellen", public/image-import-ui.js).
   Builds on .copy-dialog; the steps are switched with hidden, data-step on
   the dialog only adapts the preview. On phones it fills the screen. */
.import-dialog {
  width: min(560px, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  overflow: auto;
}

/* Elements of the dialog with a display of their own stay hidden. */
.import-dialog [hidden] { display: none !important; }

.import-step {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* The file input is visually hidden inside its label: the label looks and
   reacts like the primary button (.copy-dialog label is a text label). */
.copy-dialog .import-file-label {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
  min-height: 44px;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.copy-dialog .import-file-label:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.copy-dialog .import-file-label:has(input:disabled) {
  opacity: 0.6;
  cursor: progress;
}

.import-preview {
  margin: 0;
  display: flex;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.import-preview img {
  display: block;
  max-width: 100%;
  max-height: 40vh;
  object-fit: contain;
}

/* While editing, the photo is only a reminder. */
.import-dialog[data-step="edit"] .import-preview img { max-height: 120px; }

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

.import-spinner {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: import-spin 0.9s linear infinite;
}

@keyframes import-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .import-spinner { animation-duration: 3s; }
}

.import-warnings {
  margin: 0;
  padding: 0.5rem 0.75rem 0.5rem 1.75rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.import-items-label {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.import-items {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.import-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}

.import-item .import-item-text {
  flex: 1 1 10rem;
  min-width: 0;
}

.import-item-error { flex-basis: 100%; }

.import-item-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  background: none;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.import-item-btn:hover:not(:disabled) { background: var(--hover); }
.import-item-btn.danger { color: var(--danger); }

.import-item-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.import-dialog .import-add { margin-top: 0; }

.import-dialog .import-add:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* Inline confirmation before a draft is discarded (no nested dialog). */
.import-confirm {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--danger);
  border-radius: 8px;
}

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

@media (max-width: 720px) {
  .import-dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: none;
    border-radius: 0;
  }

  /* Actions stay reachable at the bottom while the task list scrolls. */
  .import-actions {
    position: sticky;
    bottom: 0;
    margin: 0 -1.25rem;
    padding: 0.75rem 1.25rem;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
  }

  .import-actions button { min-height: 44px; }
}
