:root {
  --bg: #f3f6f8;
  --surface: #fff;
  --surface-2: #f7fafb;
  --border: #dfe6eb;
  --text: #13232f;
  --muted: #627482;
  --brand: #0e7c86;
  --brand-ink: #fff;
  --brand-soft: #e3f3f4;
  --danger: #c2413b;
  --ok: #1f8a4c;
  --warn: #b7791f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418; --surface: #151d23; --surface-2: #1a242b; --border: #2a3740;
    --text: #e6eef2; --muted: #93a6b3; --brand: #3fb6bf; --brand-ink: #062226; --brand-soft: #173238;
    --danger: #f07167; --ok: #4ccf86; --warn: #f2b84b;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14.5px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }
code { font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 1px 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 13.5px/1 Inter, system-ui, sans-serif; color: var(--text); text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px 13px;
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .lnk:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px;
}
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; margin-bottom: 14px; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
label.check input { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px 12px; margin: 0 0 14px; }
legend { font-weight: 600; font-size: 13px; padding: 0 4px; }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 30px 28px; box-shadow: 0 10px 40px rgba(0,0,0,.06); display: flex; flex-direction: column; }
.login img { border-radius: 12px; margin-bottom: 12px; }
.login h1 { margin: 0; font-size: 20px; }
.login p { margin: 4px 0 18px; }
.login .btn { margin: 4px 0 16px; padding: 11px; }
.login a { text-align: center; text-decoration: none; }
.error { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); border-radius: 8px; padding: 8px 10px; font-size: 13px; }

/* Top bar */
.bar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.bar-inner { max-width: 1000px; margin: 0 auto; padding: 10px 24px; display: flex; align-items: center; gap: 14px; }
.bar-brand { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.bar-brand img { border-radius: 8px; }
.bar nav { display: flex; gap: 4px; margin-left: auto; }
.status { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.ok { color: var(--ok); }
.status.pending { color: var(--warn); }
.status.err, .status.warn { color: var(--danger); }

.wrap { max-width: 1000px; margin: 0 auto; padding: 24px 24px 80px; }
.toolbar { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar h1 { margin: 0 0 2px; font-size: 22px; }
.toolbar p { margin: 0; }
.toolbar-actions { margin-left: auto; display: flex; gap: 8px; }
.grip-inline { font-weight: 700; }

/* Sections */
.sec { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 14px; overflow: hidden; }
.sec-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.sec.collapsed .sec-head { border-bottom: 0; }
.sec.collapsed .link-list { display: none; }
.collapse { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; width: 24px; height: 28px; transition: transform .15s; }
.sec.collapsed .collapse { transform: rotate(-90deg); }
.sec-title { font-weight: 700; font-size: 15px; width: auto; flex: 0 1 260px; min-width: 80px; background: transparent; border-color: transparent; padding: 5px 8px; }
.sec-title:hover { border-color: var(--border); background: var(--surface); }
.sec-title:focus { background: var(--surface); border-color: var(--brand); }
.count { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.grip { cursor: grab; color: var(--muted); font-size: 16px; padding: 4px 2px; user-select: none; touch-action: none; }
.sec-grip { font-size: 18px; }

.link-list { list-style: none; margin: 0; padding: 6px; min-height: 52px; }
.link-list:empty::after { content: "No links yet – add one, or drag a link here."; display: block; color: var(--muted); font-size: 13px; padding: 14px 10px; text-align: center; border: 1.5px dashed var(--border); border-radius: 8px; }
.lnk { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 8px; cursor: pointer; background: var(--surface); }
.lnk:hover { background: var(--surface-2); }
.lnk .btn { opacity: 0; }
.lnk:hover .btn, .lnk:focus-within .btn { opacity: 1; }
.lnk-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.lnk-text strong { font-size: 14px; }
.lnk-text .url { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lnk-text .desc { font-size: 12.5px; color: var(--text); opacity: .8; }
.warn-note { color: var(--warn); font-size: 12px; }
.lnk.flash { animation: flash 1.4s ease-out; }
@keyframes flash { from { background: var(--brand-soft); } to { background: var(--surface); } }
.drag-ghost { opacity: .4; background: var(--brand-soft) !important; }
.drag-chosen { box-shadow: 0 6px 18px rgba(0,0,0,.12); }
.empty-state { text-align: center; color: var(--muted); padding: 40px; border: 1.5px dashed var(--border); border-radius: 12px; }

.icon { width: 36px; height: 36px; flex: none; border-radius: 9px; display: grid; place-items: center; background: #fff; border: 1px solid var(--border); overflow: hidden; }
.icon img { width: 22px; height: 22px; object-fit: contain; }
.letter { width: 100%; height: 100%; display: grid; place-items: center; color: #fff; font-weight: 700; background: hsl(var(--h) 45% 45%); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--brand); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 99px; font-size: 11px; font-weight: 600; vertical-align: 1px; color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.sec-head .badge { margin-left: 0; }
.lnk.is-hidden > .icon, .lnk.is-hidden .lnk-text .url, .lnk.is-hidden .lnk-text .desc, .lnk.is-hidden .lnk-text strong { opacity: .5; }
.lnk.is-hidden .lnk-text strong .badge { opacity: 1; }
.lnk.is-hidden .btn, .sec.is-hidden .sec-head .btn { opacity: 1; }
.sec.is-hidden { border-style: dashed; }
.sec.is-hidden .link-list, .sec.is-hidden .sec-title { opacity: .55; }

/* Dialogs */
dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(10, 20, 28, .45); }
dialog form { padding: 22px 24px 18px; max-height: calc(100vh - 40px); overflow: auto; }
dialog h2 { margin: 0 0 16px; font-size: 18px; }
.dlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.icon-row { display: flex; gap: 14px; align-items: center; }
.icon-preview .icon { width: 52px; height: 52px; border-radius: 12px; }
.icon-preview .icon img { width: 32px; height: 32px; }
.icon-actions { display: flex; flex-wrap: wrap; gap: 6px; }
#icon-note { margin: 8px 0 0; }
.themes { display: grid; gap: 8px; }
.theme-opt { flex-direction: row; align-items: center; gap: 10px; margin: 0; font-weight: 500; }
.theme-opt input { width: auto; }
.theme-swatch { display: inline-flex; gap: 3px; padding: 5px; border-radius: 7px; border: 1px solid var(--border); }
.theme-swatch i { width: 14px; height: 18px; border-radius: 3px; }
.theme-classic { background: #f3f6f8; } .theme-classic i { background: #fff; border: 1px solid #dfe6eb; } .theme-classic i:first-child { background: #0e7c86; }
.theme-tiles { background: #0b1220; } .theme-tiles i { background: #17223a; } .theme-tiles i:first-child { background: #34c3c9; }
details { border-top: 1px solid var(--border); padding: 12px 0 4px; }
summary { cursor: pointer; font-weight: 600; font-size: 13.5px; margin-bottom: 8px; }
.pw-grid { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; }
.pw-grid label { margin: 0; }
.row-gap { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #13232f; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px; transition: .2s; z-index: 100; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

@media (max-width: 640px) {
  .bar-inner { padding: 8px 16px; flex-wrap: wrap; gap: 6px; }
  .bar-brand strong { display: none; }
  .wrap { padding: 16px 16px 60px; }
  .toolbar-actions { margin-left: 0; width: 100%; }
  .toolbar-actions .btn { flex: 1; }
  .sec-head { flex-wrap: wrap; }
  .sec-title { flex: 1 1 140px; }
  .lnk .btn { display: none; }
  .pw-grid { grid-template-columns: 1fr; }
}
