/* =========================================================
   LJUST, STILRENT TEMA – index.html + script.js
   ========================================================= */

/* ---------- Variabler ---------- */
:root{
  --bg:#f6f8fb;
  --surface:#ffffff;
  --surface-2:#f1f5fb;

  --text:#0f172a;
  --muted:#5b6473;

  --primary:#2563eb;
  --primary-2:#1e4fd1;
  --accent:#10b981;
  --danger:#ef4444;

  --border:#e6eaf1;
  --radius:12px;
  --shadow:0 8px 28px rgba(15,23,42,.06);
  --shadow-sm:0 3px 12px rgba(15,23,42,.05);

  /* Nya: dov, jordnära ton för de tre toppkorten */
  --tone:#f3efe7;          /* varm sand/linne */
  --tone-2:#eee9df;        /* lite mörkare botten i gradient */
  --tone-border:#e7e1d4;   /* matchande kant */
}

/* ---------- Bas ---------- */
* { box-sizing: border-box; }
html, body { height:100%; }
body {
  margin:0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans";
  line-height:1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1{ font-size: clamp(1.6rem, 1.1rem + 2.2vw, 2.2rem); line-height:1.15; margin:4px 0 8px; }
h2{ font-size: clamp(1.2rem, 1.0rem + .8vw, 1.5rem); line-height:1.2; margin:0 0 8px; }
h3{ font-size: 1.05rem; margin:0 0 6px; }
h4{ font-size: 1rem;  margin:0 0 6px; }
p  { margin:0 0 8px; }
.lead{ font-size:1.15rem; font-weight:700; }

/* Layout-containers */
.container { max-width: 1100px; margin: 0 auto; padding: 16px; }

.header {
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(6px);
  background: linear-gradient(to bottom, rgba(246,248,251,.85), rgba(246,248,251,.55));
  display:flex; align-items:center; justify-content:space-between; gap:16px; padding: 14px 16px; margin-bottom:12px;
  border-bottom:1px solid var(--border);
}
.footer{ color:var(--muted); font-size:.95rem; padding: 16px; text-align:left; }

/* Utilities */
.hidden { display:none !important; }
.row { display:flex; align-items:center; gap:10px; }
.row.end { justify-content:flex-end; }
.space-between { justify-content: space-between; }
.stack > * + * { margin-top:10px; }
.grid { display:grid; grid-template-columns: repeat(3, 1fr); gap:16px; }
@media (max-width: 980px){ .grid{ grid-template-columns: 1fr; } }
.muted { color: var(--muted); }
.mini { font-size: .9rem; }
.big { font-size: 1.25rem; font-weight: 700; }

/* Fokusringar */
:focus-visible{
  outline:3px solid rgba(37,99,235,.35);
  outline-offset:2px;
  border-radius:8px;
}

/* ---------- Kort / ytor ---------- */
.card, .ai-card, .summary-card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card:hover{ box-shadow: var(--shadow-sm); }

/* Toppradens 3 kort: jordnära ton – endast i Översiktens grid */
/* ==== Top-panels: Ocean Blue look (no JS changes needed) ==== */
#sum-cards .card{
  background: linear-gradient(180deg, #eef4ff 0%, #eaf2ff 100%);
  border-color: #cfe0ff;
  box-shadow: 0 12px 28px rgba(37, 99, 235, .12), var(--shadow-sm);
}
#sum-cards .card:hover{
  transform: translateY(-2px);
  box-shadow: 0 16px 36px rgba(37, 99, 235, .16), var(--shadow-sm);
}

/* små chips/rundade badges inuti panelerna (t.ex. "Per vecka") */
#sum-cards .chip,
#sum-cards .stat-chip{
  background: #f1f6ff;
  border-color: #d8e6ff;
}

/* bars i “Styrkor & potential” tonas in mot blått */
#sum-cards .bar{ background:#eaf1ff; border-color:#dbe7ff; }
#sum-cards .bar > div{
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
}

/* huvudrubrikerna i panelerna poppar lite mer */
#sum-cards h3{ font-weight: 800; }

/* liten separationsmarginal mellan raderna */
#ai-insights{ margin-top: 12px; }


/* ---------- Header-links ---------- */
.nav .link {
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, box-shadow .15s ease, transform .1s ease;
}
.nav .link:hover { background: var(--surface-2); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
button:disabled, .nav .link:disabled { opacity:.5; cursor:not-allowed; transform:none; box-shadow:none; }

/* ---------- Tabs ---------- */
.tabs { display:flex; gap:10px; margin: 12px 0 16px; flex-wrap:wrap; }
.tabs .tab, .tabs button {
  padding:12px 16px;                   /* större klickyta */
  border-radius:12px;
  border:1px solid var(--border);
  background: var(--surface);
  color:var(--text);
  cursor:pointer;
  font-weight: 700;                     /* tydligare text */
  font-size: .98rem;
  transition: background .15s ease, transform .1s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.tabs .tab:hover, .tabs button:hover{
  background: var(--surface-2);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.tabs .tab.active, .tabs button.active {
  background:var(--primary);
  color:#fff;
  border-color: var(--primary-2);
  box-shadow: 0 2px 10px rgba(37,99,235,.18);
}

/* ---------- Inputs ---------- */
input[type="text"], input[type="password"], textarea {
  width:100%; background:#fff; color:var(--text);
  border:1px solid var(--border); border-radius:10px; padding:10px 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input::placeholder, textarea::placeholder{ color:#9aa4b3; }
input:focus, textarea:focus{
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
textarea { min-height: 64px; resize: vertical; }

/* ---------- Buttons ---------- */
button, .btn{
  background: var(--primary);
  color:#fff;
  border:none;
  border-radius:10px;
  padding:10px 14px;
  font-weight:600;
  cursor:pointer;
  transition: background .15s ease, transform .1s ease, box-shadow .15s ease;
}
button:hover{ background: var(--primary-2); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
button.ghost{ background: transparent; color: var(--text); border:1px solid var(--border); }
button.danger{ background: var(--danger); color:white; }
button.secondary { background: transparent; color: var(--text); border:1px solid var(--border); }
button.secondary:hover { background: var(--surface-2); }
button.mini{ padding:6px 10px; font-size:.9rem; border-radius:8px; }
button.mini.primary{ background:var(--primary); color:#fff; }

/* ---------- Progress ---------- */
.progress{
  width:100%; height:12px; border-radius:8px; background:var(--surface-2); overflow:hidden;
  border:1px solid var(--border);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.03);
}
.progress.big{ height:14px; }
.progress > span, .bar > div{
  display:block; height:100%;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  transition: width .25s ease;
}
.bar { width:100%; height:10px; border-radius:7px; background:var(--surface-2); overflow:hidden; border:1px solid var(--border); margin-top:6px; }

/* ---------- Quiz ---------- */
.pill-group { display:grid; gap:10px; margin-top:10px; }
.quiz-option{
  display:flex; align-items:center; gap:12px;
  padding:14px 14px;
  border:1px solid var(--border);
  border-radius:12px;
  background:#fff;
  cursor:pointer;
  transition: border-color .15s ease, box-shadow .15s ease, transform .08s ease;
}
.pill.quiz-option input { accent-color: var(--primary); }
.quiz-option:hover{ transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.quiz-option.selected{ border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

/* ---------- Planlayout ---------- */
.plan-grid { display:grid; grid-template-columns: 320px 1fr; gap:16px; }
@media (max-width: 1100px){ .plan-grid{ grid-template-columns: 1fr; } }

/* Vänstersida – modulkort */
#plan-modules { display:flex; flex-direction:column; gap:12px; }
#plan-modules .header-muted{ display:none !important; }

.module {
  background:#fff; border:1px solid var(--border); border-radius:12px;
  padding:14px 12px; display:flex; justify-content:space-between; align-items:flex-start;
  gap:12px; box-shadow: var(--shadow-sm);
}
.module .subtitle{ color:var(--muted); margin-top:2px; }
.module .time-pill{
  background:var(--surface-2); border:1px solid var(--border); border-radius:999px;
  padding:6px 10px; font-size:.9rem; white-space:nowrap;
}

/* Högersida – moduldetalj */
.module-detail{
  background:#fff; border:1px solid var(--border); border-radius:12px; box-shadow: var(--shadow);
  padding:22px;
}
.module-detail > .row.space-between{ margin-bottom:14px; }
.module-detail h3{ margin-bottom:6px; }
.module-detail p.muted{ margin-bottom:10px; }

.plan-steps { margin-top:8px; }
.step-row{
  display:grid; grid-template-columns: 34px 1fr; gap:10px; align-items:center;
  padding:12px 0; border-bottom:1px dashed var(--border);
}
.step-row:last-child{ border-bottom:none; }
.idx-bubble{
  width:28px; height:28px; border-radius:999px; display:grid; place-items:center;
  background:var(--surface-2); border:1px solid var(--border); font-weight:700;
}
.step-row .title { line-height:1.45; }
.step-row .actions{ margin-top:6px; }

/* ---------- Overlay / spinner ---------- */
#overlay{
  position:fixed; inset:0; background:rgba(15, 23, 42, 0.25);
  display:flex; align-items:center; justify-content:center;
  z-index:9999;
}
#overlay.hidden{ display:none !important; }
.spinner{
  width:52px; height:52px; border-radius:50%;
  border:4px solid rgba(15,23,42,0.2);
  border-top-color: var(--primary);
  animation: spin .9s linear infinite;
}
@keyframes spin{ to { transform: rotate(360deg) } }

/* ---------- Små skärmar ---------- */
@media (max-width: 640px){
  .header{ padding:12px 10px; }
  .container{ padding: 12px; }
  button, .btn{ padding:9px 12px; }
  .plan-grid{ gap:12px; }
}

/* ---------- Sista polish ---------- */
.card h3 + p.muted{ margin-top:-4px; }
#quiz-count{ align-self:flex-end; }

/* ===== Stats-chips (på översikten) ===== */
.stats { display:flex; gap:8px; flex-wrap:wrap; margin:8px 0 10px; }
.stat-chip {
  display:inline-flex; align-items:center; gap:6px;
  background: var(--surface-2); border:1px solid var(--border);
  border-radius:999px; padding:6px 10px; font-size:.9rem;
}
.next-actions { margin-top:8px; }
.next-actions li { margin-left:18px; }

#cta-lock, #cta-goto-plan { white-space:nowrap; }

/* =========================================================
   BADGES – roligare, stabil layout
   ========================================================= */

/* Grid */
.achv-grid{
  display:grid; grid-template-columns: repeat(auto-fill, minmax(260px,1fr));
  gap:14px;
}

/* Kort */
.achv{
  position:relative; overflow:hidden;
  padding:14px 14px 12px; border-radius:18px;
  background:linear-gradient(180deg,#fff,#f8fafc);
  border:1px solid var(--border);
  box-shadow: 0 6px 18px rgba(15,23,42,.06), inset 0 1px 0 rgba(255,255,255,.8);
  display:grid; grid-template-columns: 68px 1fr 76px;
  gap:12px; align-items:center; min-height:96px;
}

/* Medalj + progressring (CSS only) */
.achv .medal{
  --pct: 0; /* 0..1 – sätt via style="--pct:.6" om du vill visa framsteg */
  width:64px; height:64px; border-radius:50%; position:relative;
  display:grid; place-items:center;
  background:
    conic-gradient(#60a5fa calc(var(--pct)*360deg), #e5eaf3 0) border-box,
    radial-gradient(circle at 30% 30%, #fff, #eef2ff 60%, #e2e8f0) padding-box;
  border:4px solid transparent;
  box-shadow: inset 0 2px 6px rgba(0,0,0,.06);
  font-size:30px;
}

/* Formvarianter */
.shape-hex .medal{ clip-path: polygon(25% 6%, 75% 6%, 100% 50%, 75% 94%, 25% 94%, 0 50%); }
.shape-shield .medal{ clip-path: polygon(50% 0, 95% 25%, 78% 100%, 22% 100%, 5% 25%); }

/* Text */
.achv .title{
  font-weight:800; line-height:1.2;
  display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden;
  margin-right:6px;
}
.achv .desc{ color:var(--muted); font-size:.92rem; margin-top:2px; max-width:40ch; }
.achv .when{ color:var(--muted); font-size:.82rem; white-space:nowrap; }

/* Poäng */
.achv .points{
  justify-self:end; align-self:start;
  background:#fff; border:1px solid var(--border); border-radius:999px;
  padding:4px 10px; font-weight:800; box-shadow: var(--shadow-sm);
  display:inline-flex; gap:6px; align-items:center; min-width:60px;
}
.achv .points .star{ filter: drop-shadow(0 0 6px rgba(250,204,21,.35)); }

/* Locked */
.achv.locked{ filter: grayscale(.92) brightness(.95); }
.achv.locked .points{ opacity:.75; }

/* Raritet / glow */
.achv.common    { border-color:#dbe2ea; }
.achv.rare      { border-color:#93c5fd; box-shadow: 0 0 0 2px rgba(59,130,246,.08) inset, var(--shadow-sm); }
.achv.epic      { border-color:#c084fc; box-shadow: 0 0 0 2px rgba(168,85,247,.12) inset, 0 0 18px rgba(168,85,247,.12); }
.achv.legendary { border-color:#fbbf24; box-shadow: 0 0 0 2px rgba(251,191,36,.18) inset, 0 0 22px rgba(251,191,36,.16); }

/* Interaktion */
@media (hover:hover){
  .achv:hover{ transform: translateY(-1px); transition: transform .08s; }
  .achv:focus-visible{ outline:3px solid rgba(37,99,235,.25); outline-offset:2px; }
}

/* Sammanfattningsrad med totalpoäng */
#badges-summary{
  display:flex; align-items:center; gap:12px; margin:0 0 10px;
}
#badges-summary .meter{
  flex:1; height:10px; border:1px solid var(--border); border-radius:8px;
  background:var(--surface-2); overflow:hidden;
}
#badges-summary .meter > div{
  height:100%; width:0%; background:linear-gradient(90deg,#f59e0b,#fbbf24); transition:width .25s;
}
#badges-summary .tot { font-weight:700; white-space:nowrap; }

/* Endast en hint-rad */
#tab-badges .achv-hint{ margin-top:10px; }

/* Steglistan: plats för soptunna */
.step-row{
  display:grid;
  grid-template-columns: 34px 1fr auto;
  gap:10px; align-items:center;
  padding:12px 0; border-bottom:1px dashed var(--border);
}
.step-row:last-child{ border-bottom:none; }

.del{
  background:transparent; border:none; cursor:pointer;
  padding:6px; border-radius:8px; color:#6b7280;
  opacity:.0; transition:opacity .12s ease, background .12s ease, color .12s ease;
}
.step-row:hover .del{ opacity:1; }
.del:hover{ background:var(--surface-2); color:#111827; }
.del svg{ width:18px; height:18px; display:block; }

.module-detail .row.space-between { margin-bottom: 8px; }
.module-detail .subtitle { margin-top: 2px; }
.module-detail .plan-steps { margin-top: 8px; }

/* ===== Progress & streaks ===== */
.progress-card { margin-top: 16px; }

.progress-track{
  position: relative;
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(15,23,42,0.03);
}
.progress-fill{
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #22c55e, #f59e0b, #ef4444);
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  transition: width .35s ease;
}

.milestones{
  pointer-events: none;
  position: absolute; inset: 0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  align-items: center;
}
.milestones .dot{
  position: relative; top: -18px; justify-self: end;
  transform: translateX(50%);
  font-size: .85rem; color: var(--muted);
}
.milestones .dot::before{
  content: "";
  position:absolute; bottom: -10px; left: 50%;
  width: 8px; height: 8px; border-radius: 50%;
  transform: translateX(-50%);
  background: #cbd5e1; border: 1px solid var(--border);
  box-shadow: 0 0 0 2px #fff;
}
.milestones .dot.active{ color: var(--text); font-weight: 700; }
.milestones .dot.active::before{ background: var(--primary); }

.streak-pill{
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

/* Confetti canvas */
.confetti{
  width: 100%;
  height: 160px;
  display:block;
  margin-top:8px;
  border-radius: 12px;
  background: transparent;
}

/* Rarity-bakgrund */
.achv.common    { --achv-bg: linear-gradient(180deg,#fff,#f8fafc); }
.achv.rare      { --achv-bg: linear-gradient(180deg,#f0f7ff,#eaf2ff); }
.achv.epic      { --achv-bg: linear-gradient(180deg,#f9f0ff,#f3e8ff); }
.achv.legendary { --achv-bg: linear-gradient(180deg,#fff7e6,#fff1cc); }

.achv{
  background: var(--achv-bg);
  transition: transform .12s ease, box-shadow .12s ease, filter .2s ease;
}
.achv.locked { filter: grayscale(.85) brightness(.95); }

@keyframes achvPop {
  0%   { transform: scale(.98); box-shadow: 0 0 0 rgba(0,0,0,0); }
  40%  { transform: scale(1.03); }
  100% { transform: scale(1.00); }
}
@keyframes achvGlow {
  0%   { box-shadow: 0 0 0 rgba(0,0,0,0); }
  50%  { box-shadow: 0 0 20px rgba(251,191,36,.35); }
  100% { box-shadow: var(--shadow-sm); }
}

/* körs när en badge nyss låstes upp */
.achv.just-unlocked{
  animation: achvPop .45s ease, achvGlow 1.1s ease;
  filter: none !important;
}

/* liten 'toast' för feedback (används av logFollowUp/shareTemplate) */
.toast{
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(8px);
  background:#111827; color:#fff; padding:10px 14px; border-radius:10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18); opacity:0; pointer-events:none; transition: .18s;
  z-index: 9999;
}
.toast.show{ opacity:1; transform: translateX(-50%) translateY(0); }

/* --- Dova, professionella paneler för topp-3-boxarna --- */
#sum-cards .card{
  /* ljusare, kallt blått utan att ta över */
  background: linear-gradient(180deg, #fbfcff, #f6f9ff);
  border-color: #e7eefc;
  /* mindre skugga = mindre “spill” */
  box-shadow: 0 4px 14px rgba(37,99,235,.05), 0 1px 0 rgba(17,24,39,.03);
}

/* gör inner-baren lite diskretare i dessa paneler */
#sum-cards .bar{ background:#eef2ff; border-color:#e6ebfa; }
#sum-cards .bar > div{
  background: linear-gradient(90deg, #3b82f6, #8ab6ff);
}

/* runda hörn aningen mer för att ge mjukare intryck */
#sum-cards .card{ border-radius: 14px; }

/* knapparna behåller sin primärblå, men känns mindre “hårda” mot panelerna */
#sum-cards .card .secondary:hover{ background:#eff3ff; }
