/* Grundstil och layout */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  color: var(--text);
  background-color: var(--bg);
  background-image: radial-gradient(var(--grid-dot) 1px, transparent 1px);
  background-size: 24px 24px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--text); text-decoration: none; }
a:hover { color: var(--accent); }

h1, h2, h3, p { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mono { font-family: var(--font-mono); }

/* Små etiketter i versaler med spärrning */
.label {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-2);
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Appens ram ---------- */
.app {
  display: flex;
  min-height: 100vh;
}

/* ---------- Vänstermeny ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  padding: 32px 20px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 40px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.brand-link:hover { color: var(--text); }
.brand-link svg { color: var(--accent); flex-shrink: 0; }

.menu-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 15px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 46px;
  padding: 0 14px;
  border-radius: var(--r-sm);
  color: var(--text-3);
}
.nav a:hover { background: var(--subtle); color: var(--text); }
.nav a svg { flex-shrink: 0; }

.nav a[aria-current="page"] {
  background: var(--accent-tint);
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Innehåll ---------- */
.main {
  flex-grow: 1;
  min-width: 0;
  padding: 0 var(--gutter) var(--gutter);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.page-header {
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.page-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.page-title h1 {
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

/* ---------- Kort ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card-lg);
  padding: 28px;
}

.empty {
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-card);
  padding: 40px;
  text-align: center;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-2);
}

/* ---------- Knappar ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 44px;
  padding: 0 20px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { color: var(--text); background: var(--subtle); }

.btn-dark { background: var(--dark); border-color: var(--dark); color: var(--on-dark); }
.btn-dark:hover { background: var(--dark-hover); border-color: var(--dark-hover); color: var(--on-dark); }

.btn-accent { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #FFFFFF; }

.btn-danger { background: var(--warning); border-color: var(--warning); color: #FFFFFF; }
.btn-danger:hover { background: var(--warning-hover); border-color: var(--warning-hover); color: #FFFFFF; }

/* ---------- Bekräftelseruta (js/dialog.js) ---------- */
.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-pop);
}
.dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(4px); }

.dialog-body { display: flex; flex-direction: column; gap: 12px; padding: 28px; }
.dialog-title { font-size: 20px; font-weight: 500; letter-spacing: -0.01em; }
.dialog-message { font-size: 15px; line-height: 1.6; color: var(--text-3); }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

/* ---------- Sidhuvud med knappar och nyckeltal (delas av flera sidor) ---------- */
.header-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  font-size: 16px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--subtle); }

.month-pill {
  min-width: 160px;
  height: 44px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
}

.save-status {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--text-2);
  min-width: 90px;
  text-align: right;
}
.save-status.is-error { color: var(--warning); }

/* ---------- Nyckeltal ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card-sm);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.stat .label { font-size: 11px; letter-spacing: 0.1em; }
.stat-value { font-size: 26px; font-weight: 400; letter-spacing: -0.02em; white-space: nowrap; }
.stat-note { font-size: 12px; color: var(--text-2); }
.stat-value.is-positive { color: var(--positive); }

.stat-dark { background: var(--feature-bg); border-color: var(--feature-border); color: var(--on-feature); }
.stat-dark .label { color: var(--on-feature-2); }
.stat-dark .stat-value.is-negative { color: var(--on-feature-negative); }

.loading { padding: 40px; text-align: center; color: var(--text-2); }

.icon-tile {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: var(--r-sm);
  background: var(--accent-tint);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Döljer sidan tills inloggningen är kontrollerad, och tills översättningen är klar */
.auth-pending body, .i18n-pending body { visibility: hidden; }

/* ---------- Menyfot med användare ---------- */
.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.user {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 14px;
  min-width: 0;
}
.user-name { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-email { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-button {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 46px;
  padding: 0 14px;
  border: none;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-3);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.nav-button:hover { background: var(--subtle); color: var(--text); }

/* ---------- Formulär ---------- */
.form { display: flex; flex-direction: column; gap: 24px; }

.form-row { display: flex; flex-direction: column; gap: 8px; }

.form-row-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.field {
  height: 52px;
  width: 100%;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 15px;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--focus-ring); }

.btn-block { width: 100%; height: 52px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.link-button {
  padding: 0;
  border: none;
  background: none;
  font-size: 13px;
  color: var(--text-3);
  cursor: pointer;
}
.link-button:hover { color: var(--accent); }

/* Meddelanden (fel och bekräftelser) */
.msg {
  padding: 14px 16px;
  border-radius: var(--r-md);
  font-size: 14px;
  line-height: 1.5;
}
.msg:empty { display: none; }
.msg-error { background: var(--warning-bg); color: var(--warning-text); }
.msg-ok { background: var(--positive-bg); color: var(--positive); }
.msg-info { background: var(--accent-tint); color: var(--text); }

/* ---------- Mobil och surfplatta ---------- */
@media (max-width: 900px) {
  :root { --gutter: 16px; --header-h: 88px; }

  .app { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 12px 16px;
    gap: 0;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .brand { padding: 0; }
  .menu-toggle { display: inline-flex; }

  .nav { display: none; padding-top: 12px; }
  .sidebar.is-open .nav { display: flex; }

  .sidebar-foot { display: none; margin-top: 12px; }
  .sidebar.is-open .sidebar-foot { display: flex; }

  .page-header { flex-direction: column; align-items: flex-start; padding: 16px 0; }
  .header-actions { justify-content: flex-start; }
  .month-pill { min-width: 0; flex-grow: 1; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .stat { padding: 16px; }
  .stat-value { font-size: 20px; }
}

/* ---------- Support (js/support.js) ---------- */
.support-fab {
  position: fixed;
  left: calc(var(--sidebar-w) + 24px); /* nere till vänster om innehållet, bredvid menyn */
  bottom: 24px;
  z-index: 50;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 12px 28px -10px var(--accent-glow), 0 2px 6px rgba(0, 0, 0, .12);
  transition: transform .3s var(--ease-spring), box-shadow .3s var(--ease-out), background .2s;
}
.support-fab:hover { transform: translateY(-2px) scale(1.05); background: var(--accent-hover); }
.support-fab.is-open { transform: rotate(-8deg) scale(.94); }

.support-panel {
  position: fixed;
  inset: auto auto 96px calc(var(--sidebar-w) + 24px);
  margin: 0;
  width: min(400px, calc(100vw - 32px));
  max-height: calc(100vh - 128px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-pop);
  overflow: auto;
}
.support-panel::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
.support-panel[open] { animation: support-in .35s var(--ease-out); }
@keyframes support-in { from { opacity: 0; transform: translateY(16px) scale(.97); } }

.support-form, .support-done { display: flex; flex-direction: column; gap: 14px; padding: 24px; }
.support-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.support-head h2, .support-done h2 { font-size: 20px; font-weight: 500; }
.support-head p, .support-done p { font-size: 14px; line-height: 1.5; color: var(--text-2); margin-top: 4px; }
.support-form .field { height: 46px; }
.support-textarea { height: auto !important; min-height: 120px; padding: 12px 16px; line-height: 1.5; resize: vertical; }
.support-form .field-hint { align-self: flex-end; font-size: 12px; color: var(--text-2); }

.support-done { align-items: center; text-align: center; padding: 36px 24px 28px; }
.support-check {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--positive-bg);
  color: var(--positive);
  animation: pop-check .5s var(--ease-spring);
}
@keyframes pop-check { from { transform: scale(0); } }

@media (max-width: 900px) {
  .support-fab { left: 16px; bottom: 16px; width: 52px; height: 52px; }
  .support-panel { inset: auto 16px 80px 16px; width: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .support-fab, .support-panel[open], .support-check { animation: none; transition: none; }
}

/* Luft i botten så att supportknappen inte skymmer det sista på sidan */
.main { padding-bottom: calc(var(--gutter) + 64px); }

/* ---------- Förklaringar (js/tooltip.js) ---------- */
.info-tip {
  width: 16px;
  height: 16px;
  margin-left: 6px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: transparent;
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 600;
  line-height: 14px;
  letter-spacing: 0;
  text-transform: none;
  vertical-align: 1px;
  cursor: help;
  transition: color .2s, border-color .2s, background .2s;
}
.info-tip:hover, .info-tip:focus-visible { color: var(--accent); border-color: var(--accent); background: var(--accent-tint); }
.stat-dark .info-tip, .hero-stat.is-dark .info-tip { border-color: rgba(255, 255, 255, .3); color: var(--on-feature-2); }

.tooltip {
  position: fixed;
  z-index: 200;
  max-width: 260px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  box-shadow: var(--shadow-lift);
  pointer-events: none;
  animation: tip-in .18s var(--ease-out);
}
@keyframes tip-in { from { opacity: 0; transform: translateY(4px); } }
.tooltip.is-below { animation-name: tip-in-below; }
@keyframes tip-in-below { from { opacity: 0; transform: translateY(-4px); } }

/* ---------- Rundtur (js/tour.js) ---------- */
.tour { position: fixed; inset: 0; z-index: 300; }
.tour-shield { position: absolute; inset: 0; transition: background .3s ease; }
.tour.is-centered .tour-shield { background: var(--tour-dim); }
.tour-spot {
  position: fixed;
  border-radius: 18px;
  box-shadow: 0 0 0 200vmax var(--tour-dim), 0 0 0 2px var(--accent), 0 0 24px 2px var(--accent-glow);
  transition: left .35s var(--ease-out), top .35s var(--ease-out), width .35s var(--ease-out), height .35s var(--ease-out), opacity .3s;
  pointer-events: none;
}
.tour.is-centered .tour-spot { opacity: 0; }
.tour-bubble {
  position: fixed;
  width: min(380px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-pop);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .25s ease, transform .25s var(--ease-out);
}
.tour-bubble.is-in { opacity: 1; transform: none; }
.tour-top { display: flex; align-items: center; justify-content: space-between; }
.tour-close {
  width: 32px;
  height: 32px;
  margin: -6px -8px -6px 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--text-2);
  cursor: pointer;
}
.tour-close:hover { background: var(--hover-bg); color: var(--text); }
.tour-bubble h2 { font-size: 19px; font-weight: 500; letter-spacing: -0.01em; }
.tour-bubble p { font-size: 14px; line-height: 1.6; color: var(--text-2); }
.tour-bubble strong { color: var(--text); font-weight: 600; }
.tour-dots { display: flex; gap: 4px; margin-top: 4px; }
.tour-dots i { flex: 1; height: 3px; border-radius: 3px; background: var(--line-strong); transition: background .3s; }
.tour-dots i.is-on { background: var(--accent); }
.tour-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.tour-actions .btn { height: 40px; }
.tour-actions .btn-plain { border-color: transparent; background: transparent; }
.tour.is-leaving { opacity: 0; transition: opacity .25s ease; }
