:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --ok: #059669;
  --discord: #5865f2;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #181b21;
    --text: #e6e8eb;
    --muted: #9aa1ac;
    --line: #2a2e36;
    --accent: #818cf8;
    --accent-soft: #23264a;
    --warn: #fbbf24;
    --warn-soft: #3a2e10;
    --danger: #f87171;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .9rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; font-weight: 400; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .8rem 1rem; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: .5rem; }
.brand:hover { text-decoration: none; }
.logo {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: .75rem; font-weight: 800;
}
.me { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.me img { border-radius: 50%; }
.me form { margin: 0; }

main { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.2rem; margin-bottom: 1rem;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: .5rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.2rem; }

.btn {
  display: inline-flex; align-items: center; gap: .5rem; padding: .55rem 1rem;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); margin-left: auto; }
.btn.discord { background: var(--discord); border-color: var(--discord); color: #fff; justify-content: center; width: 100%; padding: .8rem; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
button.link:hover { text-decoration: underline; }
form.inline { display: inline; margin: 0; }

.flash { background: var(--accent-soft); border-radius: 8px; padding: .7rem 1rem; margin-bottom: 1rem; }
.error { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: .7rem 1rem; margin: 1rem 0; }

.login { max-width: 400px; margin: 10vh auto 0; text-align: center; padding: 2rem; }
.login h1 { margin-bottom: .5rem; }
.login p { margin-bottom: 1.5rem; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; }
.stat .label { display: block; color: var(--muted); font-size: .85rem; }
.stat .value { display: block; font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat:first-child .value { color: var(--accent); }

.alerts { margin-bottom: 1rem; }
.alert { background: var(--warn-soft); color: var(--text); border-left: 4px solid var(--warn); border-radius: 8px; padding: .7rem 1rem; margin-bottom: .5rem; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.bars { list-style: none; margin: 0; padding: 0; }
.bars li { margin-bottom: .7rem; }
.bar-label { display: flex; justify-content: space-between; font-size: .9rem; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--accent-soft); border-radius: 4px; overflow: hidden; margin-top: .25rem; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

.upcoming { list-style: none; margin: 0; padding: 0; }
.upcoming li { display: grid; grid-template-columns: 4.5rem 1fr auto; gap: .5rem; padding: .45rem 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.upcoming li:last-child { border-bottom: 0; }
.upcoming .date { color: var(--muted); font-size: .88rem; }
.upcoming .amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.upcoming li.soon .date { color: var(--warn); font-weight: 600; }

.sort { font-size: .88rem; color: var(--muted); }
.sort a { margin-left: .5rem; color: var(--muted); }
.sort a.on { color: var(--accent); font-weight: 600; }

.table-wrap { overflow-x: auto; }
table.subs { width: 100%; border-collapse: collapse; }
.subs th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: .5rem; border-bottom: 1px solid var(--line); }
.subs td { padding: .7rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; font-variant-numeric: tabular-nums; }
.subs tfoot td { font-weight: 700; border-bottom: 0; }
.subs .num { text-align: right; }
.sub-name { font-weight: 600; color: var(--text); }
.tag { display: inline-block; font-size: .72rem; padding: .05rem .45rem; border-radius: 99px; background: var(--accent-soft); color: var(--accent); margin-left: .35rem; vertical-align: 1px; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.row-actions { text-align: right; white-space: nowrap; font-size: .88rem; }
.row-actions > * { margin-left: .6rem; }

.inactive { list-style: none; margin: 0; padding: 0; }
.inactive li { display: flex; gap: .8rem; align-items: baseline; padding: .4rem 0; border-bottom: 1px solid var(--line); }
.inactive li:last-child { border-bottom: 0; }
.inactive li a { text-decoration: line-through; color: var(--muted); }
.inactive form { margin-left: auto; font-size: .88rem; }

.empty { text-align: center; padding: 3rem 1.5rem; }
.empty p { max-width: 460px; margin: .5rem auto 1.5rem; }

.back { font-size: .9rem; }
.form-card { max-width: 640px; }
.form-card h1 { font-size: 1.3rem; margin-bottom: 1.2rem; }
.sub-form { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.sub-form .full { grid-column: 1 / -1; }
.sub-form label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; font-weight: 600; }
.sub-form input:not([type=checkbox]), .sub-form select, .sub-form textarea {
  font: inherit; font-weight: 400; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); width: 100%;
}
.sub-form input:focus, .sub-form select:focus, .sub-form textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.sub-form label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
.hint { font-weight: 400; color: var(--muted); font-size: .78rem; }
.field-error { font-weight: 400; color: var(--danger); font-size: .8rem; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .3rem; }

@media (max-width: 760px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .grid { grid-template-columns: 1fr; }
  .stat .value { font-size: 1.25rem; }
  .me span { display: none; }
  .sub-form { grid-template-columns: 1fr; }
  .subs thead { display: none; }
  .subs tr { display: grid; grid-template-columns: 1fr auto; padding: .7rem 0; border-bottom: 1px solid var(--line); }
  .subs td { border: 0; padding: .1rem 0; }
  .subs td:nth-child(1) { grid-column: 1 / -1; }
  .subs td:nth-child(4) { grid-column: 1; color: var(--muted); font-size: .88rem; }
  .subs td.row-actions { grid-column: 2; grid-row: 3; }
  .subs .row-actions > :first-child { margin-left: 0; }
  .subs tfoot tr { border-bottom: 0; }
  .subs tfoot td:last-child { grid-column: 1 / -1; }
}

/* Huvudknappar */
.head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.head-actions.center { justify-content: center; }

/* Import */
.import-form { display: flex; flex-direction: column; gap: 1rem; margin: 1.2rem 0; }
.drop {
  display: flex; flex-direction: column; align-items: center; gap: .4rem; padding: 1.6rem 1rem;
  border: 2px dashed var(--line); border-radius: var(--radius); background: var(--bg); cursor: pointer; text-align: center;
}
.drop:hover, .drop:focus-within { border-color: var(--accent); }
.drop input { max-width: 100%; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: .92rem; }
details textarea {
  width: 100%; margin-top: .6rem; font: .85rem/1.4 ui-monospace, monospace; padding: .6rem;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text);
}
.import-form .btn { align-self: flex-start; }
.howto { border-top: 1px solid var(--line); padding-top: 1rem; margin-top: .5rem; }
.howto ul { padding-left: 1.2rem; margin: .7rem 0; }
.howto li { margin-bottom: .3rem; font-size: .92rem; }

.review input:not([type=checkbox]), .review select {
  font: inherit; padding: .35rem .5rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text); width: 100%; min-width: 0;
}
.review input.price { width: 6rem; }
.review td { vertical-align: middle; }
.review td:first-child { width: 2rem; }
.review input[type=checkbox] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.review tr.dim td { opacity: .6; }
.badges { margin-top: .25rem; }
.badges .tag { margin: 0 .25rem 0 0; }
.tag.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.sample { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 760px) {
  .page-head { flex-wrap: wrap; gap: .8rem; }
  .review tr { grid-template-columns: 2rem 1fr 1fr; gap: .4rem; }
  .review td:nth-child(1) { grid-column: 1; grid-row: 1; }
  .review td:nth-child(2) { grid-column: 2 / -1; grid-row: 1; }
  .review td:nth-child(3) { grid-column: 2; }
  .review td:nth-child(4) { grid-column: 3; }
  .review td:nth-child(5) { grid-column: 2 / -1; }
  .review td:nth-child(6) { grid-column: 2 / -1; color: var(--muted); }
  .review input.price { width: 100%; }
}

/* Meny */
.nav { display: flex; gap: .2rem; margin-right: auto; margin-left: 1.5rem; }
.nav a { color: var(--muted); padding: .35rem .7rem; border-radius: 8px; font-size: .92rem; font-weight: 600; }
.nav a:hover { text-decoration: none; background: var(--bg); color: var(--text); }
.nav a.on { color: var(--accent); background: var(--accent-soft); }

/* Gmail */
.alert.info { background: var(--accent-soft); border-left-color: var(--accent); }
.facts { padding-left: 1.2rem; margin: 1rem 0 1.4rem; }
.facts li { margin-bottom: .35rem; }
code { font-size: .85em; background: var(--bg); padding: .1rem .35rem; border-radius: 4px; word-break: break-all; }
.suggest { list-style: none; margin: 0; padding: 0; }
.suggest li { display: grid; grid-template-columns: 1fr auto auto; gap: 1rem; align-items: center; padding: .8rem 0; border-bottom: 1px solid var(--line); }
.suggest li:last-child { border-bottom: 0; }
.s-price { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.s-actions { display: flex; gap: .4rem; align-items: center; margin: 0; }
.s-actions select { font: inherit; padding: .45rem .4rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
.s-actions .btn { padding: .45rem .8rem; }
.card-head .head-actions form { margin: 0; }
.card-head .btn.danger { margin-left: 0; }

@media (max-width: 760px) {
  .top { flex-wrap: wrap; }
  .nav { order: 3; width: 100%; margin: .2rem 0 0; }
  .suggest li { grid-template-columns: 1fr auto; }
  .s-actions { grid-column: 1 / -1; }
  .receipts td:nth-child(1) { grid-column: 1; grid-row: 1; color: var(--muted); font-size: .85rem; }
}
