@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@500&display=swap');

:root {
  --ink:        #1E2230;
  --ink-soft:   #4B5164;
  --paper:      #F6F3EC;
  --paper-raised: #FFFFFF;
  --line:       #E2DDCF;
  --navy:       #182238;
  --navy-soft:  #26324C;
  --gold:       #A9791F;
  --gold-soft:  #F1E4C4;
  --gain:       #2E6F5E;
  --gain-bg:    #E4EFE9;
  --loss:       #B0402A;
  --loss-bg:    #F5E4DF;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'IBM Plex Sans', -apple-system, Segoe UI, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

h1, h2 { font-family: var(--font-display); font-weight: 600; margin: 0; }
h1 { font-size: 1.85rem; }
h2.section-title { font-size: 1.15rem; margin: 2rem 0 0.75rem; color: var(--ink); }

a { color: var(--navy); }

/* ---------- App layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--navy);
  color: #E7E9F0;
  display: flex;
  flex-direction: column;
  padding: 1.75rem 1.25rem;
}

.sidebar__brand { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 2.5rem; }
.sidebar__mark {
  font-family: var(--font-display);
  font-weight: 600;
  background: var(--gold);
  color: var(--navy);
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 3px;
  font-size: 0.85rem;
}
.sidebar__title { font-family: var(--font-display); font-size: 1.05rem; letter-spacing: 0.01em; }

.sidebar__nav { list-style: none; margin: 0; padding: 0; flex-grow: 1; }
.sidebar__nav li { margin-bottom: 0.15rem; }
.sidebar__nav a {
  display: block;
  padding: 0.6rem 0.75rem;
  border-radius: 4px;
  color: #C4CADC;
  text-decoration: none;
  font-size: 0.94rem;
  border-left: 2px solid transparent;
}
.sidebar__nav a:hover { background: var(--navy-soft); color: #fff; }
.sidebar__nav a.is-active { background: var(--navy-soft); color: #fff; border-left-color: var(--gold); }

.sidebar__user {
  border-top: 1px solid rgba(255,255,255,0.12);
  padding-top: 1rem;
  font-size: 0.85rem;
}
.sidebar__user-name { color: #E7E9F0; margin-bottom: 0.35rem; }
.sidebar__logout { color: #9AA2BC; text-decoration: none; }
.sidebar__logout:hover { color: #fff; }

.main-wrapper { flex-grow: 1; padding: 2.25rem 2.75rem; max-width: none; }

.content--narrow { max-width: 560px; }

.content__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.content__header-actions { display: flex; gap: 0.6rem; }

/* ---------- Summary cards ---------- */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.summary-card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.summary-card__label { font-size: 0.82rem; color: var(--ink-soft); }
.summary-card__value { font-family: var(--font-mono); font-size: 1.4rem; }
.summary-card__hint { font-size: 0.78rem; color: var(--ink-soft); }
.summary-card.is-positive .summary-card__value { color: var(--gain); }
.summary-card.is-negative .summary-card__value { color: var(--loss); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; background: var(--paper-raised); border: 1px solid var(--line); border-radius: 4px; }
.table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.table th, .table td { padding: 0.55rem 0.6rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { font-weight: 600; color: var(--ink-soft); font-size: 0.76rem; text-transform: none; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #FBFAF6; }
.table .num { font-family: var(--font-mono); text-align: right; }
.table .text-positive { color: var(--gain); }
.table .text-negative { color: var(--loss); }
.table__actions form { display: flex; gap: 0.4rem; }

.group-header td {
  background: var(--gold-soft);
  padding: 0.6rem 0.9rem;
  white-space: normal;
}
.group-header__inner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.group-header:not(:first-child) td { border-top: 2px solid var(--line); }
.group-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.group-toggle__arrow { display: inline-block; width: 0.9em; color: var(--gold); }
.group-header__totals {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.group-header__update {
  margin-left: auto;
}
.group-child td { background: #FBFAF6; }
.group-child__name { color: var(--ink-soft); padding-left: 1.75rem !important; }
.group-child.is-sald td,
tr.is-sald td:not(.table__actions) { opacity: 0.65; }

/* ---------- Rad-åtgärder: sälj / ta bort ---------- */
.table__actions { display: flex; align-items: center; gap: 0.3rem; white-space: nowrap; }
.inline-form { display: inline-flex; margin: 0; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0;
}
.icon-btn:hover { background: var(--paper); }
.icon-btn--sell { color: var(--gain); border-color: var(--gain); }
.icon-btn--sell:hover { background: var(--gain-bg); }
.icon-btn--danger { color: var(--loss); border-color: var(--loss); }
.icon-btn--danger:hover { background: var(--loss-bg); }

.badge--sald { background: var(--line); color: var(--ink-soft); }

/* ---------- Historik: färgad radbakgrund efter resultat ---------- */
.table tbody tr.row-vinst td { background: var(--gain-bg); }
.table tbody tr.row-forlust td { background: var(--loss-bg); }
.table tbody tr.row-neutral td { background: #FCEFDC; }
.table tbody tr.row-vinst:hover td { background: #D9EBE2; }
.table tbody tr.row-forlust:hover td { background: #EFD7CF; }
.table tbody tr.row-neutral:hover td { background: #FBE6C4; }

/* ---------- Historik: resultat per aktie ---------- */
.per-aktie-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
}
.per-aktie-card {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: var(--paper-raised);
}
.per-aktie-card__namn { font-weight: 600; }
.per-aktie-card__resultat { font-family: var(--font-mono); font-size: 0.95rem; }
.per-aktie-card.is-positive { background: var(--gain-bg); border-color: var(--gain); }
.per-aktie-card.is-positive .per-aktie-card__resultat { color: var(--gain); }
.per-aktie-card.is-negative { background: var(--loss-bg); border-color: var(--loss); }
.per-aktie-card.is-negative .per-aktie-card__resultat { color: var(--loss); }
.per-aktie-card.is-neutral { background: #FCEFDC; border-color: var(--gold); }

/* ---------- Sälj-modal (dialog) ---------- */
dialog.modal {
  border: none;
  border-radius: 6px;
  padding: 0;
  width: 100%;
  max-width: 420px;
  background: var(--paper);
}
dialog.modal::backdrop { background: rgba(24, 34, 56, 0.55); }
dialog.modal form { padding: 1.75rem; display: flex; flex-direction: column; gap: 1rem; }
dialog.modal h2 { font-size: 1.2rem; margin-bottom: 0.15rem; }
.modal__subtitle { margin: 0; color: var(--ink-soft); font-size: 0.88rem; }
.modal__actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 0.25rem; }

dialog.modal--wide { max-width: 640px; }
.modal__inner { padding: 1.5rem 1.75rem 1.75rem; }
.modal__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.modal__header h2 { margin: 0; }
.chart-canvas-wrap { position: relative; height: 320px; }

.sell-preview {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
}
.sell-preview__row { display: flex; justify-content: space-between; gap: 1rem; }
.sell-preview__row--total { border-top: 1px solid var(--line); padding-top: 0.4rem; font-size: 1rem; }

.badge { font-size: 0.78rem; padding: 0.15rem 0.55rem; border-radius: 3px; }
.badge--pending { background: var(--gold-soft); color: var(--gold); }
.badge--approved { background: var(--gain-bg); color: var(--gain); }
.badge--rejected { background: var(--loss-bg); color: var(--loss); }

.muted { color: var(--ink-soft); }

.empty-state {
  background: var(--paper-raised);
  border: 1px dashed var(--line);
  border-radius: 4px;
  padding: 3rem 1rem;
  text-align: center;
  color: var(--ink-soft);
}
.empty-state p { margin-bottom: 1rem; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 1rem; }
.form.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1.75rem;
}
.form label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.88rem; color: var(--ink-soft); }
.form__row--split { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.field-hint { font-size: 0.78rem; color: var(--ink-soft); font-weight: 400; }

/* ---------- Autocomplete för tickerförslag ---------- */
.autocomplete-field { position: relative; }
.autocomplete-suggestions {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 6px 16px rgba(24, 34, 56, 0.12);
  max-height: 220px;
  overflow-y: auto;
}
.autocomplete-suggestions__item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: none;
  border-bottom: 1px solid var(--line);
  background: none;
  font-family: var(--font-body);
  font-size: 0.88rem;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.autocomplete-suggestions__item:last-child { border-bottom: none; }
.autocomplete-suggestions__item:hover { background: var(--paper); }
.autocomplete-suggestions__item span { font-family: var(--font-mono); font-size: 0.8rem; color: var(--ink-soft); white-space: nowrap; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], select {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--ink);
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
}
input:focus, select:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
  border-color: var(--gold);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.6rem 1.1rem;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: var(--paper-raised);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn:hover { background: var(--paper); }
.btn--primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn--primary:hover { background: var(--navy-soft); border-color: var(--navy-soft); }
.btn--danger { background: transparent; border-color: var(--loss); color: var(--loss); }
.btn--danger:hover { background: var(--loss-bg); }
.btn--small { padding: 0.3rem 0.55rem; font-size: 0.78rem; }
.btn--block { width: 100%; }

/* ---------- Alerts ---------- */
.alert { border-radius: 4px; padding: 0.85rem 1rem; margin-bottom: 1.25rem; font-size: 0.9rem; }
.alert--error { background: var(--loss-bg); color: var(--loss); }
.alert--success { background: var(--gain-bg); color: var(--gain); }
.alert ul { margin: 0; padding-left: 1.1rem; }

/* ---------- Auth pages (login/register/setup) ---------- */
.auth-body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  font-family: var(--font-body);
}
.auth-card {
  background: var(--paper);
  width: 100%;
  max-width: 400px;
  padding: 2.5rem;
  border-radius: 6px;
}
.auth-card__brand {
  display: flex; align-items: center; gap: 0.6rem;
  margin-bottom: 1.5rem;
  font-family: var(--font-display);
  color: var(--ink-soft);
}
.auth-card h1 { margin-bottom: 1.25rem; }
.auth-note { font-size: 0.88rem; color: var(--ink-soft); margin-top: 1.25rem; }

@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 1rem 1.25rem; }
  .sidebar__nav { display: flex; flex-grow: 0; }
  .sidebar__user { display: none; }
  .main-wrapper { padding: 1.5rem; }
  .summary-cards { grid-template-columns: 1fr; }
  .form__row--split { grid-template-columns: 1fr; }
}