/* ============================================================
   Moje Finanse — design system „private banking”
   Tokeny CSS, zero JS, zero inline style (CSP: style-src 'self').
   ============================================================ */

/* ---------- Fonty (self-hosted, variable WOFF2) ---------- */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("/static/fonts/inter-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("/static/fonts/inter-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 500 600;
  font-display: swap;
  src: url("/static/fonts/fraunces-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 500 600;
  font-display: swap;
  src: url("/static/fonts/fraunces-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- Tokeny ---------- */
:root {
  --bg: #101418;
  --surface: #171c22;
  --surface-2: #1d232b;      /* hover wierszy, tło pól */
  --border: #262d36;
  --text: #e8eaed;
  --text-2: #9aa3ad;
  --accent: #c9a96a;         /* szampańskie złoto — oszczędnie */
  --accent-dim: #8a744a;
  --pos: #4caf7d;            /* zysk */
  --neg: #d26a5c;            /* wypłata / strata */

  --font-ui: "Inter", ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  --font-display: "Fraunces", "Source Serif 4", Georgia, serif;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --radius: 6px;
  --radius-s: 4px;
  --container: 1200px;
  --nav-h: 48px;
  --transition: 120ms ease;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f5f1;
    --surface: #ffffff;
    --surface-2: #f1efe9;
    --border: #e4e1d8;
    --text: #1c2127;
    --text-2: #5d6570;
    --accent: #8f7434;
    --accent-dim: #b59a5e;
    --pos: #2e7d54;
    --neg: #b04a3c;
  }
}

/* ---------- Reset / baza ---------- */
*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  font-feature-settings: "cv05" 1; /* Inter: czytelniejsze „l” */
}

main.container {
  max-width: var(--container);
  margin: 0 auto;
  padding: var(--s5) var(--s4) var(--s7);
}

a { color: var(--text); text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; transition: text-decoration-color var(--transition); }
a:hover { text-decoration-color: var(--accent); }

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

::selection { background: var(--accent); color: var(--bg); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- Typografia ---------- */
h1 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: 0.01em;
  margin: 0 0 var(--s5);
}

h2 {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-2);
  margin: var(--s6) 0 var(--s3);
}

h3 {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  margin: var(--s4) 0 var(--s2);
}

small { font-size: 12px; color: var(--text-2); }
p { margin: var(--s3) 0; }
code { font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-s); padding: 1px 5px; }

section { margin-bottom: var(--s6); }

/* Kwoty i kolumny liczbowe */
.amount {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.neg { color: var(--neg); }
.zysk { color: var(--pos); }

/* ---------- Nawigacja ---------- */
header.site {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

header.site nav {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--s4);
  min-height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: var(--s5);
  flex-wrap: wrap;
}

.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.01em;
  text-decoration: none;
}
.brand::first-letter { color: var(--accent); }

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--s2);
  list-style: none;
  margin: 0;
  padding: 0;
  flex-wrap: wrap;
}

.nav-links a {
  display: inline-block;
  padding: 0 var(--s3);
  line-height: calc(var(--nav-h) - 2px);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}
.nav-links a:hover { color: var(--text); }
.nav-links a[aria-current="page"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.nav-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s3);
}
.nav-user .login-name { font-size: 12.5px; color: var(--text-2); }

/* ---------- Przyciski ---------- */
button, a[role="button"] {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  padding: 10px var(--s4);
  border-radius: var(--radius-s);
  border: 1px solid var(--accent-dim);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
button:hover, a[role="button"]:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

button.secondary, a[role="button"].secondary,
button.outline, a[role="button"].outline {
  border-color: var(--border);
  color: var(--text-2);
}
button.secondary:hover, a[role="button"].secondary:hover,
button.outline:hover, a[role="button"].outline:hover {
  border-color: var(--text-2);
  color: var(--text);
  background: var(--surface-2);
}

.inline-form { display: inline; margin: 0; }

.logout-button {
  padding: 6px var(--s3);
  font-size: 12.5px;
}

/* ---------- Tabele ---------- */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 13.5px;
}

th, td {
  padding: 10px var(--s3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

thead th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
  background: var(--surface-2);
  white-space: nowrap;
}
thead th a { color: var(--text-2); text-decoration: none; }
thead th a:hover { color: var(--accent); }

tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

tfoot th {
  font-size: 13.5px;
  border-bottom: none;
  border-top: 1px solid var(--accent-dim);
  background: var(--surface-2);
}

.actions { white-space: nowrap; text-align: right; }
.actions a[role="button"], .actions button {
  padding: 5px 10px;
  font-size: 12px;
}

/* ---------- Badge typów operacji ---------- */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1;
  padding: 4px 8px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
  color: var(--text-2);
  white-space: nowrap;
}
.badge-zysk { border-color: color-mix(in srgb, var(--pos) 55%, transparent); color: var(--pos); }
.badge-wyplata { border-color: color-mix(in srgb, var(--neg) 55%, transparent); color: var(--neg); }
.badge-korekta { border-style: dashed; }

/* ---------- Formularze ---------- */
label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-2);
  margin: var(--s4) 0 var(--s1);
}

input, select {
  width: 100%;
  height: 36px;
  padding: 0 var(--s3);
  font-family: var(--font-ui);
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  transition: border-color var(--transition);
}
input:hover, select:hover { border-color: var(--text-2); }
input:focus, select:focus { outline: none; border-color: var(--accent); }

select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 16px) 15px, calc(100% - 11px) 15px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: var(--s6); }

input[type="date"], input[type="month"] { color-scheme: dark; }
@media (prefers-color-scheme: light) {
  input[type="date"], input[type="month"] { color-scheme: light; }
}

form button, form a[role="button"] { margin-top: var(--s5); margin-right: var(--s2); }

.field-error {
  display: block;
  color: var(--neg);
  font-size: 12.5px;
  margin-top: var(--s1);
}

.error-message {
  color: var(--neg);
  font-size: 13.5px;
  border: 1px solid color-mix(in srgb, var(--neg) 45%, transparent);
  border-radius: var(--radius-s);
  padding: var(--s3) var(--s4);
  background: color-mix(in srgb, var(--neg) 8%, transparent);
}

/* Karta formularza (dodawanie na listach, edycja) */
article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s5);
  margin: var(--s5) 0;
  max-width: 560px;
}
article h2 { margin-top: 0; }

/* ---------- Filtry listy operacji ---------- */
.filters {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s4) var(--s4) var(--s4);
  margin-bottom: var(--s5);
}
.filters fieldset {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--s3);
  border: none;
  padding: 0;
  margin: 0;
}
.filters label { margin: 0; }
.filters label input, .filters label select { margin-top: var(--s1); }
.filters button, .filters a[role="button"] { margin-top: var(--s4); margin-right: var(--s2); }

/* ---------- Paginacja ---------- */
.pagination {
  display: flex;
  gap: var(--s4);
  align-items: center;
  justify-content: center;
  margin-top: var(--s4);
  font-size: 13px;
  color: var(--text-2);
}

/* ---------- Sygnatura: nagłówek-wyciąg na dashboardzie ---------- */
.statement-head { margin: var(--s4) 0 var(--s6); }

.statement-head .eyebrow {
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-2);
  margin: 0 0 var(--s3);
}

.statement-totals {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s4) var(--s7);
  align-items: baseline;
  padding-bottom: var(--s4);
  border-bottom: 1px solid var(--border);
  position: relative;
}
.statement-totals::after {
  content: "";
  position: absolute;
  left: 0; bottom: -1px;
  width: 96px; height: 1px;
  background: var(--accent);
}

.statement-total { display: flex; align-items: baseline; gap: var(--s2); }
.statement-total .value {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 34px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.005em;
}
.statement-total .value.neg { color: var(--neg); }
.statement-total .currency {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--accent);
}
.statement-total .placeholder {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--text-2);
}

/* ---------- Stany puste ---------- */
.empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: var(--s6) var(--s5);
  text-align: center;
  color: var(--text-2);
}
.empty p { margin: 0 0 var(--s4); }

/* ---------- Logowanie ---------- */
.login-box {
  max-width: 360px;
  margin: 11vh auto 0;
  padding: var(--s6);
}
.login-box h1 { font-size: 24px; margin-bottom: var(--s2); }
.login-box .brand-rule {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, var(--accent), transparent 70%);
  margin: 0 0 var(--s5);
}
.login-box button { width: 100%; margin-top: var(--s5); }
.login-box .error-message { margin-top: var(--s4); }

/* ---------- Strona błędu ---------- */
.error-page { max-width: 480px; margin-top: var(--s7); text-align: left; }
.error-page .code {
  font-family: var(--font-display);
  font-size: 56px;
  font-weight: 500;
  color: var(--text-2);
  margin: 0;
  line-height: 1;
}

/* ---------- Wykres SVG (raport) ---------- */
.chart { max-width: 100%; height: auto; display: block; margin-bottom: var(--s5); }
.chart-frame { fill: none; stroke: var(--border); }
.chart-zero { stroke: var(--border); stroke-dasharray: 4; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.chart-dot { fill: var(--accent); }
.chart-label { fill: var(--text-2); font-family: var(--font-ui); font-size: 11px; }

/* Skróty pod tabelami / meta-linia listy */
.meta-line { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s4); flex-wrap: wrap; color: var(--text-2); font-size: 13px; }

/* ---------- Responsywność ---------- */
@media (max-width: 640px) {
  main.container { padding: var(--s4) var(--s3) var(--s6); }
  header.site nav { gap: var(--s3); padding: var(--s2) var(--s3); }
  .nav-user { margin-left: 0; width: 100%; justify-content: flex-end; }
  .nav-links a { line-height: 36px; padding: 0 var(--s2); }
  .statement-total .value { font-size: 27px; }
  .statement-totals { gap: var(--s3) var(--s5); }
  th, td { padding: 8px 10px; }
  article { padding: var(--s4); }
}

/* ---------- Druk: zawsze jasny wariant ---------- */
@media print {
  :root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f2f0ea;
    --border: #cfccc2;
    --text: #111418;
    --text-2: #4d545c;
    --accent: #8f7434;
    --accent-dim: #b59a5e;
    --pos: #2e7d54;
    --neg: #b04a3c;
  }
  header.site, .no-print, form, .actions, .pagination { display: none !important; }
  body { background: #fff; color: var(--text); font-size: 12px; }
  main.container { max-width: 100%; padding: 0; }
  table { border-radius: 0; }
  a { text-decoration: none; color: var(--text); }
}
