/* Insyn: Chatt · Kort · Tavlor. Builds on app.css (tokens, buttons, cards, charts, dialogs).
   Always light, Hyllkoll red/ink/paper, no dark mode. */
body { border-top: 4px solid var(--red); }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }

/* ---------- shell: sidebar + main ---------- */
.shell { display: grid; grid-template-columns: 268px minmax(0, 1fr); min-height: calc(100vh - 4px); }
.side { background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; position: sticky; top: 0; height: calc(100vh - 4px); }
.side-head { padding: 16px 16px 10px; display: flex; align-items: center; justify-content: space-between; }
.side-scroll { flex: 1; overflow: auto; padding: 4px 10px 16px; }
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-main { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 10px; text-decoration: none; color: var(--ink-2); font-size: 15px; font-weight: 600; }
.nav-main:hover { background: var(--hover); color: var(--ink); }
.nav-main.on { background: var(--panel2); color: var(--ink); }
.nav-main .t { flex: 1; min-width: 0; }
.nav-main .count { font-size: 12px; color: var(--muted); }
.nav-ic { display: inline-flex; color: var(--muted); }
.nav-ic svg { width: 20px; height: 20px; }
.nav-main.on .nav-ic { color: var(--red); }
.nav-group { margin-top: 22px; }
.nav-label { font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); padding: 0 10px 6px; }
.side-foot { border-top: 1px solid var(--line); padding: 12px 16px; font-size: 13px; color: var(--ink-2); display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 10px 20px; min-height: 56px; flex-wrap: wrap; }
.topbar .grow { flex: 1; }
.topbar select { min-height: 34px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); font-size: 13px; font-weight: 600; }
.topbar label { font-size: 13px; color: var(--muted); }
.menu-btn { display: none; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- home: the search box ---------- */
.home { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px 12vh; gap: 18px; }
.hello { color: var(--muted); font-size: 16px; margin: 0; }
.home h1 { font-size: clamp(30px, 4.4vw, 46px); font-weight: 800; text-align: center; }
.searchbox { width: min(720px, 100%); display: flex; align-items: flex-end; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 28px; padding: 8px 8px 8px 22px; box-shadow: 0 2px 6px rgba(20,20,20,.05), 0 10px 32px rgba(20,20,20,.06); }
.searchbox:focus-within { border-color: var(--ink-2); }
.searchbox textarea { flex: 1; border: 0; outline: 0; resize: none; background: transparent; font: inherit; font-size: 17px; line-height: 1.45; padding: 9px 0; max-height: 180px; min-height: 26px; }
.send { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--red); color: #fff; cursor: pointer; display: grid; place-items: center; flex-shrink: 0; }
.send:hover { background: var(--red-ink); }
.send[disabled] { background: var(--panel2); color: var(--muted); cursor: default; }
.send.stop { background: var(--ink); }
.send svg { width: 18px; height: 18px; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; width: min(760px, 100%); }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 14px; font-size: 13.5px; color: var(--ink-2); cursor: pointer; text-align: left; }
.chip:hover { border-color: var(--ink-2); color: var(--ink); }
.home .fine { font-size: 12.5px; color: var(--muted); text-align: center; margin: 0; max-width: 560px; }
.recent { width: min(720px, 100%); margin-top: 10px; }
.recent-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 6px 6px; }
.recent-head h2 { font: 700 11px/1.4 Inter, sans-serif; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.recent-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.recent-item { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 11px 6px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.recent-item:hover { background: var(--hover); }
.ri-title { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ri-meta { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* ---------- chat ---------- */
.thread { width: min(840px, 100%); margin: 0 auto; padding: 8px 16px 24px; display: grid; gap: 22px; flex: 1; align-content: start; }
.msg-user { justify-self: end; max-width: 78%; background: var(--panel2); border-radius: 18px 18px 4px 18px; padding: 10px 16px; font-size: 15.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-ai { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 12px; align-items: start; }
.avatar { width: 30px; height: 30px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; }
.avatar svg { width: 15px; height: 16px; }
.ai-body { display: grid; gap: 12px; min-width: 0; }
.working { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--ink-2); }
.spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13.5px; color: var(--ink-2); }
.steps li { display: flex; gap: 10px; align-items: flex-start; }
.steps .ic { width: 14px; height: 14px; margin-top: 3px; flex-shrink: 0; display: grid; place-items: center; }
.steps .ok { color: var(--ink); font-size: 12px; font-weight: 700; line-height: 14px; }
.steps .gb { color: var(--muted); }
details.how { font-size: 13px; color: var(--muted); }
details.how summary { cursor: pointer; width: fit-content; }
details.how .steps { margin-top: 8px; }
.ans-text { font-size: 15.5px; line-height: 1.6; margin: 0; }
.ans-text b { font-weight: 700; }
.ans-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.gpill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.gpill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.gpill.tunn::before { background: var(--warn); }
.gpill.skicka::before { background: transparent; border: 1.5px solid var(--red); width: 7px; height: 7px; }
.ai-body .basis { font-size: 13px; color: var(--muted); margin: 0; }
.caveats { margin: 0; padding-left: 18px; font-size: 13px; color: var(--ink-2); display: grid; gap: 2px; }
.data-block { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px 12px; display: grid; gap: 8px; }
.data-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.data-head h4 { margin: 0; font-size: 14px; font-weight: 700; }
.data-box { position: relative; height: 250px; }
.data-box.tbl { height: auto; max-height: 300px; overflow: auto; }
.data-box > .vis-target { position: absolute; inset: 0; display: flex; flex-direction: column; }
.data-box.tbl > .vis-target { position: static; }
.data-box .ins-table-wrap { height: auto; }
.ans-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-make { border-color: var(--red); color: var(--red); }
.btn-make:hover { background: var(--red); color: #fff; }
.btn-sm { min-height: 32px; padding: 5px 12px; font-size: 13px; }
pre.sql { margin: 0; background: var(--page); border: 1px solid var(--line); border-radius: 8px; padding: 12px; font: 12.5px/1.55 "JetBrains Mono", ui-monospace, monospace; overflow: auto; white-space: pre; }
.followups { display: flex; gap: 8px; flex-wrap: wrap; }
.followups .chip { font-size: 13px; padding: 6px 12px; }

/* ---------- composer (bottom), with the rotating questions while an answer is made ---------- */
.composer-wrap { position: sticky; bottom: 0; background: linear-gradient(to top, var(--page) 70%, rgba(246,246,244,0)); padding: 14px 16px 16px; }
.composer-in { width: min(840px, 100%); margin: 0 auto; display: grid; gap: 6px; }
.composer-hint { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); padding: 0 18px; min-height: 18px; }
.composer-hint kbd { font: inherit; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; background: var(--card); }
.composer { position: relative; display: flex; align-items: flex-end; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 26px; padding: 6px 6px 6px 20px; box-shadow: 0 2px 6px rgba(20,20,20,.05), 0 10px 28px rgba(20,20,20,.05); }
.composer:focus-within { border-color: var(--ink-2); }
.composer textarea { flex: 1; border: 0; outline: 0; resize: none; background: transparent; font: inherit; font-size: 15.5px; line-height: 1.45; padding: 9px 0; max-height: 160px; min-height: 24px; position: relative; z-index: 1; }
.ghost { position: absolute; left: 20px; right: 58px; top: 15px; font-size: 15.5px; line-height: 1.45; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: text; transition: opacity .35s; z-index: 2; }
.ghost.fade { opacity: 0; }
.ghost .use { color: var(--ink-2); font-weight: 600; }

/* ---------- visual picker (Gör till kort) ---------- */
.dlg > *, .make-grid > * { min-width: 0; }
dialog select, dialog input[type="text"] { max-width: 100%; }
.make-grid { display: grid; grid-template-columns: minmax(0, 330px) minmax(0, 1fr); gap: 18px; }
.vis-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.vis-tile { position: relative; border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: 10px 8px 8px; cursor: pointer; display: grid; justify-items: center; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.vis-tile svg { width: 34px; height: 24px; }
.vis-tile:hover { border-color: var(--ink-2); }
.vis-tile[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); color: var(--ink); }
.vis-tile[disabled] { opacity: .4; cursor: not-allowed; }
.vis-tile .tag { position: absolute; top: -8px; right: 6px; font-size: 10px; font-weight: 700; letter-spacing: .04em; background: var(--red); color: #fff; border-radius: 999px; padding: 1px 6px; }
.chk { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; color: var(--ink-2); }
.chk input { margin-top: 3px; accent-color: var(--ink); }
.make-preview { border: 1px solid var(--line); border-radius: var(--radius); background: var(--page); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.make-preview .card { flex: 1; min-height: 300px; }   /* the card fills the preview, so a table shows its rows */

/* ---------- Kort (saved cards) ---------- */
.page-wrap { width: min(1180px, 100%); margin: 0 auto; padding: 8px 20px 64px; }
.page-wrap > .page-head { margin-top: 6px; }
.lead2 { color: var(--ink-2); margin: -10px 0 18px; max-width: 720px; }
.wlist { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.wlist button.witem { width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; cursor: pointer; box-shadow: var(--shadow); display: grid; gap: 8px; }
.wlist button.witem:hover { border-color: var(--ink-2); }
.witem .row1 { display: flex; align-items: center; gap: 10px; }
.witem .row1 svg { width: 30px; height: 22px; flex-shrink: 0; }
.witem h3 { font-size: 15.5px; font-weight: 700; flex: 1; min-width: 0; }
.witem .meta { font-size: 12.5px; color: var(--muted); }
.spill { display: inline-flex; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }
.spill.ogranskat { border-color: var(--warn); color: var(--warn); }
.spill.kontrollerat { border-color: var(--ink); color: var(--ink); }
.spill.ny { border-color: var(--red); color: var(--red); }
.wdetail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: 16px; align-items: start; }
.wdetail .card { min-height: 360px; }
.side-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 10px; font-size: 14px; }
.side-box h3 { font-size: 14px; font-family: Inter, sans-serif; font-weight: 700; color: var(--ink-2); }
.side-box .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.builder { display: grid; gap: 12px; }
.builder textarea.sqlbox { width: 100%; min-height: 220px; border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: var(--card); font: 13px/1.55 "JetBrains Mono", ui-monospace, monospace; resize: vertical; }
.builder .ask-row { display: flex; gap: 8px; flex-wrap: wrap; }
.builder .ask-row input { flex: 1 1 320px; min-height: 42px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
.run-meta { font-size: 13px; color: var(--muted); }
.result-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; max-height: 340px; overflow: auto; }

/* ---------- Tavlor (boards) ---------- */
.board-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-rows: 92px; gap: 12px; grid-auto-flow: dense; }
.board-grid .card { grid-column: span 6; grid-row: span 4; min-width: 0; }
.board-grid .card.w3 { grid-column: span 3; } .board-grid .card.w4 { grid-column: span 4; } .board-grid .card.w8 { grid-column: span 8; } .board-grid .card.w12 { grid-column: span 12; }
.board-grid .card.h2 { grid-row: span 2; } .board-grid .card.h3 { grid-row: span 3; } .board-grid .card.h5 { grid-row: span 5; }
.card { min-width: 0; }
.card-foot .basis { min-width: 0; }
.make-preview > * { min-width: 0; }
.card.fresh { animation: fresh 2.4s ease-out; }
@keyframes fresh { 0%, 30% { box-shadow: 0 0 0 3px var(--red); } 100% { box-shadow: var(--shadow); } }
.card .card-chart { inset: 4px 14px 0; }
.card-body.scroll { overflow: auto; }
/* Nyckeltal = a small scorecard (Looker Studio style): name, number, change, grade + basis.
   The number scales with the card (container units), so a bigger card on a tavla gets a bigger number. */
.card.scorecard { padding: 12px 16px 10px; gap: 2px; container-type: size; }
.sc-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.sc-label { font-size: 13px; font-weight: 600; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.sc-head .spill { font-size: 10.5px; padding: 1px 6px; flex-shrink: 0; }
.sc-body { flex: 1; min-height: 0; }
.card.scorecard .ins-kpi { justify-content: center; gap: 3px; height: 100%; }
.card.scorecard .ins-kpi-value { font-family: "Inter Tight", Inter, system-ui, sans-serif; font-weight: 800; font-size: clamp(26px, min(24cqh, 17cqw), 96px); line-height: 1.02; letter-spacing: -.02em; }
.sc-delta { font-size: 12.5px; font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sc-delta.bad { color: var(--red); }
.sc-delta.sc-none { visibility: hidden; }
.card.scorecard .ins-kpi-compare { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-foot { display: flex; align-items: center; gap: 6px; min-width: 0; padding-top: 7px; margin-top: 2px; border-top: 1px solid var(--line); font-size: 11.5px; color: var(--muted); }
.sc-foot .grade { font-size: 11.5px; flex-shrink: 0; }
.sc-foot .basis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.make-preview .card.scorecard { flex: 0 0 auto; width: 300px; height: 176px; min-height: 0; margin: 28px auto 0; }
.wdetail .card.scorecard { min-height: 0; width: min(320px, 100%); height: 184px; }
/* type icons: the same five as the "Visa som" tiles */
.vicon { display: inline-flex; flex-shrink: 0; }
.vicon svg { width: 34px; height: 24px; display: block; }
.vicon.sm svg { width: 20px; height: 14px; }
.vis-grid.compact { gap: 6px; }
.vis-grid.compact .vis-tile { padding: 8px 4px 6px; font-size: 12px; }
.vis-grid.compact .vis-tile svg { width: 28px; height: 20px; }
.vis-grid.compact .vis-tile .tag { top: -7px; right: 4px; font-size: 9px; }
/* "Lägg till kort": the cards as tiles, each with its type */
.cardpick { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.cardpick li { display: flex; }
.cardpick-tile { width: 100%; text-align: left; display: grid; gap: 8px; align-content: start; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; cursor: pointer; }
.cardpick-tile:hover { border-color: var(--ink-2); }
.cardpick-tile .vicon { color: var(--ink-2); }
.cardpick-name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.cardpick-meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--muted); margin-top: auto; }
.board-empty { grid-column: 1 / -1; grid-row: span 3; display: grid; place-items: center; text-align: center; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); padding: 24px; color: var(--ink-2); }
.board-empty .actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.boards li button.bitem { width: 100%; text-align: left; display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); cursor: pointer; }
.boards li button.bitem:hover { border-color: var(--ink-2); }
.boards li button.bnew { border-style: dashed; box-shadow: none; color: var(--ink-2); font-weight: 600; min-height: 100%; }

/* ---------- line chart (insyn-line.js) ---------- */
.ml-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ml-line.ml-own { stroke: var(--own); }
.ml-line.ml-other { stroke: var(--other); }
.ml-dot { stroke: var(--card); stroke-width: 2; }
.ml-dot.ml-own { fill: var(--own); }
.ml-dot.ml-other { fill: var(--other); }
.ml-cross { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; pointer-events: none; }
.ml-key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; flex-shrink: 0; }
.ml-key-own { background: var(--own); }
.ml-key-other { background: var(--other); }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--card); border-radius: 999px; padding: 10px 12px 10px 18px; font-size: 14px; display: flex; gap: 12px; align-items: center; box-shadow: 0 10px 30px rgba(20,20,20,.18); z-index: 50; max-width: calc(100vw - 32px); }
.toast button { border: 0; background: var(--card); color: var(--ink); border-radius: 999px; padding: 5px 12px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- phone / small screens ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); z-index: 40; transform: translateX(-102%); transition: transform .2s; height: 100vh; box-shadow: 0 0 40px rgba(20,20,20,.12); }
  .menu-open .side { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(246,246,244,.75); z-index: 39; display: none; }
  .menu-open .scrim { display: block; }
  .menu-btn { display: inline-flex; margin-right: auto; }
  .topbar { padding: 8px 16px; justify-content: flex-end; gap: 8px; }
  .topbar label { display: none; }
  .topbar select { max-width: 60vw; }
  .searchbox textarea { font-size: 16px; }
  .make-grid, .wdetail { grid-template-columns: minmax(0, 1fr); }
  .vis-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .board-grid { grid-template-columns: 1fr; grid-auto-rows: auto; }
  .board-grid .card, .board-grid .card.w3, .board-grid .card.w4, .board-grid .card.w8, .board-grid .card.w12 { grid-column: 1 / -1; grid-row: auto; min-height: 320px; }
  .board-grid .card.h2 { min-height: 190px; }
  .page-wrap { padding: 8px 16px 64px; }
  .msg-user { max-width: 92%; }
  .ghost { right: 56px; }
}
