/* QR Tracker — POC. Bez zależności, bez frameworka CSS. */

:root {
  --ink: #14181d;
  --ink-soft: #3d444c;
  --muted: #6d7268;
  --paper: #eff0ec;
  --surface: #ffffff;
  --line: #dcded6;
  --line-soft: #e8e9e4;
  --pine: #14584a;
  --pine-soft: #e4ede9;
  --clay: #8a4a12;
  --clay-soft: #f6ecdf;
  --red: #98342c;
  --radius: 3px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--pine); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--ink); }

h1 { font-size: 1.6rem; letter-spacing: -0.02em; margin: 0 0 .25rem; }
h2 { font-size: .95rem; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); margin: 0 0 .9rem; font-weight: 600; }
code, .mono { font-family: var(--mono); font-size: .88em; }

/* ---------- Znak firmowy: siatka modułów jak w kodzie QR ---------- */
.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  width: 22px; height: 22px;
  flex: none;
}
.brand-mark span { background: var(--line); border-radius: 1px; }
.brand-mark span:nth-child(1), .brand-mark span:nth-child(3),
.brand-mark span:nth-child(5), .brand-mark span:nth-child(7),
.brand-mark span:nth-child(9) { background: var(--pine); }
.brand-mark-lg { width: 34px; height: 34px; gap: 3px; margin-bottom: 1rem; }

/* ---------- Górny pasek ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  padding: .85rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--ink); }
.brand-text { font-weight: 650; letter-spacing: -0.01em; }
.brand-text em { font-style: normal; font-family: var(--mono); font-size: .7rem; color: var(--muted); margin-left: .45rem; }
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.topbar nav a { text-decoration: none; color: var(--ink-soft); font-weight: 500; }
.topbar nav a:hover { color: var(--ink); }
.topbar nav .signout { color: var(--muted); font-size: .9rem; }

/* ---------- Układ ---------- */
.wrap { max-width: 1080px; margin: 0 auto; padding: 1.75rem 1.5rem 3rem; }
.wrap-narrow { max-width: 420px; padding-top: 4rem; }
.foot { max-width: 1080px; margin: 0 auto; padding: 0 1.5rem 2.5rem; color: var(--muted); font-size: .8rem; }

.page-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1.5rem;
}
.eyebrow { font-family: var(--mono); font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.lede { color: var(--ink-soft); margin: .2rem 0 0; max-width: 62ch; }
.head-actions { display: flex; gap: .5rem; }

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

.split { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.split-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; }

/* ---------- Przyciski ---------- */
.btn {
  display: inline-block; padding: .5rem .9rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: .9rem; font-weight: 500;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-soft); color: var(--ink); }
.btn-primary { background: var(--pine); border-color: var(--pine); color: #fff; }
.btn-primary:hover { background: #0f463b; border-color: #0f463b; color: #fff; }
.btn-ghost { border-color: transparent; color: var(--muted); }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; border-color: var(--red); }
.btn-block { display: block; width: 100%; text-align: center; margin-top: 1.25rem; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--pine); outline-offset: 2px;
}

/* ---------- Formularze ---------- */
input[type=text], input[type=url], input[type=email], input[type=password],
input[type=search], input[type=datetime-local], select, textarea {
  width: 100%; padding: .55rem .65rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: .95rem;
}
input:focus, select:focus, textarea:focus { border-color: var(--pine); outline: none; box-shadow: 0 0 0 3px var(--pine-soft); }
label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .3rem; }
.field { margin-bottom: 1.1rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.hint { color: var(--muted); font-size: .82rem; margin: .35rem 0 0; }
.err { color: var(--red); font-size: .82rem; margin: .35rem 0 0; font-weight: 500; }
.warn {
  margin: .5rem 0 0; padding: .55rem .7rem; font-size: .82rem;
  background: var(--clay-soft); border-left: 2px solid var(--clay); color: var(--clay);
}
.form-actions { display: flex; gap: .6rem; padding-top: .4rem; }
.slug-input { display: flex; gap: .4rem; align-items: center; }
.slug-input .prefix { font-family: var(--mono); font-size: .8rem; color: var(--muted); white-space: nowrap; }
.slug-input input { font-family: var(--mono); }
.search { display: flex; gap: .4rem; }
.search input { min-width: 240px; }

/* ---------- Komunikaty ---------- */
.alert { padding: .7rem .9rem; border-radius: var(--radius); font-size: .9rem; margin: 0 0 1.25rem; }
.alert-ok { background: var(--pine-soft); border-left: 2px solid var(--pine); color: #0f463b; }
.alert-error { background: #fbe9e7; border-left: 2px solid var(--red); color: var(--red); }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 3rem 1.5rem; text-align: center; }
.empty p { margin: 0 0 .4rem; color: var(--muted); }
.empty .btn { margin-top: 1rem; }
.empty-inline { color: var(--muted); font-size: .9rem; margin: .2rem 0 0; }

/* ---------- Tabele ---------- */
.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.grid th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 600; padding: .7rem .9rem; border-bottom: 1px solid var(--line);
}
.grid td { padding: .8rem .9rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.grid tbody tr:last-child td { border-bottom: none; }
.grid tbody tr:hover { background: #fafbf9; }
.grid-compact td, .grid-compact th { padding: .5rem .9rem; }
.num { text-align: right; }
.small { font-size: .82rem; }
.sub { display: block; color: var(--muted); font-size: .76rem; margin-top: .15rem; }
.strong-link { font-weight: 600; text-decoration: none; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { white-space: nowrap; text-align: right; }
.actions a { margin-left: .8rem; font-size: .85rem; }
.slug { background: var(--paper); padding: .15rem .4rem; border-radius: 2px; }

.pill {
  display: inline-block; font-size: .7rem; font-weight: 600; padding: .12rem .45rem;
  border-radius: 2px; letter-spacing: .02em; white-space: nowrap;
}
.pill-active { background: var(--pine-soft); color: var(--pine); }
.pill-paused { background: #ecedea; color: var(--muted); }
.pill-expired { background: #f1e6e5; color: var(--red); }
.pill-scheduled { background: var(--clay-soft); color: var(--clay); }
.pill-bot { background: #ecedea; color: var(--muted); }

/* ---------- Kafelki liczbowe ---------- */
.stat-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1.25rem; overflow: hidden; }
.stat { background: var(--surface); padding: .9rem 1rem; }
.stat-label { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .3rem; }
.stat-value { display: block; font-size: 1.5rem; font-weight: 650; letter-spacing: -0.02em; }
.stat-value.small { font-size: .95rem; font-weight: 500; }
.stat-muted .stat-value { color: var(--muted); }

/* ---------- Wykres dzień po dniu ---------- */
/* Słupki wypełnione siatką modułów — nawiązanie do struktury kodu QR. */
.chart { display: flex; align-items: flex-end; gap: 2px; height: 190px; margin: 1rem 0 .4rem; }
.chart-col { flex: 1 1 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; min-width: 0; }
.chart-bar {
  width: 100%; max-width: 26px; min-height: 2px;
  background-color: var(--pine);
  background-image:
    linear-gradient(to right, rgba(255,255,255,.28) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,.28) 1px, transparent 1px);
  background-size: 6px 6px;
  border-radius: 1px;
}
.chart-col:hover .chart-bar { background-color: #0f463b; }
.chart-count { font-size: .65rem; color: var(--muted); height: 1rem; line-height: 1rem; order: -1; }
.chart-axis { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: .4rem; }
.range { display: flex; gap: .1rem; }
.range a { font-size: .8rem; padding: .2rem .55rem; border-radius: 2px; text-decoration: none; color: var(--muted); }
.range a.is-active { background: var(--ink); color: #fff; }
.toggle { border-top: 1px solid var(--line-soft); padding-top: .7rem; margin-top: 1rem; }

/* ---------- Zestawienia ---------- */
.breakdown { list-style: none; margin: 0; padding: 0; }
.breakdown li { display: grid; grid-template-columns: minmax(0, 7rem) 1fr auto; gap: .6rem; align-items: center; margin-bottom: .5rem; font-size: .85rem; }
.bd-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bd-track { background: var(--paper); height: 8px; border-radius: 1px; overflow: hidden; }
.bd-fill { display: block; height: 100%; background: var(--pine); opacity: .8; }
.bd-value { color: var(--muted); font-size: .8rem; }

/* ---------- Panel z kodem QR ---------- */
.qr-panel { text-align: center; }
.qr-panel h2 { text-align: left; }
.qr-preview { width: 190px; height: 190px; image-rendering: pixelated; border: 1px solid var(--line); border-radius: var(--radius); }
.qr-panel .dl { display: flex; gap: .5rem; justify-content: center; margin: .8rem 0; }
.qr-panel hr { border: none; border-top: 1px solid var(--line-soft); margin: 1.4rem 0 1rem; }
.qr-panel .hint, .qr-panel form { text-align: left; }
.qr-inline { display: flex; gap: 2rem; align-items: center; justify-content: space-between; }
.qr-inline .dl { display: flex; gap: .5rem; margin-top: 1rem; }
.qr-inline .hint { max-width: 52ch; }

/* ---------- Logowanie i komunikaty publiczne ---------- */
.login-card, .message-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 2rem;
}
.message-card { text-align: center; max-width: 460px; margin: 4rem auto; }
.message-card .brand-mark-lg { margin: 0 auto 1rem; }
.message-card p { color: var(--muted); }
.login-card .lede { margin-bottom: 1.5rem; font-size: .9rem; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .split, .split-3, .field-row { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .qr-inline { flex-direction: column; align-items: flex-start; }
  .truncate { max-width: 150px; }
  .chart-count { display: none; }
  .grid, .grid thead, .grid tbody, .grid th, .grid td, .grid tr { display: block; }
  .grid thead { display: none; }
  .grid tr { border-bottom: 1px solid var(--line); padding: .6rem 0; }
  .grid td { border: none; padding: .25rem .9rem; }
  .actions { text-align: left; }
  .actions a { margin: 0 1rem 0 0; }
}

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