/* CRM sukcesyjny — style. Mobile-first, bez kroku budowania. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #1c2330;
  --muted: #667085;
  --primary: #1d4ed8;
  --primary-soft: #e8efff;
  --danger: #c62828;
  --danger-soft: #fdecec;
  --warn: #b45309;
  --warn-soft: #fff4e0;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-2: #1f2430;
    --border: #2a3140;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --primary: #6d9bff;
    --primary-soft: #1b2a4a;
    --danger: #ff6b6b;
    --danger-soft: #3a1c1c;
    --warn: #f5b041;
    --warn-soft: #3a2c12;
    --ok: #4ade80;
    --ok-soft: #12301d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
.small { font-size: .875rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }

/* ---------- układ ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.topbar .search { flex: 1; max-width: 480px; margin-left: auto; position: relative; }
.topbar .search input { width: 100%; padding: .5rem .75rem; }
.topnav { display: none; gap: .25rem; }
.topnav a { padding: .4rem .7rem; border-radius: 8px; color: var(--text); }
.topnav a.active { background: var(--primary-soft); color: var(--primary); }
.topnav a:hover { text-decoration: none; background: var(--surface-2); }
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: 70vh; overflow: auto; z-index: 30;
}
.search-results:empty { display: none; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: .72rem; color: var(--muted); gap: 2px;
}
.bottomnav a .ico { font-size: 1.3rem; line-height: 1; }
.bottomnav a.active { color: var(--primary); }
.bottomnav a:hover { text-decoration: none; }
.bottomnav .add .ico {
  background: var(--primary); color: #fff; width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
}

@media (min-width: 900px) {
  body { padding-bottom: 24px; }
  .bottomnav { display: none; }
  .topnav { display: flex; }
  .topbar { padding: .6rem 24px; }
  main { padding: 24px; }
}

.page-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; margin-bottom: 1rem;
}
.page-head h1 { margin: 0; flex: 1 1 auto; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; }
@media (min-width: 900px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-main { grid-template-columns: 2fr 1fr; align-items: start; }
}

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.card > h2:first-child, .card-head { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.card.flush { padding: 0; }
.card.flush .card-head { padding: 12px 16px 0; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; color: var(--text);
}
.stat:hover { text-decoration: none; border-color: var(--primary); }
.stat .num { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat .lbl { font-size: .8rem; color: var(--muted); }
.stat.danger .num { color: var(--danger); }

/* ---------- listy ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: var(--text);
}
a.row:hover { background: var(--surface-2); text-decoration: none; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: .85rem; color: var(--muted); }
.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .9rem;
}
.empty { padding: 16px; color: var(--muted); text-align: center; }
.section-label {
  font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: 12px 16px 4px;
}
.section-label.danger { color: var(--danger); }

/* zadania */
.task { display: flex; align-items: flex-start; gap: 10px; padding: 10px 16px; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task .check {
  flex: none; width: 28px; height: 28px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--border); background: var(--surface); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: .9rem; color: transparent;
}
.task .check:hover { border-color: var(--ok); color: var(--ok); }
.task.done .check { background: var(--ok); border-color: var(--ok); color: #fff; }
.task .body { flex: 1; min-width: 0; }
.task-title { font-weight: 500; color: var(--text); }
.task .meta { font-size: .82rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 10px; }
.task .meta .overdue { color: var(--danger); font-weight: 600; }
.task .tools { display: flex; gap: 4px; flex: none; }
.task .tools form { margin: 0; }

/* lista kontrolna */
.check-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 16px; }
.check-item .box {
  flex: none; width: 26px; height: 26px; border-radius: 6px; border: 2px solid var(--border);
  background: var(--surface); cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: transparent; font-weight: 700;
}
.check-item.done .box { background: var(--ok); border-color: var(--ok); color: #fff; }
.check-item.done .name, .check-item.na .name { color: var(--muted); text-decoration: line-through; }
.check-item .grow { flex: 1; min-width: 0; }
.check-item .hint { font-size: .82rem; color: var(--muted); }
.check-item .tools { display: flex; gap: 4px; }
.check-item .tools form { margin: 0; }
.check-item .hint span + span::before { content: " · "; }
@media (max-width: 600px) {
  .check-item { padding: 10px 12px; gap: 8px; }
  .check-item .tools { gap: 0; }
  .check-item .tools .btn.sm { padding: .25rem .4rem; }
}

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--ok); }

/* etapy */
.stages { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.stages form { margin: 0; flex: none; }
.stage-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 99px; padding: .35rem .8rem; font-size: .85rem; cursor: pointer; white-space: nowrap;
}
.stage-btn.past { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.stage-btn.current { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }

/* oś czasu */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--border); }
.timeline li:first-child { border-top: 0; }
.timeline .ico { flex: none; width: 28px; text-align: center; }
.timeline .grow { flex: 1; min-width: 0; }
.timeline .body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.timeline li.system { font-size: .88rem; color: var(--muted); padding-top: 6px; padding-bottom: 6px; }

/* ---------- etykiety ---------- */
.badge {
  display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.primary { background: var(--primary-soft); color: var(--primary); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: baseline; }

/* ---------- formularze ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=search],
input[type=date], input[type=time], input[type=datetime-local], input[type=number], select, textarea {
  width: 100%; padding: .6rem .75rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox] { width: 20px; height: 20px; vertical-align: middle; }
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.field.check label { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.field .help { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.field .error, .errorlist { color: var(--danger); font-size: .85rem; margin: 4px 0 0; padding: 0; list-style: none; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.form-grid { display: grid; gap: 0 16px; }
@media (min-width: 700px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .full { grid-column: 1 / -1; } }
fieldset { border: 0; padding: 0; margin: 0 0 8px; }
legend { font-weight: 700; margin-bottom: 8px; font-size: 1rem; padding: 0; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.form-actions .spacer { flex: 1; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form > * { flex: 1 1 140px; }
.inline-form > button { flex: 0 0 auto; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input[type=search] { flex: 1 1 200px; width: auto; }
.filters select { width: auto; flex: 0 1 auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: .5rem 1rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.sm { min-height: 34px; padding: .25rem .65rem; font-size: .85rem; }
.btn.icon { min-height: 34px; width: 34px; padding: 0; font-size: 1rem; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.quick-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 0; }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.tabs a { padding: .5rem .8rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 0; }
dl.props dt { color: var(--muted); font-size: .9rem; }
dl.props dd { margin: 0; overflow-wrap: anywhere; }

.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li { padding: 10px 14px; border-radius: 10px; margin-bottom: 8px; background: var(--primary-soft); }
.messages li.success { background: var(--ok-soft); color: var(--ok); }
.messages li.error { background: var(--danger-soft); color: var(--danger); }
.messages li.warning { background: var(--warn-soft); color: var(--warn); }

details > summary { cursor: pointer; font-weight: 600; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "＋ "; color: var(--primary); }
details[open] > summary::before { content: "－ "; }

.auth-wrap { max-width: 420px; margin: 8vh auto 0; }
.qr svg { width: 220px; height: 220px; background: #fff; padding: 8px; border-radius: 8px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.pagination { display: flex; gap: 8px; justify-content: center; align-items: center; margin: 12px 0; }
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { opacity: 1; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.hide-mobile { display: none; }
@media (min-width: 700px) { .hide-mobile { display: initial; } .hide-desktop { display: none; } }
