:root {
  /* Teqnions profil: gult #FDC725, barnsten #FFB116, antracit #3E3E3E. */
  --brand: #fdc725;
  --brand-dark: #e8b113;
  --brand-ink: #1f2226;          /* text pa gult */
  --bg: #f0f4f7;
  --surface: #ffffff;
  --surface-2: #f4f7fa;
  --border: #dde3ea;
  --text: #3e3e3e;
  --heading: #2b2e31;
  --muted: #777777;
  --accent: #9c6207;             /* lankar: morkad barnsten, lasbar pa vitt */
  --accent-soft: #fdf4dd;
  --ok: #2e7d32;
  --ok-soft: #e8f3e9;
  --warn: #9a6a00;
  --warn-soft: #fdf3dc;
  --danger: #b3261e;
  --danger-soft: #fbeae9;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(31, 34, 38, .07), 0 6px 20px rgba(31, 34, 38, .07);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #fdc725;
    --brand-dark: #e8b113;
    --brand-ink: #1f2226;
    --bg: #16181b;
    --surface: #1e2125;
    --surface-2: #24282d;
    --border: #31363c;
    --text: #e6e8ea;
    --heading: #f3f4f5;
    --muted: #a0a5ad;
    --accent: #ffb116;
    --accent-soft: #332a12;
    --ok: #6cc073;
    --ok-soft: #1b2a1c;
    --warn: #e0a84e;
    --warn-soft: #2f2611;
    --danger: #ef8880;
    --danger-soft: #331d1b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 6px 20px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 "Open Sans", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

header.top {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 24px;
  height: 64px;
  background: var(--brand);
  border-bottom: 1px solid var(--brand-dark);
  position: sticky;
  top: 0;
  z-index: 40;
}

header.top .brand { display: flex; align-items: center; text-decoration: none; }
header.top .brand img { height: 30px; width: auto; display: block; }
header.top nav { display: flex; align-items: center; gap: 20px; margin-left: auto; font-size: 14px; }
header.top nav a { color: var(--brand-ink); text-decoration: none; opacity: .78; font-weight: 600; }
header.top nav a:hover { opacity: 1; }
header.top nav .who {
  color: var(--brand-ink);
  font-weight: 700;
  padding-left: 18px;
  border-left: 1px solid rgba(31, 34, 38, .22);
}
button.linkish {
  border: none;
  background: none;
  padding: 0;
  color: var(--brand-ink);
  font: inherit;
  font-weight: 600;
  opacity: .78;
  cursor: pointer;
}
button.linkish:hover { opacity: 1; }

main { max-width: 1120px; margin: 0 auto; padding: 28px 24px 80px; }
main.wide { max-width: 1400px; }

h1 { font-size: 25px; font-weight: 700; letter-spacing: -.3px; color: var(--heading); margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 700; color: var(--heading); margin: 0 0 12px; }
p.sub { color: var(--muted); margin: 0 0 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; align-items: start; }

label.field { display: block; margin-bottom: 14px; }
label.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }

input[type="text"], input[type="email"], input[type="password"], input[type="file"], textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  background: var(--surface);
}

textarea { min-height: 72px; resize: vertical; }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}

button:hover, .btn:hover { border-color: var(--muted); }

.btn-primary, button.primary {
  background: var(--brand);
  border-color: var(--brand-dark);
  color: var(--brand-ink);
  font-weight: 700;
}
.btn-primary:hover, button.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 6px 11px; font-size: 13px; }

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.pill.draft { background: var(--surface-2); color: var(--muted); }
.pill.sent { background: var(--warn-soft); color: var(--warn); }
.pill.completed { background: var(--ok-soft); color: var(--ok); }
.pill.declined, .pill.cancelled { background: var(--danger-soft); color: var(--danger); }

table.docs { width: 100%; border-collapse: collapse; }
table.docs th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 0 12px 9px;
  font-weight: 600;
}
table.docs td { padding: 13px 12px; border-top: 1px solid var(--border); vertical-align: middle; }
table.docs tr:hover td { background: var(--surface-2); }
table.docs a.title { font-weight: 600; color: var(--text); text-decoration: none; }
table.docs a.title:hover { color: var(--accent); }
/* Min egen roll i ett dokument, i listan. */
.roll {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}
.roll.signerat { background: var(--ok-soft); color: var(--ok); }
.roll.vantar { background: var(--warn-soft); color: var(--warn); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: "Cascadia Code", Consolas, "SF Mono", monospace; font-size: 12px; word-break: break-all; }

.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 18px; font-size: 14px; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--danger-soft); color: var(--danger); }

.empty { text-align: center; padding: 46px 20px; color: var(--muted); }

/* ------------------------------------------------------------- filterrad */

.filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 14px;
}
.filterbar label { display: flex; flex-direction: column; gap: 4px; }
.filterbar label span {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 700;
}
.filterbar select {
  width: auto;
  min-width: 150px;
  padding: 7px 10px;
  font-size: 13.5px;
  background: var(--surface);
}
.filterbar .clear {
  font-size: 13px;
  color: var(--muted);
  text-decoration: underline;
  padding-bottom: 9px;
}
.filterbar .clear:hover { color: var(--text); }

/* ---------------------------------------------------- dokumentvy / sidor */

.pagestack { display: flex; flex-direction: column; gap: 18px; align-items: center; }

.page-wrap {
  position: relative;
  background: var(--surface);
  box-shadow: var(--shadow);
  border-radius: 4px;
  overflow: hidden;
  width: 100%;
}
.page-wrap img { display: block; width: 100%; height: auto; }

.fld {
  position: absolute;
  border: 1.5px dashed var(--fc, var(--accent));
  background: color-mix(in srgb, var(--fc, var(--accent)) 12%, transparent);
  border-radius: 4px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fc, var(--accent));
  overflow: hidden;
  user-select: none;
  text-align: center;
  padding: 2px;
}

.fld .lbl { pointer-events: none; font-weight: 600; white-space: nowrap; }
.fld img { width: 100%; height: 100%; object-fit: contain; }

/* --------------------------------------------------------- förberedelse */

.layout { display: grid; grid-template-columns: 330px 1fr; gap: 22px; align-items: start; }
.sidebar { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 16px; }

/* Tva oberoende rullytor: menyn till vanster, dokumentet till hoger. */
.layout.split {
  align-items: stretch;
  height: calc(100vh - 172px);
  min-height: 420px;
}
.layout.split > .sidebar,
.layout.split > section {
  position: static;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 6px;
}
.layout.split > section { padding-right: 10px; }
.layout.split ::-webkit-scrollbar { width: 10px; }
.layout.split ::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
  border: 3px solid var(--bg);
}
.layout.split ::-webkit-scrollbar-thumb:hover { background: var(--muted); }
body:has(.layout.split) { overflow: hidden; }

.rcp-row {
  display: flex;
  gap: 9px;
  align-items: center;
  margin-bottom: 10px;
  padding: 9px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.rcp-row .dot { width: 11px; height: 11px; border-radius: 50%; flex: 0 0 auto; }
.rcp-row .stack { display: flex; flex-direction: column; gap: 6px; flex: 1 1 auto; min-width: 0; }
.rcp-row input { width: 100%; padding: 8px 10px; font-size: 13.5px; background: var(--surface); }
.rcp-row select.grupp {
  width: 100%;
  padding: 6px 9px;
  font-size: 12.5px;
  background: var(--surface);
}
.rcp-row .rm {
  border: none; background: none; color: var(--muted);
  padding: 2px 4px; font-size: 17px; line-height: 1; flex: 0 0 auto;
}
.rcp-row .rm:hover { color: var(--danger); }

.chip-list { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  cursor: grab;
  background: var(--surface-2);
  user-select: none;
}
.chip:active { cursor: grabbing; }
.chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.fld.editable { cursor: move; }
.fld.selected { border-style: solid; box-shadow: 0 0 0 2px color-mix(in srgb, var(--fc) 40%, transparent); }
.fld .handle {
  position: absolute;
  right: -5px;
  bottom: -5px;
  width: 11px;
  height: 11px;
  background: var(--fc);
  border: 2px solid var(--surface);
  border-radius: 50%;
  cursor: nwse-resize;
}

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

/* Banderoll som alltid syns, oavsett var i sidan man befinner sig. */
.toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translate(-50%, -14px);
  z-index: 200;
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

/* ------------------------------------------------------------ signering */

.signbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.signbar .title { font-weight: 650; }
.signbar .spacer { margin-left: auto; }

.progress-track { width: 110px; height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--ok); transition: width .25s ease; }

/* ------------------------------------------------ guiden i signeringsvyn */

.guide {
  position: fixed;
  z-index: 60;
  max-width: 230px;
  padding: 9px 14px;
  background: var(--brand);
  color: var(--brand-ink);
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.3;
  box-shadow: var(--shadow);
  cursor: pointer;
}

/* Pilen ar en svans pa pratbubblan och pekar mot faltet. */
.guide::after {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
}
.guide[data-riktning="hoger"]::after {
  left: 100%; top: 50%; transform: translateY(-50%);
  border-top: 7px solid transparent; border-bottom: 7px solid transparent;
  border-left: 9px solid var(--brand);
}
.guide[data-riktning="vanster"]::after {
  right: 100%; top: 50%; transform: translateY(-50%);
  border-top: 7px solid transparent; border-bottom: 7px solid transparent;
  border-right: 9px solid var(--brand);
}
.guide[data-riktning="ner"]::after {
  top: 100%; left: 20px;
  border-left: 7px solid transparent; border-right: 7px solid transparent;
  border-top: 9px solid var(--brand);
}
.guide[data-riktning="upp"]::after {
  bottom: 100%; left: 20px;
  border-left: 7px solid transparent; border-right: 7px solid transparent;
  border-bottom: 9px solid var(--brand);
}

.guide[data-riktning="hoger"] { animation: guide-hoger 1.7s ease-in-out infinite; }
.guide[data-riktning="vanster"] { animation: guide-vanster 1.7s ease-in-out infinite; }
.guide[data-riktning="ner"] { animation: guide-ner 1.7s ease-in-out infinite; }
.guide[data-riktning="upp"] { animation: guide-upp 1.7s ease-in-out infinite; }

.guide.klar { background: var(--ok); color: #fff; }
.guide.klar[data-riktning="hoger"]::after { border-left-color: var(--ok); }
.guide.klar[data-riktning="vanster"]::after { border-right-color: var(--ok); }
.guide.klar[data-riktning="ner"]::after { border-top-color: var(--ok); }
.guide.klar[data-riktning="upp"]::after { border-bottom-color: var(--ok); }

@keyframes guide-hoger { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(5px); } }
@keyframes guide-vanster { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(-5px); } }
@keyframes guide-ner { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(5px); } }
@keyframes guide-upp { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

/* Faltet guiden pekar pa. */
.fld.mine.aktiv {
  border-style: solid;
  border-color: var(--brand-dark);
  background: color-mix(in srgb, var(--brand) 30%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 45%, transparent);
}

#finishBtn.redo { box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 45%, transparent); }

@media (prefers-reduced-motion: reduce) {
  .guide { animation: none !important; }
}

.fld.mine { cursor: pointer; border-color: var(--accent); background: var(--accent-soft); }
.fld.mine:hover { filter: brightness(.97); }
.fld.mine.filled { border-style: solid; border-color: var(--ok); background: transparent; }
.fld.other { border-color: var(--border); background: var(--surface-2); color: var(--muted); opacity: .65; }
.fld.other.done { border-style: solid; background: transparent; opacity: .9; color: var(--text); }
.fld input.inline {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  padding: 0 4px;
  font-size: inherit;
  color: var(--text);
}

.consent {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 17px;
  margin-bottom: 18px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.consent input {
  width: 20px;
  height: 20px;
  margin-top: 1px;
  flex: 0 0 auto;
  accent-color: var(--brand-dark);
  cursor: pointer;
}
.consent .steg {
  flex: 0 0 auto;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  background: var(--brand);
  color: var(--brand-ink);
}

/* Innan man kryssat i: rutan ar det enda som ska dra blicken. */
.consent.vantar {
  border-color: var(--brand-dark);
  background: color-mix(in srgb, var(--brand) 14%, var(--surface));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 32%, transparent);
}
.consent.vantar .consent-text strong { color: var(--heading); }

/* Efteråt lugnar den ner sig och blir en kvittering. */
.consent.klar { border-color: var(--ok); background: var(--ok-soft); }
.consent.klar .steg { background: var(--ok); color: #fff; }
.consent.klar .consent-text strong { display: none; }

dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  box-shadow: var(--shadow);
  max-width: 540px;
  width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(10, 12, 18, .5); }
dialog .dlg-head { padding: 16px 20px 0; }
dialog .dlg-body { padding: 16px 20px; }
#confirmBody { white-space: pre-line; }
dialog .dlg-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 9px;
  justify-content: flex-end;
}

.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs button { padding: 7px 13px; font-size: 13px; }
.tabs button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

#padWrap { border: 1px dashed var(--border); border-radius: 8px; background: var(--surface-2); }
#pad { display: block; width: 100%; height: 170px; touch-action: none; cursor: crosshair; }

.font-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.font-option {
  padding: 10px 8px;
  font-size: 21px;
  line-height: 1.25;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.font-option:hover { border-color: var(--muted); }
.font-option.active {
  border-color: var(--brand-dark);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--brand-dark);
}

.typed-preview {
  height: 170px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  font-family: "Segoe Script", "Brush Script MT", "Snell Roundhand", cursive;
  font-size: 46px;
  overflow: hidden;
}

/* --------------------------------------------------------------- status */

.steps { list-style: none; padding: 0; margin: 0; }
.steps li { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.steps li:first-child { border-top: none; }
.steps .marker { width: 9px; height: 9px; border-radius: 50%; margin-top: 7px; flex: 0 0 auto; background: var(--border); }
.steps .marker.done { background: var(--ok); }
.steps .marker.declined { background: var(--danger); }

.link-row { display: flex; gap: 8px; margin-top: 7px; }
.link-row input { font-size: 12px; font-family: "Cascadia Code", Consolas, monospace; }

.audit { list-style: none; padding: 0; margin: 0; font-size: 13.5px; }
.audit li { padding: 9px 0; border-top: 1px solid var(--border); display: flex; gap: 14px; }
.audit li:first-child { border-top: none; }
.audit time { color: var(--muted); font-size: 12.5px; white-space: nowrap; min-width: 160px; }

@media (max-width: 900px) {
  .layout, .grid-2 { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .layout.split { height: auto; display: block; }
  .layout.split > .sidebar, .layout.split > section { overflow: visible; padding-right: 0; }
  body:has(.layout.split) { overflow: auto; }
}
