:root {
  --bg: #f5f3ee;
  --card: #ffffff;
  --card-hover: #faf9f6;
  --line: #e7e3da;
  --text: #22211f;
  --muted: #7a766d;
  --accent: #2f6f6a;
  --accent-soft: #e3eeec;
  --shadow: 0 1px 2px rgba(40, 35, 25, .05), 0 4px 16px rgba(40, 35, 25, .04);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --card: #1f1f1d;
    --card-hover: #262624;
    --line: #2e2d2a;
    --text: #ecebe6;
    --muted: #8f8b82;
    --accent: #7cc0b8;
    --accent-soft: #23302e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--card); border: 1px solid var(--line);
  border-radius: 20px; padding: 32px 24px; box-shadow: var(--shadow); display: grid; gap: 10px;
}
.login-card img { border-radius: 13px; justify-self: center; }
.login-card h1 { margin: 4px 0 12px; text-align: center; font-size: 20px; font-weight: 600; }
.login-card label { font-size: 13px; color: var(--muted); }
.login-card input {
  font: inherit; font-size: 16px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login-card button {
  margin-top: 6px; padding: 12px; border: 0; border-radius: 10px; background: var(--accent);
  color: #fff; font-weight: 600; cursor: pointer;
}
@media (prefers-color-scheme: dark) { .login-card button { color: #10201e; } }
.note, .error { margin: 0; font-size: 13px; }
.error { color: #c0392b; }
.note code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }

/* ---------- Side ---------- */
.page {
  max-width: 1680px; margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 40px max(16px, env(safe-area-inset-left));
}
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin: 12px 0 22px; }
.greeting { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -.01em; }
.date { margin: 2px 0 0; color: var(--muted); }
.clock { margin: 0; font-size: 40px; font-weight: 300; letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--muted); }

.search-wrap { position: relative; margin-bottom: 28px; }
.search-wrap input {
  width: 100%; font: inherit; font-size: 17px; padding: 15px 48px 15px 46px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  box-shadow: var(--shadow); -webkit-appearance: none; appearance: none;
}
.search-wrap input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.search-wrap input::-webkit-search-cancel-button { display: none; }
.search-icon {
  position: absolute; left: 16px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%);
  fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round;
}
.hint {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  font: 12px ui-monospace, SFMono-Regular, monospace; color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px; padding: 2px 7px;
}
@media (pointer: coarse) { .hint { display: none; } }

.section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 12px 2px; }

/* Favoritter */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-bottom: 34px; }
.tile {
  display: grid; justify-items: center; gap: 8px; padding: 14px 6px 12px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); text-align: center;
  transition: background .15s, transform .15s;
}
@media (hover: hover) { .tile:hover { background: var(--card-hover); transform: translateY(-1px); } }
.tile .fav { width: 32px; height: 32px; border-radius: 8px; font-size: 15px; }
.tile span.label { font-size: 12.5px; line-height: 1.25; max-width: 100%; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }

/* Mapper */
.cards { columns: 4 260px; column-gap: 16px; }
.card {
  break-inside: avoid; margin-bottom: 14px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px 6px;
}
.card > h2 { display: flex; justify-content: space-between; align-items: baseline; margin: 6px 10px 6px; font-size: 14px; font-weight: 600; }
.count { font-size: 12px; font-weight: 400; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; }
.list .list { padding-left: 14px; border-left: 1px solid var(--line); margin-left: 17px; }
.row {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 9px; min-height: 38px;
  transition: background .12s;
}
.row.active { background: var(--accent-soft); }
@media (hover: hover) { .row:hover { background: var(--accent-soft); } }
.row:active, .tile:active { background: var(--accent-soft); }
.row .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.row .fav { width: 18px; height: 18px; flex: none; border-radius: 4px; font-size: 10px; }
details > summary { list-style: none; cursor: pointer; color: var(--text); }
details > summary::-webkit-details-marker { display: none; }
.folder-icon { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linejoin: round; }
details[open] > summary .folder-icon { stroke: var(--accent); }
.more {
  display: block; width: calc(100% - 12px); margin: 4px 6px 2px; padding: 8px; border: 0; border-radius: 9px;
  background: transparent; color: var(--accent); font-size: 13px; cursor: pointer; text-align: left;
}
@media (hover: hover) { .more:hover { background: var(--accent-soft); } }

.fav { display: grid; place-items: center; object-fit: contain; }
span.fav { background: var(--accent-soft); color: var(--accent); font-weight: 600; text-transform: uppercase; }

/* Søgeresultater */
.results { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; }
.results .row { min-height: 48px; }
.path { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .text { flex: 1; min-width: 0; }
.results .text .label { display: block; }
.empty { padding: 18px 14px; color: var(--muted); }
.empty b { color: var(--text); }

.foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 30px; font-size: 13px; color: var(--muted); }
.foot a:hover { color: var(--text); }

@media (max-width: 600px) {
  .top { margin-top: 4px; }
  .greeting { font-size: 22px; }
  .clock { font-size: 30px; }
  .tiles { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .tile { padding: 12px 4px 10px; }
  .tile .fav { width: 30px; height: 30px; }
  .tile span.label { font-size: 11.5px; }
  .row { min-height: 44px; }
}
@media (max-width: 360px) { .tiles { grid-template-columns: repeat(3, 1fr); } }

/* Gemt fra iPhone */
.card.inbox { margin-bottom: 34px; border-color: var(--accent); }
.inbox-note { margin: 4px 10px 6px; font-size: 12.5px; color: var(--muted); }

/* Fod */
.foot-links { display: flex; gap: 18px; }
.linkish { background: none; border: 0; padding: 0; cursor: pointer; color: inherit; font-size: inherit; }
.linkish:hover { color: var(--text); }

/* Rediger ikoner */
body.editing .linkish { color: var(--accent); font-weight: 600; }
body.editing a.row, body.editing a.tile { outline: 1.5px dashed var(--accent); outline-offset: -3px; cursor: pointer; }
body.editing #app::before {
  content: "Tryk på et bogmærke for at omdøbe, slette eller skifte ikon.";
  display: block; margin: -12px 0 20px; padding: 10px 14px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent); font-size: 14px;
}

dialog#icon-dialog {
  width: min(420px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 18px;
  background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog#icon-dialog::backdrop { background: rgba(20, 18, 15, .35); }
#icon-form { display: grid; gap: 8px; padding: 22px; }
.dlg-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.dlg-preview .fav { width: 44px; height: 44px; border-radius: 11px; font-size: 18px; }
.dlg-titles { display: grid; min-width: 0; }
.dlg-titles strong, .dlg-titles span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-titles span { font-size: 13px; color: var(--muted); }
.dlg-label { font-size: 13px; color: var(--muted); margin-top: 6px; }
#icon-form input[type=url] {
  font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
#icon-form input[type=file] { font-size: 14px; }
.dlg-error { margin: 0; min-height: 1.2em; font-size: 13px; color: #c0392b; }
.dlg-buttons { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.dlg-buttons .spacer { flex: 1; }
.dlg-buttons button { font: inherit; font-size: 14px; padding: 9px 14px; border-radius: 10px; cursor: pointer; border: 1px solid var(--line); background: var(--bg); }
.dlg-buttons .primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.dlg-buttons .primary:disabled { opacity: .6; }
.dlg-buttons .danger { color: #c0392b; background: transparent; border-color: transparent; padding-left: 4px; }
.dlg-buttons .danger.confirm { background: #c0392b; border-color: #c0392b; color: #fff; padding-left: 14px; }
#icon-form input[type=text] {
  font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
#icon-form input[type=text]:focus, #icon-form input[type=url]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.dlg-section { display: flex; justify-content: space-between; align-items: baseline; margin-top: 10px; }
.dlg-section .dlg-label { margin-top: 0; }
.linkish.small { font-size: 13px; color: var(--accent); }
@media (prefers-color-scheme: dark) { .dlg-buttons .primary { color: #10201e; } }

a, button, summary { -webkit-tap-highlight-color: transparent; }

.top-right { display: grid; justify-items: end; gap: 2px; }
.edit-btn { font-size: 13px; color: var(--muted); }
body.editing .edit-btn { color: var(--accent); font-weight: 600; }
