:root {
  --background: #f5f5f4;
  --surface: #ffffff;
  --surface-raised: #ececea;
  --border: #dddcd8;
  --text: #1c1c1a;
  --text-muted: #77766f;
  --accent: #d97706;
  --accent-soft: rgba(217, 119, 6, 0.12);
  --status-created: #9a9a92;
  --status-started: #2f80ed;
  --status-testing: #8e44ad;
  --status-done: #27ae60;
  --status-cancelled: #b23b3b;
}
[data-theme="dark"] {
  --background: #16171a;
  --surface: #1e2024;
  --surface-raised: #26292e;
  --border: #33363c;
  --text: #e6e6e3;
  --text-muted: #8b8d93;
  --accent: #f0a53c;
  --accent-soft: rgba(240, 165, 60, 0.14);
  --status-created: #7b7d84;
  --status-started: #5aa3ff;
  --status-testing: #b57bdc;
  --status-done: #4ccb7a;
  --status-cancelled: #e06a6a;
}

* { box-sizing: border-box; }
html { height: 100%; }
body { margin: 0; min-height: 100vh; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--background);
  color: var(--text);
  display: flex;
}
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 13px; padding: 4px 0; }

/* Sidebar */
#sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  gap: 10px;
  height: 100vh;
  position: sticky;
  top: 0;
}
.sidebar-header { display: flex; justify-content: space-between; align-items: center; padding: 0 6px; }
.brand { font-weight: 700; letter-spacing: 0.04em; display: inline-flex; align-items: center; gap: 8px; }
.brand-logo { width: 20px; height: 20px; }
.icon-button {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  width: 28px; height: 28px; cursor: pointer;
}
.icon-button:hover { background: var(--surface-raised); }
#project-list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.project-link {
  display: flex; align-items: center; justify-content: space-between;
  text-align: left; background: none; border: none; border-radius: 6px;
  padding: 7px 10px; cursor: pointer; width: 100%;
}
.project-link:hover { background: var(--surface-raised); }
.project-link.selected { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.project-link.paused { color: var(--text-muted); font-style: italic; }
.project-link .count { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.paused-divider {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); padding: 10px 10px 2px;
}
.inline-form input {
  width: 100%; background: transparent; border: 1px dashed var(--border);
  border-radius: 6px; padding: 7px 10px; outline: none;
}
.inline-form input:focus { border-style: solid; border-color: var(--accent); }

/* Main */
#main { flex: 1; padding: 28px 40px 80px; max-width: 1130px; }
#empty-state { color: var(--text-muted); margin-top: 60px; }
.project-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  flex-wrap: wrap;
  position: sticky; top: 0; z-index: 15;
  background: var(--background);
  padding: 24px 0 12px; margin: -28px 0 16px;
  border-bottom: 1px solid var(--border);
}
h1 { font-size: 24px; margin: 0; outline: none; padding: 2px 6px; margin-left: -6px; border-radius: 6px; }
h1:focus { background: var(--surface-raised); }
.header-actions { display: flex; gap: 6px; align-items: center; }
.tab, .button {
  background: none; border: 1px solid transparent; border-radius: 6px;
  padding: 5px 12px; cursor: pointer; color: var(--text-muted);
}
.tab.active { background: var(--surface); border-color: var(--border); color: var(--text); }
.button.subtle:hover { background: var(--surface-raised); color: var(--text); }
.count { font-size: 12px; }

/* Sections */
.section { margin-bottom: 26px; }
.section h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-muted); margin: 0 0 8px; display: flex; align-items: center; gap: 8px;
  outline: none;
}
.section h2[contenteditable]:focus { color: var(--text); }
.section h2 .delete-section {
  opacity: 0; background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 12px;
}
.section:hover h2 .delete-section { opacity: 1; }
.prio-section { padding: 12px 14px; background: var(--accent-soft); border-radius: 10px; }
.prio-section h2 { color: var(--accent); }

.task-list { list-style: none; margin: 0; padding: 0; }
.task {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: 6px; margin-left: -8px;
}
.task:hover { background: var(--surface-raised); }
.task .title { flex: 1; outline: none; padding: 1px 4px; border-radius: 4px; min-width: 0; }
.task .title:focus { background: var(--surface); }
.task.status-done .title, .task.status-cancelled .title { text-decoration: line-through; color: var(--text-muted); }
.task .status {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  font-size: 11px; padding: 2px 8px; cursor: pointer; text-transform: uppercase; letter-spacing: 0.05em;
  appearance: none; -webkit-appearance: none;
}
.status-created .status { color: var(--status-created); opacity: 0; }
.task:hover .status, .task .status:focus { opacity: 1; }
.status-testing .status { color: var(--status-testing); border-color: var(--status-testing); }
.status-started .status { color: var(--status-started); border-color: var(--status-started); }
.status-done .status { color: var(--status-done); border-color: var(--status-done); }
.status-cancelled .status { color: var(--status-cancelled); }
.task .kind {
  background: none; border: none; cursor: pointer; font-size: 13px; width: 24px; color: var(--text-muted);
}
.task .kind.idea { color: var(--accent); }
.task .kind.question { color: var(--status-started); }
.task .kind.note { color: var(--status-done); }
.task .kind.bug { color: var(--status-cancelled); }
.task .star { background: none; border: none; cursor: pointer; font-size: 16px; color: var(--text-muted); opacity: 0.35; }
.task .star.on, .task:hover .star { opacity: 1; }
.task .star.on { color: var(--accent); }
.task .section-ref { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.task .date { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.task .restore { background: none; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; padding: 2px 8px; cursor: pointer; color: var(--text-muted); }
.task .restore:hover { color: var(--text); }
.archive .task { align-items: flex-start; }
.archive-project-group { margin-top: 18px; }

.section .inline-form { margin-top: 4px; }
.section .inline-form input { border: none; padding-left: 4px; }
.section .inline-form input:focus { border: none; background: var(--surface-raised); }

@media (max-width: 700px) {
  body { flex-direction: column; }
  #sidebar {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 20;
    border-right: none; border-bottom: 1px solid var(--border);
    padding: 8px 10px; gap: 6px;
  }
  #project-list { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding-bottom: 2px; }
  .project-link { width: auto; flex-shrink: 0; padding: 5px 10px; }
  .paused-divider { padding: 5px 4px 0; white-space: nowrap; }
  .sidebar-row { display: flex; gap: 8px; }
  #search-input { flex: 1; }
  #new-project-form { flex: 1; }
  #main { padding: 16px; }
  .project-header { position: static; margin: 0 0 16px; padding: 0 0 10px; }
}

/* Project colors */
.color-dot, .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--project-color, #888); flex-shrink: 0; }
.project-link { gap: 8px; }
.project-link .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-block { display: flex; align-items: center; gap: 14px; }
h1[data-color] { border-left: 4px solid var(--project-color, transparent); padding-left: 10px; margin-left: 0; }
.color-picker { display: flex; gap: 6px; }
.swatch { width: 14px; height: 14px; border: 2px solid transparent; cursor: pointer; padding: 0; opacity: 0.5; }
.swatch:hover { opacity: 1; }
.swatch.selected { opacity: 1; border-color: var(--text); }
[data-color="slate"]  { --project-color: #8a9099; }
[data-color="red"]    { --project-color: #e05252; }
[data-color="orange"] { --project-color: #f08a3c; }
[data-color="yellow"] { --project-color: #e6c239; }
[data-color="green"]  { --project-color: #4cbf6e; }
[data-color="teal"]   { --project-color: #38b2ac; }
[data-color="blue"]   { --project-color: #4f8ff7; }
[data-color="purple"] { --project-color: #a473e6; }
[data-color="pink"]   { --project-color: #e86fa9; }

/* Markdown in tasks */
.task .title { cursor: text; }
.task .title code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--surface-raised); padding: 1px 5px; border-radius: 4px; }
.task .title a { color: var(--accent); }
.task .title .md-bullet { color: var(--text-muted); }
.title-editor {
  flex: 1; resize: none; border: 1px solid var(--accent); border-radius: 4px; padding: 2px 4px;
  background: var(--surface); font: inherit; color: inherit; line-height: 1.45; outline: none; min-width: 0;
  overflow: hidden;
}
.task { align-items: flex-start; }
/* All row controls share one fixed height matching the title's first line, so icons sit on one line. */
.task > .kind, .task > .star, .task > .quick-archive, .task > .attach, .task > .delete-task,
.task > .drag-handle, .task > .section-ref, .task > .created-date, .task > .date, .task > .restore {
  height: 22px; display: inline-flex; align-items: center; justify-content: center; line-height: 1;
}
.task > .status { height: 22px; padding-top: 0; padding-bottom: 0; }
.task > .title { padding-top: 0; }

.task .delete-task {
  background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 16px; line-height: 1;
  opacity: 0; padding: 0 4px;
}
.task:hover .delete-task { opacity: 0.6; }
.task .delete-task:hover { opacity: 1; color: var(--status-cancelled); }

/* Drag & drop of projects */
.project-link { position: relative; }
.project-link.dragging { opacity: 0.4; }
.project-link.drop-before::before, .project-link.drop-after::after {
  content: ""; position: absolute; left: 6px; right: 6px; height: 2px; background: var(--accent); border-radius: 2px;
}
.project-link.drop-before::before { top: -2px; }
.project-link.drop-after::after { bottom: -2px; }

/* Whole-project markdown editor */
.doc-editor {
  width: 100%; height: calc(100vh - 250px); min-height: 300px; resize: vertical;
  font: 14px/1.5 ui-monospace, Menlo, Consolas, monospace;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; outline: none;
}
.doc-editor:focus { border-color: var(--accent); }
.editor-footer { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.button.primary { background: var(--accent); color: var(--background); border-color: var(--accent); }
.button.primary:hover { filter: brightness(1.1); }

.editor-toolbar { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.marker-button {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 9px; cursor: pointer; font-size: 15px; line-height: 1.3;
}
.marker-button:hover { border-color: var(--accent); background: var(--surface-raised); }

/* Modals */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px 22px; width: min(560px, 92vw); max-height: 85vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
}
.modal h3 { margin: 0; font-size: 17px; }
.modal label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
.modal select {
  background: var(--background); border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 10px; outline: none; color: var(--text); font: inherit;
}
.modal label code { font-size: 12px; }
.modal input[type="password"], .modal input:not([type]), .modal textarea {
  background: var(--background); border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 10px; outline: none; color: var(--text); font: inherit;
}
.modal textarea { font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; resize: vertical; }
.modal input:focus, .modal textarea:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 8px; align-items: center; }
.modal p { margin: 0; }

#import-error {
  background: var(--background); border: 1px solid var(--status-cancelled); border-radius: 6px;
  padding: 10px 12px; margin: 0 0 8px; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word; color: var(--status-cancelled);
  max-height: 200px; overflow-y: auto; user-select: text;
}

/* Sidebar search */
#search-input {
  background: var(--background); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; outline: none; font-size: 13px;
}
#search-input:focus { border-color: var(--accent); }
#search-view h1 { margin-bottom: 16px; }
.search-project { font-size: 12px; font-weight: 600; white-space: nowrap; }
.task.archived-hit { opacity: 0.6; }
.task.flash { animation: flash-bg 1.6s ease-out; }
@keyframes flash-bg { 0%, 40% { background: var(--accent-soft); } 100% { background: transparent; } }

/* Instructions box */
.notes-section { padding: 12px 14px; background: color-mix(in srgb, var(--status-done) 9%, transparent); border-radius: 10px; }
.notes-section h2 { color: var(--status-done); }

/* Repo chip */
#repo-chip { display: inline-flex; align-items: center; gap: 4px; }
#repo-chip a { color: var(--text-muted); font-size: 13px; text-decoration: none; border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; }
#repo-chip a:hover { color: var(--accent); border-color: var(--accent); }
#repo-chip .repo-edit { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 12px; opacity: 0.5; }
#repo-chip .repo-edit:hover { opacity: 1; }
#repo-chip .repo-add { background: none; border: 1px dashed var(--border); border-radius: 999px; padding: 3px 10px; cursor: pointer; color: var(--text-muted); font-size: 12px; }
#repo-chip input { background: var(--background); border: 1px solid var(--accent); border-radius: 6px; padding: 3px 8px; outline: none; font-size: 13px; width: 260px; }

/* Section TOC */
.project-body { display: flex; gap: 30px; align-items: flex-start; }
.project-main { flex: 1; min-width: 0; max-width: 860px; }
#section-toc {
  position: sticky; top: 96px; width: 190px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 1px;
  max-height: calc(100vh - 48px); overflow-y: auto;
  border-left: 1px solid var(--border); padding-left: 4px;
}
#section-toc button {
  text-align: left; background: none; border: none; border-radius: 6px;
  padding: 4px 9px; cursor: pointer; color: var(--text-muted); font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#section-toc button:hover { color: var(--text); background: var(--surface-raised); }
#section-toc button.special { color: var(--accent); }
#section-toc button .toc-count { color: var(--text-muted); font-size: 11px; margin-left: 4px; }
@media (max-width: 1000px) { #section-toc { display: none; } }
.section.flash-section, .prio-section.flash-section, .notes-section.flash-section { animation: flash-bg 1.6s ease-out; }

/* Etapp 1 */
.task .quick-archive {
  background: none; border: none; cursor: pointer; font-size: 13px; padding: 0 2px;
  opacity: 0; filter: grayscale(1);
}
.task:hover .quick-archive { opacity: 0.6; }
.task .quick-archive:hover { opacity: 1; filter: none; }
.button.danger { color: var(--status-cancelled); border-color: transparent; }
.button.danger:hover { background: color-mix(in srgb, var(--status-cancelled) 12%, transparent); }
.button.danger:disabled { opacity: 0.4; cursor: not-allowed; }
#delete-project-run { border: 1px solid var(--status-cancelled); }

/* Etapp 2: drag & drop */
.drag-handle {
  cursor: grab; color: var(--text-muted); opacity: 0; font-size: 13px; user-select: none;
  padding: 0 2px; flex-shrink: 0;
}
.task:hover .drag-handle, .section h2:hover .drag-handle { opacity: 0.5; }
.drag-handle:hover { opacity: 1 !important; }
.task.dragging, .section.dragging { opacity: 0.4; }
.section { position: relative; }
.section.drop-before::before, .section.drop-after::after {
  content: ""; position: absolute; left: 0; right: 0; height: 2px; background: var(--accent); border-radius: 2px;
}
.section.drop-before::before { top: -13px; }
.section.drop-after::after { bottom: -13px; }
.section.drop-target { outline: 2px dashed var(--accent); outline-offset: 6px; border-radius: 8px; }
#section-toc button.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; color: var(--accent); }

/* Etapp 3: bilder */
.task .attach {
  background: none; border: none; cursor: pointer; font-size: 12px; padding: 0 2px;
  opacity: 0; filter: grayscale(1);
}
.task:hover .attach { opacity: 0.6; }
.task .attach:hover { opacity: 1; filter: none; }
.task-with-attachments { list-style: none; margin-left: -8px; }
.attachment-strip { display: flex; gap: 8px; flex-wrap: wrap; padding: 2px 0 6px 42px; }
.attachment-thumb { position: relative; display: inline-block; }
.attachment-thumb img {
  height: 64px; max-width: 160px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--border); cursor: zoom-in; display: block;
}
.attachment-thumb .attachment-remove {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; line-height: 1;
  border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-muted); cursor: pointer; font-size: 12px; padding: 0; opacity: 0;
}
.attachment-thumb:hover .attachment-remove { opacity: 1; }
.attachment-thumb .attachment-remove:hover { color: var(--status-cancelled); }
.lightbox {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.75); z-index: 30;
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }

.title-editor.uploading { border-color: var(--status-started); }
.title-editor.uploaded { border-color: var(--status-done); }

/* Radnivå-drop för omsortering */
.task { position: relative; }
.task.drop-before::before, .task.drop-after::after {
  content: ""; position: absolute; left: 4px; right: 4px; height: 2px; background: var(--accent); border-radius: 2px; z-index: 1;
}
.task.drop-before::before { top: -1px; }
.task.drop-after::after { bottom: -1px; }

/* Skapad-datum */
.task .created-date { font-size: 11px; color: var(--text-muted); white-space: nowrap; opacity: 0.6; }
#recent-list .task { cursor: default; }

/* Typ-meny */
.kind-menu {
  position: absolute; left: 24px; top: calc(100% - 4px); z-index: 25;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 4px; display: flex; flex-direction: column; gap: 1px; min-width: 160px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.kind-menu button {
  display: flex; align-items: center; gap: 8px; text-align: left;
  background: none; border: none; border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 14px;
}
.kind-menu button:hover { background: var(--surface-raised); }
.kind-menu button.selected { background: var(--accent-soft); color: var(--accent); }
.kind-menu-icon { width: 18px; text-align: center; }

/* Arkivets statusbadge (span, inte select) */
.archive-status { opacity: 1 !important; cursor: default; display: inline-flex; align-items: center; }

/* Kopierad-feedback på thumbnail */
.attachment-thumb.copied::after {
  content: "Kopierad ✓"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.65); color: #4ccb7a; font-size: 11px; font-weight: 600; border-radius: 6px;
}

/* Kopieringstoast */
#copy-toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 40;
  background: var(--surface); border: 1px solid var(--accent); color: var(--text);
  border-radius: 8px; padding: 8px 14px; font-size: 13px;
  opacity: 0; transform: translateY(6px); transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
}
#copy-toast.visible { opacity: 1; transform: translateY(0); }

/* Bilder buffrade i snabbinmatningen */
.pending-images { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 4px 2px; }
.pending-images .attachment-thumb img { height: 44px; }

/* Statusfilter i headern */
#status-filter {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px; font-size: 13px; color: var(--text-muted); cursor: pointer; outline: none;
}
#status-filter.filter-active { border-color: var(--accent); color: var(--accent); }

/* Inloggning */
#login-view {
  position: fixed; inset: 0; z-index: 50; background: var(--background);
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 40px 48px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px;
  max-width: 90vw;
}
.login-logo { width: 56px; height: 56px; color: var(--text); }
.login-card h1 { margin: 0; padding: 0; }
.google-button {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 10px;
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 22px; color: var(--text); text-decoration: none; font-weight: 600;
}
.google-button:hover { border-color: var(--accent); }
#login-message { max-width: 320px; color: var(--status-cancelled); }

/* Användarbricka */
#user-chip {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; margin-top: 2px;
  border-top: 1px solid var(--border); padding-top: 10px; font-size: 13px;
}
#user-avatar { width: 24px; height: 24px; border-radius: 50%; }
#user-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }

/* ---------- PWA/offline + röstinmatning ---------- */
#offline-banner {
  position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%);
  background: var(--surface-raised); border: 1px solid var(--border); color: var(--text-muted);
  padding: 6px 14px; border-radius: 999px; font-size: 13px; z-index: 60;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25); white-space: nowrap; max-width: 92vw;
  overflow: hidden; text-overflow: ellipsis;
}
.task.queued { color: var(--text-muted); font-style: italic; padding: 3px 0 3px 26px; }
.section .inline-form { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.section .inline-form input { flex: 1; min-width: 200px; }
.section .inline-form .pending-images { flex-basis: 100%; }
.mic-button {
  background: none; border: none; cursor: pointer; font-size: 15px;
  opacity: 0.4; padding: 3px 6px; border-radius: 6px; line-height: 1;
}
.mic-button:hover { opacity: 1; }
.mic-button.recording { opacity: 1; background: var(--accent-soft); animation: mic-pulse 1.2s ease-in-out infinite; }
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-soft); }
  50% { box-shadow: 0 0 0 6px var(--accent-soft); }
}

/* ---------- Mobilanpassning av uppgiftsraderna ---------- */
@media (max-width: 700px) {
  /* Titeln får radbredden; datum/status/stjärna radbryts till raden under istället för
     att klämma ihop titeln till ett ord per rad. */
  .task { flex-wrap: wrap; gap: 2px 8px; }
  .task > .title { min-width: 70%; }
  /* Hover-knappar är osynliga utan mus men tog ändå plats på touch — bort med dem. */
  .task > .drag-handle, .task > .attach, .task > .quick-archive, .task > .delete-task { display: none; }
  /* Flikraden i projekthuvudet är bredare än skärmen — låt knapparna radbrytas. */
  .header-actions { flex-wrap: wrap; }
  /* Titelraden (titel + färgprickar + repo-chip) radbryts, och titeln får krympa. */
  .title-block { min-width: 0; flex-wrap: wrap; }
  .title-block h1 { min-width: 0; overflow-wrap: anywhere; }
  /* Utan hover måste status alltid synas (created är annars opacity 0 tills hover). */
  .status-created .status { opacity: 1; }
}

/* ---------- Dikteringsvyn ---------- */
#dictation-view {
  position: fixed; inset: 0; z-index: 100;
  background: color-mix(in srgb, var(--background) 88%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
#dictation-view.hidden { display: none; }
.dictation-card {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 24px; max-width: 560px; width: 100%; text-align: center;
}
#dictation-section-name { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; }
.dictation-circle {
  position: relative; width: 112px; height: 112px; border-radius: 50%;
  border: 2px solid var(--accent); background: var(--accent-soft);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.dictation-mic { font-size: 44px; line-height: 1; }
/* "Levande" lyssnar-indikator: två ringar som pulserar ut ur cirkeln, omlott. */
.dictation-circle::before, .dictation-circle::after {
  content: ""; position: absolute; inset: -2px; border-radius: 50%;
  border: 2px solid var(--accent); opacity: 0;
  animation: dictation-ripple 2.4s ease-out infinite;
}
.dictation-circle::after { animation-delay: 1.2s; }
@keyframes dictation-ripple {
  0% { transform: scale(1); opacity: 0.55; }
  100% { transform: scale(1.75); opacity: 0; }
}
.dictation-hint { font-size: 13px; }
#dictation-text {
  min-height: 64px; max-height: 40vh; overflow-y: auto;
  font-size: 20px; line-height: 1.45; overflow-wrap: anywhere;
}
#dictation-text-interim { opacity: 0.55; }
@media (prefers-reduced-motion: reduce) {
  .dictation-circle::before, .dictation-circle::after { animation: none; }
}

/* ---------- Dra-för-att-uppdatera (standalone-PWA) ---------- */
#pull-refresh {
  position: fixed; top: -48px; left: 50%; transform: translateX(-50%); z-index: 90;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface-raised); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease;
}
#pull-refresh.hidden { display: none; }
.pull-refresh-icon { font-size: 18px; color: var(--text-muted); transition: transform 0.15s ease; }
#pull-refresh.armed .pull-refresh-icon { color: var(--accent); transform: rotate(180deg); }
#pull-refresh.refreshing {
  transform: translateX(-50%) translateY(64px);
  transition: none;
}
#pull-refresh.refreshing .pull-refresh-icon { color: var(--accent); animation: pull-spin 0.8s linear infinite; }
@keyframes pull-spin { to { transform: rotate(360deg); } }

/* ---------- Online-indikator + mobilens projektrad ---------- */
#connection-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--status-cancelled); margin-right: 8px; vertical-align: 2px;
  transition: background 0.3s ease;
}
#connection-dot.online { background: var(--status-done); }
.project-add { display: none; }
@media (max-width: 700px) {
  /* Nytt projekt: litet + i samma rad som projekten; textraden visas först vid tryck. */
  .sidebar-row { display: none; }
  .sidebar-row.revealed { display: flex; }
  .project-add {
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0; width: 30px; height: 30px; align-self: center;
    border-radius: 50%; border: 1px dashed var(--border); background: none;
    color: var(--text-muted); font-size: 17px; line-height: 1; cursor: pointer; padding: 0;
  }
  /* Aktivt projekt först i raden så namnet alltid syns i sticky-toppen. */
  .project-link.selected { order: -1; }
}

/* ---------- Sektions-chips, scroll-spy och uppmätta sticky-höjder ---------- */
/* TOC:en följer headerns verkliga höjd — hårdkodade 96px lät headern täcka översta raderna. */
#section-toc { top: var(--toc-top, 96px); max-height: calc(100vh - var(--toc-top, 96px) - 20px); }
#section-toc button.active { color: var(--accent); background: var(--accent-soft); }
/* Hopp från TOC/chips (och scroll-spyns "landning") hamnar nedanför sticky-ytorna. */
.section, .prio-section, .notes-section { scroll-margin-top: calc(var(--scroll-sticky-offset, 100px) + 2px); }

#section-chips { display: none; }
@media (max-width: 700px) {
  #section-chips {
    display: flex; gap: 6px; overflow-x: auto;
    position: sticky; top: var(--chips-top, 0px); z-index: 15;
    background: var(--background); padding: 8px 0; margin-bottom: 4px;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  #section-chips::-webkit-scrollbar { display: none; }
  #section-chips.hidden, #section-chips:empty { display: none; }
  #section-chips .chip {
    flex-shrink: 0; border: 1px solid var(--border); background: var(--surface);
    color: var(--text-muted); border-radius: 999px; padding: 5px 12px;
    font-size: 13px; line-height: 1.2; cursor: pointer; white-space: nowrap;
    max-width: 45vw; overflow: hidden; text-overflow: ellipsis;
  }
  #section-chips .chip.special { color: var(--accent); }
  #section-chips .chip.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); font-weight: 600; }
  /* Större träffyta för mikrofonen på touch. */
  .mic-button { font-size: 22px; padding: 8px 12px; opacity: 0.6; }
}

/* ---------- Allowlist i inställningarna ---------- */
#allowlist-section { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 10px; }
#allowlist-section h4 { margin: 0 0 2px; }
#allowlist-items { list-style: none; margin: 8px 0; padding: 0; max-height: 180px; overflow-y: auto; }
#allowlist-items li { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; }
#allowlist-items .origin { color: var(--text-muted); font-size: 11px; border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; }
#allowlist-items li > button { margin-left: auto; background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 15px; }
#allowlist-items li > button:hover { color: var(--status-cancelled); }
#allowlist-form { display: flex; gap: 6px; }
#allowlist-form input { flex: 1; }

/* ---------- Kopiera-knapp i lightboxen ---------- */
.lightbox-copy {
  position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 9px 18px; font-size: 14px; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.lightbox-copy:hover { border-color: var(--accent); color: var(--accent); }
.lightbox-copy.copied { border-color: var(--status-done); color: var(--status-done); }
