/* Stash – one stylesheet for the app, the add popup and shared pages. */

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1b2130;
  --muted: #647084;
  --border: #dce1e9;
  --accent: #2f6fed;
  --accent-hover: #2459c9;
  --on-accent: #ffffff;
  --danger: #cf3636;
  --notice: #fff6d6;
  --notice-text: #5c4700;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .22);
  --radius: 10px;
  --tint: 16%;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #13161b;
  --surface: #1c2027;
  --surface-2: #272c36;
  --text: #e7eaf0;
  --muted: #9aa4b5;
  --border: #323946;
  --accent: #5a8dff;
  --accent-hover: #7aa3ff;
  --on-accent: #0c1220;
  --danger: #ff6b6b;
  --notice: #3a3210;
  --notice-text: #f3e2a0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .6);
  --tint: 26%;
  --fav-plate: #dfe3ea;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"], :root:not([data-theme]) {
    --bg: #13161b;
    --surface: #1c2027;
    --surface-2: #272c36;
    --text: #e7eaf0;
    --muted: #9aa4b5;
    --border: #323946;
    --accent: #5a8dff;
    --accent-hover: #7aa3ff;
    --on-accent: #0c1220;
    --danger: #ff6b6b;
    --notice: #3a3210;
    --notice-text: #f3e2a0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .6);
    --tint: 26%;
    --fav-plate: #dfe3ea;
    color-scheme: dark;
  }
}

/* palette for tabs, categories and bookmarks */
.c-red { --c: #d9463f; }
.c-orange { --c: #e07a1f; }
.c-yellow { --c: #c79a00; }
.c-green { --c: #2f9e52; }
.c-teal { --c: #12948a; }
.c-blue { --c: #2f6fed; }
.c-indigo { --c: #5b5bd6; }
.c-purple { --c: #9a4fd0; }
.c-pink { --c: #d6478c; }
.c-gray { --c: #6b7686; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2, h3, p, ul { margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
ul { padding: 0; list-style: none; }
a { color: var(--accent); }
hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; width: 100%; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.block { display: block; }
.grow { flex: 1; }
.pad { padding: 6px 8px; }
.icon { display: inline-flex; vertical-align: middle; }

/* --- controls --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 5px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-quiet { color: var(--danger); margin-right: auto; }
.btn.small { min-height: 28px; padding: 2px 9px; font-size: .85rem; }
.btn.block { display: flex; width: 100%; }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 28px; height: 28px; padding: 0;
  border: 0; border-radius: 6px; background: transparent; color: inherit; cursor: pointer; opacity: .75;
}
.iconbtn:hover { background: color-mix(in srgb, currentColor 14%, transparent); opacity: 1; }

.linklike { border: 0; padding: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; text-align: left; }
.linklike:hover { text-decoration: underline; }
.linklike.muted { color: var(--muted); }
.linklike.small { font-size: .85rem; }

.input {
  width: 100%; min-height: 34px; padding: 5px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea.input { resize: vertical; }
select.input { width: auto; max-width: 100%; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span:first-child { font-size: .85rem; font-weight: 600; color: var(--muted); }
.field--inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.field--inline > span:first-child { font-size: 1rem; font-weight: 400; color: var(--text); }
.check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.check input { margin: 3px 0 0; flex: none; width: 16px; height: 16px; accent-color: var(--accent); }
.indent { margin-left: 24px; }
.form-error { color: var(--danger); font-weight: 500; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row > .input { flex: 1; min-width: 0; }
.notice {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-radius: 8px; background: var(--notice); color: var(--notice-text);
}
.empty { padding: 40px 16px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.plain { display: flex; flex-direction: column; gap: 6px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg > * { flex: 1; }
.seg label { cursor: pointer; }
.seg label input { position: absolute; opacity: 0; pointer-events: none; }
.seg label span, .seg button {
  display: block; padding: 5px 14px; border: 0; background: none; color: var(--text); font: inherit; text-align: center; cursor: pointer;
}
.seg label input:checked + span, .seg button.on { background: var(--accent); color: var(--on-accent); }
.seg label input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.seg--full { display: flex; }
.seg--full button { min-width: 0; padding: 5px 6px; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg--menu { display: flex; }
.seg--menu button { padding: 4px 0; }

.chips { display: contents; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px;
  border: 0; border-radius: 999px; background: var(--surface-2); color: var(--text); font: inherit; font-size: .82rem; white-space: nowrap;
}
.chip button { border: 0; padding: 0 2px; background: none; color: var(--muted); font: inherit; cursor: pointer; }
button.chip { cursor: pointer; }
button.chip:hover { background: color-mix(in srgb, var(--accent) 22%, var(--surface-2)); }
.chip--filter { background: var(--accent); color: var(--on-accent); }
.chip--filter:hover { background: var(--accent-hover) !important; }

.taginput {
  position: relative; display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  min-height: 34px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: text;
}
.taginput:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }
.taginput__field { flex: 1; min-width: 90px; border: 0; outline: 0; background: none; color: var(--text); font: inherit; padding: 2px 4px; }
.suggest {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px);
  display: flex; flex-direction: column; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg);
  max-height: 220px; overflow: auto;
}
.suggest__item { border: 0; border-radius: 6px; padding: 5px 8px; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.suggest__item:hover, .suggest__item.on { background: var(--surface-2); }

.loc { display: flex; flex-direction: column; gap: 8px; }
.loc .seg { align-self: flex-start; }
.loc__dash { display: flex; flex-direction: column; gap: 6px; }
.loc__dash select { flex: 1; min-width: 0; width: 100%; }
.loc__find { position: relative; }

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 22px; height: 22px; padding: 0; border: 2px solid transparent; border-radius: 50%; background: var(--c); cursor: pointer; }
.swatch.c-none { background: linear-gradient(135deg, var(--surface) 44%, var(--danger) 45% 55%, var(--surface) 56%); border-color: var(--border); }
.swatch.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }

.fav { flex: none; width: 16px; height: 16px; border-radius: 3px; }
img.fav { background: var(--fav-plate, transparent); }
.fav--letter {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--muted); font-size: 10px; font-weight: 700;
}
.fav--glyph { color: var(--muted); }

/* --- modal, menu, toast --- */
.modal {
  width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); overflow: visible;
}
.modal.wide { width: min(720px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(10, 14, 22, .5); }
.modal__form { display: flex; flex-direction: column; max-height: calc(100dvh - 26px); }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px 6px 18px; }
.modal__body { padding: 8px 18px 14px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.modal__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }

.menu {
  position: fixed; z-index: 50; min-width: 190px; max-width: 280px; max-height: calc(100dvh - 16px); overflow: auto;
  display: flex; flex-direction: column; padding: 5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg);
}
.menu__item { border: 0; border-radius: 6px; padding: 6px 10px; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.menu__item:hover, .menu__item:focus-visible { background: var(--surface-2); outline: 0; }
.menu__item.danger { color: var(--danger); }
.menu__heading { padding: 6px 10px 2px; font-size: .75rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.menu__custom { padding: 4px 10px 6px; }

.toasts { position: fixed; z-index: 100; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { padding: 9px 16px; border-radius: 999px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg); max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); color: #fff; }

/* --- header --- */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.top__nav { display: flex; gap: 2px; margin-left: 8px; }
.top__link { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; text-decoration: none; }
.top__link:hover { background: var(--surface-2); }
.top__link.active { color: var(--text); background: var(--surface-2); }
.top__username { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; }

.view { padding: 14px 16px 60px; }

/* --- dashboard --- */
.tabsbar { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; flex: 1; min-width: 0; overflow: hidden; }
.tab {
  flex: none; display: inline-flex; align-items: center; gap: 6px; max-width: 260px;
  padding: 7px 14px; border: 1px solid transparent; border-bottom: 0; border-radius: 9px 9px 0 0;
  background: color-mix(in srgb, var(--c, var(--muted)) var(--tint), transparent); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
}
.tab.c-none { background: transparent; }
.tab:hover { background: color-mix(in srgb, var(--c, var(--muted)) 30%, transparent); }
.tab.active { background: var(--c, var(--surface)); color: #fff; border-color: var(--c, var(--border)); }
.tab.active.c-none { color: var(--text); box-shadow: inset 0 3px 0 var(--accent); }
.tab.overflow { display: none; }
.tab__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs.size-s .tab { font-size: .85rem; padding: 5px 10px; }
.tabs.size-l .tab { font-size: 1.15rem; padding: 9px 18px; }
.tabs__more { flex: none; }

.dash__tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.dash__search { flex: 1 1 220px; max-width: 420px; margin-right: auto; }

.columns { display: grid; gap: 14px; align-items: start; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); }
.columns[data-cols="1"] { --cols: 1; }
.columns[data-cols="2"] { --cols: 2; }
.columns[data-cols="3"] { --cols: 3; }
.columns[data-cols="4"] { --cols: 4; }
.columns[data-cols="5"] { --cols: 5; }
.col { display: flex; flex-direction: column; gap: 14px; min-height: 80px; min-width: 0; }

.cat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.cat.flash { outline: 3px solid var(--accent); }
.cat__head {
  display: flex; align-items: center; gap: 2px; padding: 4px 6px 4px 4px;
  background: var(--c, var(--surface-2)); color: var(--text); cursor: grab; user-select: none;
}
.cat:not(.c-none) .cat__head { color: #fff; }
.cat__head--static { padding: 7px 12px; cursor: default; }
.cat__toggle { border: 0; background: none; color: inherit; padding: 4px; cursor: pointer; display: inline-flex; border-radius: 6px; }
.cat__toggle .icon { transition: transform .15s; }
.cat.collapsed .cat__toggle .icon { transform: rotate(-90deg); }
.cat__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .95rem; }
.cat__count { font-size: .8rem; opacity: .75; padding: 0 4px; }
.cat.collapsed .bms { display: none; }

.bms { padding: 4px; min-height: 30px; }
.bms:empty::after { content: attr(data-empty); display: block; padding: 5px 8px; color: var(--muted); font-size: .85rem; }
.bm {
  display: flex; align-items: center; gap: 8px; padding: 1px 2px 1px 8px; border-radius: 6px;
  background: color-mix(in srgb, var(--c, transparent) var(--tint), transparent);
}
.bm.c-none { background: transparent; }
.bm:hover { background: color-mix(in srgb, var(--c, var(--muted)) 24%, transparent); }
.bm__link { flex: 1; min-width: 0; padding: 4px 0; color: var(--text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bm__link:hover { text-decoration: underline; }
.bm__menu { opacity: 0; }
.bm:hover .bm__menu, .bm__menu:focus-visible { opacity: .75; }
@media (hover: none) { .bm__menu { opacity: .5; } }
.sortable-ghost { opacity: .35; }

.results { display: flex; flex-direction: column; gap: 10px; max-width: 900px; }
.results__list { display: flex; flex-direction: column; gap: 2px; }
.results .bm .linklike { flex: none; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .85rem; }

/* --- my bookmarks --- */
.mybm { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 18px; align-items: start; }
.side {
  position: sticky; top: 62px; display: flex; flex-direction: column; gap: 8px;
  max-height: calc(100dvh - 76px); padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.side__head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 4px; }
.side > * { flex: none; }
.side > .taglist { flex: 0 1 auto; overflow: auto; min-height: 120px; }
.tagrow {
  display: flex; width: 100%; gap: 8px; align-items: center; justify-content: space-between;
  padding: 4px 8px; border: 0; border-radius: 6px; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.tagrow:hover { background: var(--surface-2); }
.tagrow.on { background: var(--accent); color: var(--on-accent); }
.tagrow.on .muted { color: inherit; }
.tagrow__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tagrow__n { color: var(--muted); font-size: .8rem; }

.main { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.main__content { display: flex; flex-direction: column; gap: 10px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
.toolbar .mybm__search { flex: 1 1 240px; }
.summary { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 0 12px; }
.summary .check { align-items: center; }
.summary .check input { margin: 0; }
.jobbar, .bulkbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px;
  border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border));
}
.bulkbar { position: sticky; top: 58px; z-index: 5; }
.jobbar progress { width: 160px; }

.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list:empty { display: none; }
.row-bm { display: flex; gap: 10px; align-items: flex-start; padding: 9px 8px 9px 12px; border-bottom: 1px solid var(--border); }
.row-bm:last-child { border-bottom: 0; }
.row-bm.selected { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.row-bm > input, .row-bm > .fav { margin-top: 4px; flex: none; }
.row-bm > input { width: 16px; height: 16px; accent-color: var(--accent); }
.row-bm__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-bm__title { color: var(--text); font-weight: 600; text-decoration: none; overflow-wrap: anywhere; }
.row-bm__title:not(.c-none) { box-shadow: inset 3px 0 var(--c); padding-left: 8px; }
.row-bm__title:hover { text-decoration: underline; }
.row-bm__url { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-bm__notes { font-size: .9rem; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 4.4em; overflow: hidden; }
.row-bm__meta { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: .82rem; margin-top: 2px; }
.more { align-self: center; }

/* --- settings --- */
.settings { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.settings .card { display: flex; flex-direction: column; gap: 12px; }
.settings h3 { margin-top: 6px; }
.bookmarklet {
  display: inline-block; padding: 7px 16px; border-radius: 999px; background: var(--accent); color: var(--on-accent);
  font-weight: 700; text-decoration: none; cursor: grab; box-shadow: var(--shadow);
}
.bookmarklet--plain { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.qr { align-self: center; background: #fff; border-radius: 8px; }
.tablewrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: .8rem; color: var(--muted); }

/* --- sign-in, add popup, shared page --- */
.auth { max-width: 380px; margin: 0 auto; padding: 8vh 16px 40px; display: flex; flex-direction: column; gap: 16px; }
.auth__brand { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.addpage { max-width: 560px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.addpage.done { align-items: center; padding-top: 18vh; text-align: center; }
.done__mark { font-size: 3rem; color: #2f9e52; line-height: 1; }
.batch { max-height: 42vh; overflow: auto; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.batch .check span { min-width: 0; overflow-wrap: anywhere; }
.sharehead { padding: 28px 16px 6px; text-align: center; display: flex; flex-direction: column; gap: 6px; }
.sharefoot { padding: 0 16px 24px; text-align: center; font-size: .85rem; }

/* --- small screens --- */
@media (max-width: 1000px) {
  .columns[data-cols="4"], .columns[data-cols="5"] { --cols: 3; }
}
@media (max-width: 760px) {
  .columns[data-cols] { --cols: 1; }
  .col { min-height: 0; }
  .col:empty { display: none; }
  .mybm { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; max-height: 300px; }
  .top { padding: 8px 10px; gap: 6px; flex-wrap: wrap; }
  .top__nav { margin-left: 0; }
  .top__username { display: none; }
  .view { padding: 10px 10px 60px; }
  .bm__link { padding: 8px 0; }
  .field--inline { flex-direction: column; align-items: stretch; gap: 4px; }
  .bulkbar { top: 0; }
}
