:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --border: #dfe3dc;
  --text: #1b211c;
  --muted: #5f6b62;
  --accent: #1f7a4d;
  --accent-text: #ffffff;
  --accent-soft: #e4f3ea;
  --warn: #9a5b00;
  --warn-soft: #fbf0d9;
  --danger: #a3261f;
  --bubble-me: #1f7a4d;
  --bubble-me-text: #ffffff;
  --bubble-them: #eef1ec;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121512;
    --surface: #1a1f1b;
    --border: #2c342e;
    --text: #e8ece8;
    --muted: #9aa69d;
    --accent: #4cc28a;
    --accent-text: #08130d;
    --accent-soft: #16301f;
    --warn: #f0b955;
    --warn-soft: #33290f;
    --danger: #f08a82;
    --bubble-me: #2f9d68;
    --bubble-me-text: #ffffff;
    --bubble-them: #242b26;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 24px 0 8px; }
p { margin: 0 0 12px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

/* Top */
.top {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}
.top-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a {
  text-decoration: none;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 8px;
}
.nav a.active { background: var(--accent-soft); color: var(--text); }
.who { color: var(--muted); font-size: 0.875rem; text-align: right; }

main { max-width: 880px; margin: 0 auto; padding: 24px 16px 48px; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }

/* Controls */
button, .button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.link { border: 0; background: none; color: var(--muted); padding: 6px 10px; }
button:disabled { opacity: 0.55; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

label { display: block; font-weight: 600; font-size: 0.9rem; margin: 14px 0 4px; }
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
textarea { resize: vertical; min-height: 96px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; }
.error { color: var(--danger); margin: 12px 0 0; }
.actions { margin-top: 18px; display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.login { max-width: 380px; margin: 12vh auto 0; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
}
a.row:hover { border-color: var(--accent); }
.row-title { font-weight: 600; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }

.badge { font-size: 0.8rem; padding: 3px 9px; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; }
.badge.open { background: var(--accent-soft); color: var(--text); }
.badge.escalated { background: var(--warn-soft); color: var(--warn); }
.badge.closed { border-color: var(--border); color: var(--muted); }

/* Samtale */
.thread { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.msg { max-width: 82%; }
.msg .bubble { padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .meta { font-size: 0.78rem; color: var(--muted); margin: 0 6px 2px; }
.msg.me { align-self: flex-end; }
.msg.me .meta { text-align: right; }
.msg.me .bubble { background: var(--bubble-me); color: var(--bubble-me-text); border-bottom-right-radius: 4px; }
.msg.them .bubble { background: var(--bubble-them); border-bottom-left-radius: 4px; }
.msg.system { align-self: center; max-width: 100%; }
.msg.system .bubble { background: none; color: var(--muted); font-size: 0.875rem; padding: 2px 8px; text-align: center; }
.typing { color: var(--muted); font-size: 0.875rem; margin: 0 6px; }

.composer { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.composer textarea { min-height: 64px; border: 0; padding: 4px; }
.composer textarea:focus-visible { outline: none; }
.composer .actions { margin-top: 8px; justify-content: space-between; align-items: center; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius); padding: 10px 14px; margin: 12px 0; }

.section { margin-top: 16px; }
.section h2 { margin-top: 0; }
.section .head { margin-bottom: 4px; align-items: center; }
.notice.ok { background: var(--accent-soft); color: var(--text); }
.group { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 14px; }
.group h3 { font-size: 1rem; margin: 0 0 8px; }
.checks { display: grid; gap: 4px; }
.checks .check { margin: 0; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.inline label { margin: 0; }
.inline select, .inline input { width: auto; flex: 1; min-width: 180px; }
[hidden] { display: none !important; }

@media (max-width: 560px) {
  .msg { max-width: 94%; }
  .head { flex-direction: column; }
}
