/* Handla — delade listor.
   One stylesheet, no framework. Light and dark are both first-class; the
   palette is defined once on :root and only the values change. */

:root {
  color-scheme: light dark;

  --bg:        #F7F5F0;
  --surface:   #FFFFFF;
  --surface-2: #EFEDE7;
  --ink:       #17211D;
  --ink-2:     #5C6B64;
  --line:      #E0DED6;
  --accent:    #165C4A;
  --accent-ink:#FFFFFF;
  --accent-sub:#E3F0EA;
  --danger:    #A8342F;
  --ok:        #2C7A54;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --tap: 48px;

  --pad: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0F1A16;
    --surface:   #17241F;
    --surface-2: #1F2F29;
    --ink:       #E9F0EC;
    --ink-2:     #94A8A0;
    --line:      #26382F;
    --accent:    #7ED9A3;
    --accent-ink:#08150F;
    --accent-sub:#1B3229;
    --danger:    #F08A84;
    --ok:        #7ED9A3;
  }
}
:root[data-theme="dark"] {
  --bg:        #0F1A16;
  --surface:   #17241F;
  --surface-2: #1F2F29;
  --ink:       #E9F0EC;
  --ink-2:     #94A8A0;
  --line:      #26382F;
  --accent:    #7ED9A3;
  --accent-ink:#08150F;
  --accent-sub:#1B3229;
  --danger:    #F08A84;
  --ok:        #7ED9A3;
}

* { box-sizing: border-box; }

/* Every `display` rule below would otherwise beat the hidden attribute, and
   a "hidden" overlay that still swallows taps is a miserable bug to chase. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

svg { fill: currentColor; stroke: none; }
svg [stroke-width] { stroke: currentColor; fill: none; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ------------------------------------------------------------- chrome --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(var(--safe-t) + 8px) var(--pad) 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}

.tabs { display: flex; gap: 6px; align-items: center; }

.tab {
  flex: 1 1 auto;
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: background .15s, color .15s;
}
.tab[aria-current="page"] { background: var(--accent-sub); color: var(--ink); }
.tab-icon { flex: 0 0 auto; width: 42px; padding: 0; display: grid; place-items: center; }

.count {
  display: inline-block;
  min-width: 22px;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}
.count:empty { display: none; }

.netstate {
  margin-top: 8px;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 13px;
  text-align: center;
}
.netstate[data-kind="offline"] { background: #8A5A1220; color: #B4791C; }
:root[data-theme="dark"] .netstate[data-kind="offline"],
:root:not([data-theme="light"]) .netstate[data-kind="offline"] { color: #E8B55A; }

main { padding: var(--pad); padding-bottom: calc(var(--safe-b) + 40px); max-width: 720px; margin: 0 auto; }
.view { animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* -------------------------------------------------------- add field ----- */

.addform { position: relative; display: flex; gap: 8px; margin-bottom: 14px; }

.addinput {
  flex: 1 1 auto;
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  outline-offset: 2px;
}
.addinput::placeholder { color: var(--ink-2); }
.addinput:focus-visible { outline: 2px solid var(--accent); border-color: var(--accent); }
.filter { margin-bottom: 12px; width: 100%; }

.addbtn {
  flex: 0 0 var(--tap);
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--accent-ink);
}
.addbtn:active { transform: scale(.96); }

.suggestions {
  position: absolute;
  top: calc(var(--tap) + 6px);
  left: 0; right: calc(var(--tap) + 8px);
  z-index: 30;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: 0 12px 32px #0002;
  max-height: 46vh;
  overflow-y: auto;
}
.suggestions li { }
.suggestions button {
  display: flex; align-items: center; gap: 8px;
  width: 100%; min-height: 44px; padding: 0 10px;
  border: 0; border-radius: var(--r-sm);
  background: transparent; text-align: left;
}
.suggestions button:hover,
.suggestions li[aria-selected="true"] button { background: var(--surface-2); }
.suggestions .pin { font-size: 12px; color: var(--ink-2); margin-left: auto; }

/* ------------------------------------------------------------- items ---- */

.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 12px 8px 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.item.pending { opacity: .62; }
.item.flash { animation: flash .8s ease-out; }
@keyframes flash {
  from { background: var(--accent-sub); border-color: var(--accent); }
}

.check {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: transparent;
  color: var(--ink-2);
}
.check .box {
  width: 22px; height: 22px;
  border: 2px solid currentColor;
  border-radius: 7px;
}
.item.checked .check { color: var(--ok); }
.item.checked .box { background: currentColor; border-color: currentColor; }
.check svg { position: absolute; width: 16px; height: 16px; color: var(--surface); opacity: 0; }
.item.checked .check svg { opacity: 1; }
.check { position: relative; }

.item-main { flex: 1 1 auto; min-width: 0; }
.item-text {
  display: block;
  overflow-wrap: anywhere;
  font-weight: 500;
}
.item.checked .item-text { text-decoration: line-through; color: var(--ink-2); }
.item-meta { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--ink-2); }
.qty {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  font-variant-numeric: tabular-nums;
}

.who {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

.kill {
  flex: 0 0 auto;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--ink-2);
}
.kill:hover { color: var(--danger); background: var(--surface-2); }

.empty { margin: 40px 0; text-align: center; color: var(--ink-2); }

/* --------------------------------------------------------- avbockade --- */

.done-wrap { margin-top: 22px; }
.done-toggle {
  display: flex; align-items: center; gap: 6px;
  width: 100%; min-height: 44px; padding: 0 4px;
  border: 0; background: transparent; color: var(--ink-2);
  font-weight: 600;
}
.done-toggle .chev { transition: transform .18s; }
.done-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.done { margin-top: 8px; }
.done .item { background: transparent; }

/* ------------------------------------------------------------- cards ---- */

.card {
  margin-bottom: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card h4 { margin: 18px 0 6px; font-size: 14px; color: var(--ink-2); }
.card label { display: block; margin: 10px 0 6px; font-size: 13px; color: var(--ink-2); }
.card .addinput { width: 100%; }
.muted { color: var(--ink-2); font-size: 14px; }
.lede { margin: 0; color: var(--ink-2); }
.lede-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.lede-row .lede { flex: 1 1 auto; }

.linkbtn {
  flex: 0 0 auto;
  min-height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--ink-2);
  font-size: 14px; font-weight: 600;
}
.linkbtn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

.inline { display: flex; gap: 8px; align-items: center; }
.inline .addinput { flex: 1 1 auto; min-width: 0; }

.btn {
  min-height: var(--tap);
  margin-top: 10px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
  font-weight: 600;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-quiet { background: transparent; color: var(--ink-2); width: 100%; }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn:active { transform: scale(.985); }

.seg { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: var(--r-md); }
.seg-btn {
  flex: 1; min-height: 40px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--ink-2); font-weight: 600;
}
.seg-btn[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px #0001; }

.devices { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.devices li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-md);
}
.devices .grow { flex: 1 1 auto; min-width: 0; }
.devices small { display: block; color: var(--ink-2); font-size: 12px; }
.devices .revoked { opacity: .5; }
.invite-out { margin-top: 12px; }

/* ---------------------------------------------------------- basvaror --- */

.staples { display: grid; gap: 18px; margin-bottom: 20px; }
.staple-group h4 { margin: 0 0 8px; font-size: 13px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .06em; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-weight: 500;
}
.chip:active { transform: scale(.96); }
.chip[data-on="1"] { background: var(--accent-sub); border-color: var(--accent); color: var(--ink); }
.chip[data-on="1"]::before { content: "✓"; color: var(--ok); font-weight: 700; }
.staples:not([data-edit="1"]) .chip .x { display: none; }
.staples[data-edit="1"] .chip { border-style: dashed; }

.chip .x {
  margin: 0 -8px 0 2px; width: 28px; height: 28px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink-2);
  font-size: 18px; line-height: 1;
}

/* -------------------------------------------------------------- gate ---- */

.gate {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: var(--pad);
  background: var(--bg);
}
.gate-card {
  width: min(420px, 100%);
  padding: 28px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  text-align: center;
}
.gate-card img { border-radius: 18px; }
.gate-card h1 { margin: 12px 0 6px; font-size: 24px; }
.gate-card p { color: var(--ink-2); }
.gate-card .btn { width: 100%; }
.gate-card label { display: block; margin: 18px 0 6px; font-size: 13px; color: var(--ink-2); text-align: left; }
.gate-card .addinput { width: 100%; }
.gate-hint { margin-top: 18px; font-size: 13px; }

/* ------------------------------------------------------------- toast ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 20px);
  transform: translate(-50%, 8px);
  z-index: 90;
  max-width: min(90vw, 420px);
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  box-shadow: 0 10px 30px #00000030;
  opacity: 0;
  transition: opacity .18s, transform .18s;
  pointer-events: none;
}
.toast[data-show="1"] { opacity: 1; transform: translate(-50%, 0); }
