/* Motboken – gemensamt utseende för cosinusfi.se (domaner/cosinusfi.se.md) */
:root {
  --bg: #fafaf7;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --accent: #2f6f6a;
  --border: #e5e5e0;
  --grid: #ecece7;
  --ok: #1d7a35;
  --warn: #9a6200;
  --bad: #b3261e;
  /* Diagram: ökning och minskning (validerade för färgblindhet mot ljus och mörk yta) */
  --viz-pos: #008a7a;
  --viz-neg: #c4622d;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181a; --panel: #1d2023; --text: #e8e8e3; --muted: #9aa0a6; --accent: #6fb3ab; --border: #2a2d30; --grid: #2a2d30;
    --ok: #7cc78f; --warn: #e0b45c; --bad: #ef8a80;
    --viz-pos: #2fa494; --viz-neg: #d46f35;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html.nav-open { overflow: hidden; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-underline-offset: 2px; }
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 .25em; }
h2 { font-size: 1.25rem; margin: 1.2em 0 .5em; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
h3 { font-size: 1.05rem; margin: 1em 0 .4em; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.loading, .empty { color: var(--muted); font-style: italic; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.warn-text { color: var(--warn); }

/* Layout */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.app-head { border-bottom: 1px solid var(--border); background: var(--panel); position: sticky; top: 0; z-index: 10; }
.app-head-inner { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.appnav { display: flex; align-items: center; gap: 4px 16px; flex-wrap: wrap; flex: 1; }
.appnav a { text-decoration: none; color: var(--text); padding: 6px 2px; }
.appnav a[aria-current="page"] { color: var(--accent); font-weight: 600; border-bottom: 2px solid var(--accent); }
.nav-me { margin-left: auto; display: flex; gap: 12px; align-items: center; }

.app-main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 20px 16px 40px; }
.app-foot { text-align: center; padding: 16px; border-top: 1px solid var(--border); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.eyebrow { margin: 0; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.eyebrow a { color: inherit; }
.toc { margin-bottom: 16px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stile { margin: 0; }
.stat { font-size: 2rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 0 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > label { flex: 1 1 200px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain > li { padding: 6px 0; }

/* Formulär */
form.stack, .stack { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; min-height: 40px; width: 100%; }
label.inline select { width: auto; }
input[type="checkbox"], input[type="radio"] { width: 18px; min-height: 18px; accent-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
.btn, .menu-btn, .add-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px;
  border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 6px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.small { min-height: 32px; padding: 4px 12px; font-size: .9rem; }
.btn.ghost, .menu-btn { background: transparent; color: var(--accent); }
.btn.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn:disabled { opacity: .6; cursor: default; }
.menu-btn { display: none; margin-left: auto; }
.add-btn { width: 40px; padding: 0; font-size: 1.5rem; line-height: 1; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }
.form-msg { color: var(--bad); margin: 0; min-height: 1em; }
.form-msg.ok { color: var(--ok); }
details > summary { cursor: pointer; color: var(--accent); }
details.add-form > summary { display: none; }
details.add-form:not([open]) { display: none; }
details[open] > form, details[open] > div { margin-top: 10px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { flex-direction: row; }
.seg input { position: absolute; opacity: 0; }
.seg span { padding: 4px 12px; border: 1px solid var(--border); border-radius: 999px; color: var(--text); cursor: pointer; }
.seg input:checked + span { border-color: var(--accent); background: var(--accent); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs [role="tab"], .tabs a { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; font: inherit; color: var(--text); text-decoration: none; cursor: pointer; }
.tabs [aria-selected="true"], .tabs a[aria-current="page"] { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .8rem; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: currentColor; }
.badge.warn { color: var(--warn); border-color: currentColor; }
.badge.bad { color: var(--bad); border-color: currentColor; }
.badge.accent { color: var(--accent); border-color: currentColor; }

.error-box { border: 1px solid var(--bad); color: var(--bad); border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; }
.auth-box { max-width: 420px; margin: 40px auto; }

/* Tabeller */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { color: var(--muted); font-weight: 600; font-size: .8rem; white-space: nowrap; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.neg { color: var(--viz-neg); }
td.pos { color: var(--viz-pos); }

/* Produkter */
.prods > li { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; padding: 12px 16px; }
.prod-main { flex: 1 1 300px; }
.prod-edit { flex: 1 1 100%; }
.hits > li { display: flex; gap: 12px; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); }
.hits > li { padding: 6px 0; }
.hit { display: flex; gap: 10px; align-items: baseline; cursor: pointer; }
.hits-bar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin: 12px 0 4px; }
/* Produktbilder (sparade i Supabase Storage). Bilderna har vit bakgrund, så de får en ljus ram i mörkt läge. */
.pimg { width: 48px; height: 64px; object-fit: contain; flex: 0 0 auto; border-radius: 6px; background: #fff; }
.pimg.noimg { display: none; }
.pimg-sm { width: 28px; height: 38px; object-fit: contain; border-radius: 4px; background: #fff; vertical-align: middle; margin-right: 8px; }
.pimg-sm.noimg { display: none; }
.pimg-lg { width: 96px; height: 128px; object-fit: contain; border-radius: 8px; background: #fff; flex: 0 0 auto; }
.pimg-lg.noimg { display: none; }
.prod-head { display: flex; gap: 16px; align-items: flex-start; }
.hours td input[type=time] { width: 9.5em; }
.task-head { display: flex; gap: 8px; flex-wrap: wrap; justify-content: space-between; align-items: baseline; }
.task-head h3 { margin: 0; }
.resolved { border-left: 2px solid var(--accent); padding-left: 10px; margin: 6px 0; }

/* Diagram */
.tchart { position: relative; margin: 0 0 8px; }
.tchart svg { width: 100%; height: auto; display: block; overflow: visible; }
.tchart .grid { stroke: var(--grid); stroke-width: 1; }
.tchart .grid.zero { stroke: var(--muted); }
.tchart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.tchart .endlabel { fill: var(--text); font-weight: 600; font-size: 12px; }
.tchart .line { fill: none; stroke: var(--viz-pos); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.tchart .area { fill: var(--viz-pos); opacity: .1; }
.tchart .dot { fill: var(--viz-pos); stroke: var(--panel); stroke-width: 2; }
.tchart .col.pos { fill: var(--viz-pos); }
.tchart .col.neg { fill: var(--viz-neg); }
.tchart .cross { stroke: var(--muted); stroke-width: 1; }
.tchart .hit { fill: transparent; }
.ttip { position: absolute; top: -6px; background: var(--text); color: var(--bg); font-size: .8rem; padding: 4px 8px; border-radius: 4px; pointer-events: none; white-space: nowrap; }
.spark { width: 120px; height: 28px; }
.spark polyline { fill: none; stroke: var(--viz-pos); stroke-width: 1.5; }

.sbars { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.sbars li { display: grid; grid-template-columns: minmax(80px, 40%) 1fr auto; gap: 8px; align-items: center; font-size: .9rem; }
.sbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sbar-track { display: block; height: 10px; background: var(--grid); border-radius: 0 4px 4px 0; overflow: hidden; }
.sbar-fill { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.sbar-val { font-variant-numeric: tabular-nums; }
.ulist .urow { padding: 10px 0; border-bottom: 1px solid var(--border); }
.urow .uhead, .urow .ufoot { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center; }
.urow .sbar-track { margin: 6px 0; }
.urow.mid .sbar-fill { background: var(--warn); }
.urow.high .sbar-fill { background: var(--bad); }
.uspark { width: 160px; height: 28px; }
.uspark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.uspark .ulim { stroke: var(--bad); stroke-width: 1; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); opacity: 0; transition: .2s; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 6px; z-index: 50; pointer-events: none; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--bad); color: #fff; }

/* Mobilmenyn (efter knappreglerna så att den vinner) */
@media (max-width: 760px) {
  .menu-btn { display: inline-flex; }
  .appnav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; max-height: calc(100vh - 60px); overflow: auto; }
  .appnav.open { display: flex; }
  .nav-me { margin-left: 0; border-top: 1px solid var(--border); padding-top: 8px; }
}
