:root {
  --bg: #101214;
  --surface: #191d21;
  --surface-2: #232930;
  --line: #2f363e;
  --text: #eef1f4;
  --muted: #9aa5b1;
  --accent: #ffb300;
  --accent-ink: #221a00;
  --danger: #ff6b5e;
  --ok: #4ade80;
  --tap: 48px;
  --pad: 14px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior-y: none;
}

h1 { font-size: 18px; margin: 0; letter-spacing: .2px; white-space: nowrap; }
h2 { font-size: 20px; margin: 0 0 12px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .85em; }

/* ---------- header ---------- */

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px var(--pad);
}

#menu {
  flex: 0 0 auto;
  width: 48px;
  min-height: 48px;
  font-size: 17px;
  letter-spacing: 1px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}

#search {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  font-size: 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 11px;
}

#filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px var(--pad) 10px;
  scrollbar-width: none;
}
#filters::-webkit-scrollbar { display: none; }

#filters button {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 14px;
  font-size: 15px;
  white-space: nowrap;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 22px;
}

#filters button b { color: var(--text); font-weight: 700; }

#filters button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
#filters button[aria-pressed="true"] b { color: var(--accent-ink); }

#filters button.nudge[aria-pressed="false"] { border-color: #6b4a12; color: var(--accent); }

/* ---------- list ---------- */

main { padding: 10px var(--pad) calc(84px + env(safe-area-inset-bottom)); }

#empty { color: var(--muted); text-align: center; padding: 40px 0; }

#list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.shop {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
  overflow: hidden;
}

.shop.flagged { border-left: 4px solid var(--accent); }

.head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 62px;
  padding: 10px var(--pad);
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
}

.head .who { flex: 1; min-width: 0; }

/* One row per shop, always two lines exactly - a wrapping list is hard to
   scan with a thumb while standing up. */
.head .name {
  display: block;
  font-weight: 600;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.head .sub {
  display: block;
  color: var(--muted);
  font-size: 14px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.head .sub .warn { color: var(--accent); }

.dot { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 auto; }
.dot.s-not_contacted { background: #4d5761; }
.dot.s-sent { background: #6aa2ff; }
.dot.s-replied { background: var(--accent); }
.dot.s-agreement { background: var(--ok); }

.chev { color: var(--muted); font-size: 13px; }

.body { padding: 0 var(--pad) var(--pad); display: grid; gap: 12px; border-top: 1px solid var(--line); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 12px; }

.actions a, .actions button {
  flex: 1 1 calc(50% - 4px);
  min-height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 10px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1;
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
}

/* Kopiera är en gång per sittning - texten är densamma för alla - så den ska
   inte skrika högre än det man gör vid varje butik. */
.actions .quiet {
  flex-basis: 100%;
  font-weight: 400;
  color: var(--muted);
  background: none;
}

/* Frågan efter "Skickat" */
.picker { display: grid; gap: 10px; padding-top: 12px; }
.picker-q { margin: 0; font-size: 15px; font-weight: 600; }
.picker-ways { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.picker-ways button {
  min-height: 54px;
  padding: 0 8px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.picker-ways button:last-child:nth-child(odd) { grid-column: 1 / -1; }
.picker-ways button.likely { border-color: var(--accent); color: var(--accent); }

/* "Skickat" är det man trycker vid varje butik - då ska den synas mest. */
.body > .big.done { margin-top: 2px; }

.actions a, .actions button { white-space: nowrap; }

.details {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  overflow-wrap: anywhere;
  user-select: text;
}

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }

select, input, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%239aa5b1' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 11px;
  padding-right: 32px;
}

textarea { min-height: 84px; resize: vertical; line-height: 1.4; }

input[type="date"] { min-height: var(--tap); }

.row-end { display: flex; justify-content: flex-end; }

.link-danger {
  min-height: 44px;
  padding: 0 12px;
  font-size: 14px;
  color: var(--danger);
  background: none;
  border: 1px solid transparent;
  border-radius: 9px;
}

/* ---------- dialogs ---------- */

dialog {
  width: min(560px, calc(100vw - 24px));
  margin: auto;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
}
dialog::backdrop { background: rgba(0, 0, 0, .65); }
dialog > * { padding: 18px var(--pad) 0; display: grid; gap: 12px; max-height: 88vh; overflow-y: auto; }

/* Spara ska nås utan att scrolla förbi hela formuläret först. */
dialog menu {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  margin: 4px 0 0;
  padding: 10px 0 var(--pad);
  list-style: none;
  background: var(--surface);
  box-shadow: 0 -12px 16px -12px rgba(0, 0, 0, .8);
}

dialog menu button {
  flex: 1;
  min-height: var(--tap);
  font-family: inherit;
  font-size: 16px;
  line-height: 1;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
}
dialog menu button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.hint { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.5; }

/* ---------- stats ---------- */

.stat { display: flex; align-items: baseline; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.stat .ch { flex: 1; font-weight: 600; }
.stat .rate { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); }
.stat .of { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .5);
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { border-color: var(--danger); color: var(--danger); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- kontaktvägs-filter och startknappar ---------- */

#channels {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 var(--pad) 10px;
  scrollbar-width: none;
}
#channels::-webkit-scrollbar { display: none; }

#channels button {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 13px;
  font-size: 14px;
  white-space: nowrap;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
}
#channels button b { color: var(--text); font-weight: 700; }
#channels button[aria-pressed="true"] {
  background: var(--surface-2);
  border-color: var(--accent);
  color: var(--accent);
}
#channels button[aria-pressed="true"] b { color: var(--accent); }

/* Huvudknappen sitter längst ner: en tumme når skärmens underkant utan att
   greppet flyttas, toppen når den inte. */
#bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  gap: 8px;
  padding: 8px var(--pad) calc(8px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}

#bottom button {
  flex: 1;
  min-height: 52px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.15;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
#bottom button.primary { flex: 1.4; background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#bottom button:disabled { opacity: .4; }

body.grinding > #bottom { display: none; }

/* Menyn: fulla rader i stället för knappar i bredd. */
dialog menu.stack { flex-direction: column; }
dialog menu.stack button { min-height: 54px; font-weight: 600; }

/* ---------- betningsläget ---------- */

body.grinding { overflow: hidden; }
body.grinding > header, body.grinding > main { display: none; }

/* display:flex nedan slår ut hidden-attributet om man inte säger ifrån - då
   ligger ett osynligt lager över hela skärmen och äter alla tryck. */
#grind[hidden] { display: none; }

#grind {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.grind-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px var(--pad);
  border-bottom: 1px solid var(--line);
}

.grind-bar button {
  min-height: 44px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

#grind-count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

#grind-card {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px var(--pad) 24px;
}

#grind-card h2 { margin: 0; font-size: 25px; line-height: 1.15; }
#grind-card .where { margin: 0; color: var(--muted); font-size: 15px; }

/* Meddelandet får aldrig trycka ner "Skickat" under skärmkanten - hela poängen
   är att kunna beta av utan att scrolla. Långa mallar scrollar i sin egen ruta. */
.msg-wrap {
  position: relative;
  display: flex;
  min-height: 0;
}

/* Toning i nederkant när texten fortsätter nedanför - annars ser den kapade
   raden ut som ett renderingsfel i stället för något man kan scrolla. */
.msg-wrap.more::after {
  content: '';
  position: absolute;
  left: 1px;
  right: 1px;
  bottom: 1px;
  height: 38px;
  border-radius: 0 0 12px 12px;
  background: linear-gradient(to bottom, transparent, var(--surface));
  pointer-events: none;
}

.msg {
  flex: 1;
  margin: 0;
  min-height: 0;
  max-height: 30vh;
  overflow-y: auto;
  padding: 14px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  user-select: text;
}

.grind-actions, .grind-mark { display: grid; gap: 8px; }
.grind-mark { margin-top: auto; padding-top: 8px; }

.big {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 17px;
  line-height: 1.2;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 13px;
}
.big.go { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.big.done { background: #1d6b3f; border-color: #26824d; color: #eafff1; }

.others { display: flex; gap: 8px; }

.others button, .others a {
  flex: 1;
  min-height: var(--tap);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 15px;
  line-height: 1;
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
}

.link-quiet {
  min-height: 44px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 0;
  text-decoration: underline;
}

/* ---------- massmejl ---------- */

.mass-group { padding: 12px 0; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.mass-head { display: flex; align-items: baseline; gap: 10px; }
.mass-head .of { color: var(--muted); font-size: 13px; }
.mass-names {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.mass-open { background: var(--accent) !important; color: var(--accent-ink) !important; border-color: var(--accent) !important; }

/* ---------- rättelser bakom en lucka ---------- */

.fix { border-top: 1px solid var(--line); padding-top: 10px; }

.fix summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.fix summary::-webkit-details-marker { display: none; }
.fix summary::before { content: '▸ '; margin-right: 6px; }
.fix[open] summary::before { content: '▾ '; }
.fix[open] { display: grid; gap: 12px; }
