:root{
  --bg: #0b0d12;
  --panel: #101522;
  --text: #e8ecf3;
  --muted: #a8b1c3;
  --line: #1f2a3d;
  --bad: #ff6b6b;
  --good: #7ee787;
  --warn: #ffd479;
  --btn: #18233a;
  --btn2: #0f1a30;
  --radius: 16px;
}

*{ box-sizing: border-box; }
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background: radial-gradient(1200px 800px at 20% 0%, #111a2d, var(--bg));
  color: var(--text);
}

body.modal-open{ overflow: hidden; }

.topbar{
  display:flex;
  gap:16px;
  justify-content: space-between;
  align-items:flex-start;
  padding:14px 14px 10px;
  border-bottom: 1px solid var(--line);
}

.brand{ display:flex; gap:12px; align-items:center; }
.logo{
  width:44px;height:44px;
  border-radius: 14px;
  background: linear-gradient(145deg, #1a2b52, #0f1b33);
  display:grid; place-items:center;
  font-weight:800; letter-spacing: .5px;
}
.title{ font-weight:800; }
.subtitle{ color: var(--muted); font-size: 12px; margin-top:2px; }

.stats{
  display:grid;
  grid-template-columns: repeat(5, minmax(90px, 1fr));
  gap:10px;
}
.stat{
  background: rgba(16,21,34,.7);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding:10px 10px;
  display:flex;
  flex-direction: column;
  gap:2px;
  min-width: 90px;
}

.stat-click{ cursor:pointer; }
.stat-click:hover{ border-color: rgba(255,255,255,.18); }
.statHint{ display:block; font-size:11px; font-weight:700; opacity:.75; margin-top:2px; }

.btn:active{
  transform: translateY(1px);
  filter: brightness(.92);
}

.toast{
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: rgba(16,21,34,.92);
  border: 1px solid rgba(255,255,255,.12);
  padding: 10px 12px;
  border-radius: 12px;
  z-index: 10000;
  box-shadow: 0 18px 60px rgba(0,0,0,.45);
  font-weight: 800;
  max-width: min(680px, calc(100% - 32px));
  text-align: center;
}
.stat span{ color: var(--muted); font-size:12px; }
.stat strong{ font-size:14px; }

.tabs{
  display:flex;
  gap:8px;
  padding:10px 14px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  backdrop-filter: blur(10px);
  background: rgba(11,13,18,.75);
  z-index: 10;
}
.tab{
  border:1px solid var(--line);
  background: var(--btn);
  color: var(--text);
  border-radius: 999px;
  padding:8px 12px;
  cursor:pointer;
  font-weight:650;
}
.tab:hover{ background: var(--btn2); }
.tab.is-active{
  outline: 2px solid rgba(126,231,135,.25);
  border-color: rgba(126,231,135,.35);
}
.tab-ghost{
  background: transparent;
  border-style: dashed;
  color: var(--muted);
}
.spacer{ flex:1; }

.layout{
  padding:14px;
  display:grid;
  grid-template-columns: 1fr;
  gap:14px;
}
.panel{
  background: rgba(16,21,34,.72);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding:14px;
  min-height: 58vh;
}

.grid{ display:grid; gap:10px; }
.marketRow{
  display:grid;
  grid-template-columns: 1fr auto;
  gap:12px;
  padding:10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(15,20,32,.55);
  align-items:start;
}
.marketMain{
  display:grid;
  grid-template-columns: 1fr auto;
  gap:12px;
  align-items:start;
  min-width: 0;
}
.marketInfo{ min-width:0; }
.marketStats{ text-align:right; }
.marketStats .meta{ line-height: 1.15; }
.marketRow h4{ margin:0 0 2px; font-size:14px; line-height:1.2; }
.badgeWrap{ margin-top:6px; display:flex; justify-content:flex-end; }
.meta{ color: var(--muted); font-size:12px; }
.meta.good{ color: rgba(120, 255, 179, 0.95); }
.meta.bad{ color: rgba(255, 133, 133, 0.95); }
.price{ font-size: 14px; font-weight: 800; text-align:right; }
.priceSub{ font-size: 12px; opacity: .92; margin-top:2px; }
.discBadge{
  display:inline-block;
  margin-left:6px;
  font-size: 11px;
  font-weight: 900;
  color: var(--good);
}

.badge{
  display:inline-flex;
  align-items:center;
  gap:6px;
  font-size: 12px;
  padding:4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.15);
  color: var(--muted);
}
.badge.good{ color: var(--good); border-color: rgba(126,231,135,.25); }
.badge.bad{ color: var(--bad); border-color: rgba(255,107,107,.25); }
.badge.warn{ color: var(--warn); border-color: rgba(255,212,121,.25); }

.actions{
  display:flex;
  align-items: stretch;
}
.actionGrid{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap:6px;
  min-width: 220px;
}

/* Klarna-knappen (3e) tar hela raden */
.actionGrid .btn:nth-child(3){
  grid-column: 1 / -1;
}

/* Compact buttons in market rows */
.actionGrid .btn{
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.1;
}
.btn{
  border: 1px solid var(--line);
  background: #121a2d;
  color: var(--text);
  border-radius: 12px;
  padding:7px 10px;
  cursor:pointer;
  font-weight: 700;
  font-size: 12px;
}
.btn:disabled{ opacity:.45; cursor:not-allowed; }
.btn.buy{ outline: 1px solid rgba(126,231,135,.18); }
.btn.sell{ outline: 1px solid rgba(255,212,121,.16); }
.btn.klarna{ outline: 1px solid rgba(116,196,255,.22); }

.input{
  width: 140px;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(7,10,16,.6);
  color: var(--text);
  font-weight: 700;
}

.modal{
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.55);
  z-index: 9999;
  padding: 18px;
}

/* Viktigt: lat [hidden] faktiskt gomma modalen (UA-stylesheet kan annars bli overskrivet). */
.modal[hidden]{
  display: none !important;
}



.modalCard{
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(11,14,22,.92);
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  padding: 16px;
}

.modalTitle{ font-size: 18px; font-weight: 900; margin-bottom: 8px; }
.modalText{ color: var(--text); line-height: 1.35; margin-bottom: 14px; }
.modalActions{ display: flex; gap: 10px; justify-content: flex-end; }

.kv{
  display:flex;
  justify-content: space-between;
  gap:10px;
  padding:10px 12px;
  border:1px solid var(--line);
  border-radius: 14px;
  background: rgba(15,20,32,.55);
}
.kv .k{ color: var(--muted); }
.kv .v{ font-weight:800; }

.list{ display:flex; flex-direction: column; gap:10px; }

.footer{
  padding: 12px 14px 22px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

@media (min-width: 980px){
  .layout{ grid-template-columns: 1.35fr .65fr; align-items:start; }
  #view-market{ grid-column: 1 / 2; }
  #view-inventory{ grid-column: 2 / 3; }
  #view-travel{ grid-column: 2 / 3; }
  #view-log{ grid-column: 2 / 3; }
  #view-inventory[hidden],
  #view-travel[hidden],
  #view-log[hidden]{ display:block; }
}

@media (max-width: 520px){
  .marketRow{ grid-template-columns: 1fr; }
  .actions{ width: 100%; }
  .actionGrid{ min-width: 0; grid-template-columns: 1fr; }
  .actionGrid .btn:nth-child(3){ grid-column: auto; }
  .marketMain{ grid-template-columns: 1fr; }
  .marketStats{ text-align:left; }
  .badgeWrap{ justify-content:flex-start; }
}



.section{ margin-top: 14px; }
.sectionTitle{
  margin: 16px 0 10px;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: .2px;
  color: rgba(255,255,255,.92);
}

/* Bemd-rabatt i Marknad */
.priceSub{
  font-size: 0.95em;
  opacity: 0.95;
  margin-top: 2px;
}
.discBadge{
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.85em;
  background: rgba(0, 0, 0, 0.2);
}

/* Gör -10% tydligt gron */
.discBadge{ color: #9ff39f; border: 1px solid rgba(159,243,159,.35); }

/* ===== Mobile hard fix: prevent horizontal overflow ===== */
@media (max-width: 700px){
  html, body{ max-width:100%; overflow-x:hidden; }

  .topbar{ flex-direction:column; align-items:stretch; }
  .brand{ width:100%; }

  .stats{
    grid-template-columns: repeat(2, minmax(0,1fr));
    width:100%;
  }
  .stat{ min-width:0; }

  .tabs{ flex-wrap:wrap; }
  .tab{ white-space:nowrap; }
  .spacer{ display:none; }

  .marketRow{ grid-template-columns: 1fr; }
  .marketMain{ grid-template-columns: 1fr; }
  .marketStats{ text-align:left; }
  .badgeWrap{ justify-content:flex-start; }

  .actions{ width:100%; }
  .actionGrid{ min-width:0; width:100%; grid-template-columns: 1fr 1fr; }
  /* Klarna full width */
  .actionGrid .btn:nth-child(3){ grid-column: 1 / -1; }
}

/* Safety: allow grid children to shrink */
.topbar, .stats, .layout, .panel, .marketRow, .marketMain{ min-width:0; }
.marketRow > *, .marketMain > *{ min-width:0; }
