:root {
  --bg: #f5f7f3;
  --surface: #ffffff;
  --surface-2: #eef2ea;
  --ink: #15211b;
  --ink-2: #46554c;
  --muted: #7d8c81;
  --line: #e2e8dd;
  --line-2: #cfd8c8;
  --green: #1b4332;
  --green-700: #123528;
  --green-500: #2d6a4f;
  --green-300: #95d5b2;
  --green-50: #e8f2eb;
  --amber-bg: #faf1df; --amber-fg: #8a5a13;
  --red: #9b2a22; --red-bg: #fbe9e7;
  --radius: 10px;
  --radius-lg: 14px;
  --font-display: "Bricolage Grotesque", "Hanken Grotesk", system-ui, sans-serif;
  --font-sans: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Spline Sans Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  border-top: 3px solid var(--green);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(rgba(27,67,50,.045) 1px, transparent 1px);
  background-size: 22px 22px;
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--green-500); text-decoration: none; transition: color .15s; }
a:hover { color: var(--green-700); }
.muted { color: var(--muted); font-size: .9em; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.02em; color: var(--ink); }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .85rem 1.75rem;
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.brand a { display: flex; align-items: center; gap: .55rem; color: var(--ink); font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; letter-spacing: -.01em; }
.brand-mark { width: 24px; height: 24px; color: var(--green); flex: none; }
.topbar nav { display: flex; gap: 1.5rem; }
.topbar nav a { position: relative; color: var(--ink-2); font-weight: 500; padding: .15rem 0; }
.topbar nav a:hover { color: var(--ink); }
.topbar nav a.active { color: var(--green); }
.topbar nav a.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: -.9rem; height: 2px; background: var(--green); }
.topbar .user { margin-left: auto; display: flex; align-items: center; gap: 1rem; }

/* ---------- layout ---------- */
main { max-width: 1140px; margin: 0 auto; padding: 2rem 1.75rem 4rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
h1 { font-size: 1.7rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 .85rem; }

/* ---------- cards / forms ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 1.2rem 1.4rem; margin-bottom: 1.4rem;
  box-shadow: 0 1px 2px rgba(21,33,27,.04), 0 6px 16px -12px rgba(21,33,27,.12);
}
.form label, .auth label { display: block; margin-bottom: 1rem; font-size: .82rem; font-weight: 500; color: var(--ink-2); }
.form .row { display: flex; gap: 1rem; }
.form .row label { flex: 1; }
.form .row label.f3 { flex: 3; } .form .row label.f1 { flex: 1; }
input, select, textarea {
  width: 100%; margin-top: .4rem; padding: .6rem .75rem;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius);
  color: var(--ink); font: inherit; font-size: 15px; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green-500); box-shadow: 0 0 0 3px var(--green-50); }
input::placeholder, textarea::placeholder { color: #aab4a8; }
textarea { resize: vertical; }
.form-actions { display: flex; gap: .75rem; margin-top: .5rem; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1.05rem; border: 1px solid var(--line-2); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; font-size: .92rem;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--green-300); background: var(--green-50); color: var(--green-700); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-700); border-color: var(--green-700); color: #fff; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; justify-content: center; padding: .7rem; }
.btn-file { cursor: pointer; font-size: .8rem; padding: .3rem .6rem; }
.file-hidden { display: none; }
.mw-480 { max-width: 480px; }
.mw-520 { max-width: 520px; }
.notes-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.copy-src { width: 100%; margin-top: .3rem; font-family: var(--mono, ui-monospace, monospace); font-size: .82rem; line-height: 1.5; padding: .7rem .9rem; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--surface-2, #f7f7f5); color: var(--ink); resize: vertical; }
button.link { background: none; border: none; padding: 0; color: var(--green-500); font: inherit; font-weight: 500; cursor: pointer; transition: color .15s; }
button.link:hover { color: var(--green-700); }
button.link.danger, .danger-btn { color: var(--red); }
button.link.danger:hover, .danger-btn:hover { color: #7a1f18; }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1.25rem; align-items: center; }
.filters input, .filters select { width: auto; margin-top: 0; flex: 0 1 auto; }
.filters input[type="search"] { flex: 1 1 240px; }

/* ---------- zakładki firm ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: .25rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--line); }
.tab { padding: .55rem .9rem; color: var(--muted); font-weight: 600; font-size: .9rem; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s, border-color .15s; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--green); border-bottom-color: var(--green); }
.tab-count { font-family: var(--font-mono); font-size: .72rem; background: var(--surface-2); color: var(--muted); padding: .05rem .4rem; border-radius: 999px; margin-left: .25rem; }
.tab.active .tab-count { background: var(--green); color: #fff; }

/* ---------- tabela ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: 0 1px 2px rgba(21,33,27,.04); }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { text-align: left; padding: .8rem .9rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid thead th { color: var(--muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; background: #fbfcfa; }
table.grid tbody tr { transition: background .12s; }
table.grid tbody tr:hover { background: var(--green-50); }
table.grid tbody tr:last-child td { border-bottom: none; }
.params { color: var(--muted); font-size: .85rem; max-width: 260px; font-family: var(--font-mono); }
.actions { white-space: nowrap; text-align: right; }
.actions a, .actions form { display: inline-block; margin-left: .7rem; }
.count { margin-top: .85rem; }

/* miniatury */
.thumb-cell { width: 60px; }
.thumb { width: 48px; height: 48px; border-radius: var(--radius); object-fit: cover; display: block; border: 1px solid var(--line); }
.thumb-empty { display: flex; align-items: center; justify-content: center; font-size: 1.3rem; color: var(--green-500); background: var(--green-50); }
.qty-badge { font-family: var(--font-mono); font-size: 1rem; color: var(--green-500); font-weight: 500; }

/* ---------- tagi ---------- */
.tag-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin: -.5rem 0 1.1rem; }
.tag-chip {
  display: inline-block; padding: .15rem .6rem; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); font-size: .78rem; font-weight: 500;
  border: 1px solid var(--line); transition: all .12s;
}
a.tag-chip:hover { background: var(--green-50); color: var(--green-700); border-color: var(--green-300); }
.tag-chip.active { background: var(--green); color: #fff; border-color: var(--green); }
.tag-chip.sm { font-size: .72rem; padding: .08rem .5rem; }
.row-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .35rem; }
.detail-tags { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .9rem; }

/* ---------- widok do druku / PDF ---------- */
.print-only { display: none; }
.print-table th, .print-table td { font-size: .82rem; padding: .45rem .55rem; }
@media print {
  body { border-top: none; background: #fff; color: #000; }
  .topbar, .no-print, .filters, .tabs, .tag-bar { display: none !important; }
  main { max-width: none; margin: 0; padding: 0; }
  .print-only { display: block; margin: 0 0 .6rem; font-size: 1.2rem; }
  .table-wrap { border: none; box-shadow: none; overflow: visible; }
  table.grid { font-size: 11px; }
  table.grid th { background: #eee !important; color: #000 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.grid th, table.grid td { border: 0.5px solid #bbb; }
  table.grid tbody tr:hover { background: none; }
  a { color: #000; text-decoration: none; }
}

/* ---------- statusy ---------- */
.status { display: inline-block; padding: .18rem .6rem; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; }
.status-dostepna, .status-aktywny, .status-wykonany { background: var(--green-50); color: var(--green); }
.status-zajeta, .status-wdrazany, .status-zaplanowany { background: var(--amber-bg); color: var(--amber-fg); }
.status-serwis { background: var(--red-bg); color: var(--red); }
.status-wycofana, .status-wycofany, .status-anulowany { background: var(--surface-2); color: var(--muted); }

/* ---------- flash ---------- */
.flash { padding: .75rem 1.1rem; border-radius: var(--radius); margin-bottom: 1.1rem; border: 1px solid transparent; font-weight: 500; }
.flash-error { background: var(--red-bg); border-color: #eccac6; color: var(--red); }
.flash-success { background: var(--green-50); border-color: var(--green-300); color: var(--green-700); }

/* ---------- logowanie ---------- */
.auth { max-width: 400px; margin: 9vh auto 0; }
.auth-head { text-align: center; margin-bottom: 1.75rem; }
.auth-head h1 { font-size: 2rem; }
.brand-mark-lg { width: 44px; height: 44px; color: var(--green); margin-bottom: .35rem; }
.subtitle { color: var(--muted); margin: .35rem 0 0; }
.auth .card { padding: 1.75rem; }

/* ---------- szczegóły maszyny ---------- */
.head-actions { display: flex; gap: .5rem; align-items: center; }
.head-actions form { display: inline; }
.detail-layout { display: grid; grid-template-columns: 1fr 320px; gap: 1.5rem; align-items: start; }
.detail-side .photo-card { padding: .5rem; position: sticky; top: 5rem; }
.photo-card img { width: 100%; border-radius: var(--radius); display: block; }
.empty-photo { display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: 2.5rem 1rem; text-align: center; }
.meta-card { padding: 1rem 1.4rem; }
dl.meta { display: flex; flex-wrap: wrap; gap: 2rem; margin: 0; }
dl.meta dt { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
dl.meta dd { margin: .25rem 0 0; font-weight: 600; font-size: 1.02rem; }
.spec-section h2 { margin-bottom: .6rem; }
table.spec-table { width: 100%; border-collapse: collapse; }
table.spec-table th { text-align: left; width: 50%; color: var(--ink-2); font-weight: 400; padding: .5rem .25rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.spec-table td { padding: .5rem .25rem; border-bottom: 1px solid var(--line); font-family: var(--font-mono); font-size: .92rem; color: var(--ink); }
table.spec-table tr:last-child th, table.spec-table tr:last-child td { border-bottom: none; }

/* ---------- edytor parametrów ---------- */
fieldset.specs { border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1.1rem; margin-bottom: 1.1rem; }
fieldset.specs legend { padding: 0 .5rem; color: var(--green); font-family: var(--font-display); font-weight: 600; }
.spec-grid-head, .spec-row { display: grid; grid-template-columns: 1.3fr 1.6fr 1.6fr .7fr auto; gap: .5rem; align-items: center; }
.spec-grid-head { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: .6rem 0 .4rem; }
.spec-row { margin-bottom: .5rem; }
.spec-row input { margin-top: 0; }
.spec-row.std input.locked { background: var(--green-50); color: var(--green-700); border-style: dashed; border-color: var(--green-300); }
.spec-actions { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: .6rem; }
.remove-spec { font-size: 1.3rem; line-height: 1; }
.lock-mark { font-size: .85rem; align-self: center; }

/* ---------- pozostałe ---------- */
.empty { text-align: center; padding: 3.5rem 1rem; color: var(--muted); background: var(--surface); border: 1px dashed var(--line-2); border-radius: var(--radius-lg); }
.empty h1 { font-size: 3rem; color: var(--line-2); }
.inline { display: flex; gap: .6rem; margin-top: 1rem; }
.inline input { width: auto; flex: 1; margin-top: 0; }
.current-img { display: flex; align-items: center; gap: 1rem; margin: .4rem 0; }
.current-img img { width: 120px; height: 90px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--line); }
.rm-img { display: flex; align-items: center; gap: .4rem; color: var(--muted); }
.rm-img input { width: auto; margin: 0; }
.img-drop { display: flex; flex-direction: column; align-items: flex-start; gap: .6rem; padding: 1rem; margin-top: .4rem; border: 1.5px dashed var(--line-2); border-radius: var(--radius); transition: border-color .15s, background .15s; }
.img-drop.drag { border-color: var(--green-500); background: var(--green-50); }
.img-drop input[type="file"] { width: auto; margin: 0; }
#img-preview { display: none; max-width: 180px; max-height: 140px; border-radius: var(--radius); border: 1px solid var(--line); }

/* ---------- feed aktywności ---------- */
.feed-list { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.feed-item {
  display: flex; align-items: flex-start; gap: .85rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .75rem 1rem;
  box-shadow: 0 1px 2px rgba(21,33,27,.03);
}
.feed-icon { font-size: 1.2rem; flex: none; width: 2rem; text-align: center; margin-top: .15rem; }
.feed-body { flex: 1; min-width: 0; }
.feed-summary { font-weight: 500; word-break: break-word; }
.feed-meta { font-size: .82rem; margin-top: .2rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.feed-time { margin-left: auto; font-family: var(--font-mono); font-size: .78rem; white-space: nowrap; }
.feed-badge { font-size: .72rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; white-space: nowrap; align-self: center; }
.feed-badge-add    { background: var(--green-50); color: var(--green); }
.feed-badge-edit   { background: var(--amber-bg); color: var(--amber-fg); }
.feed-badge-delete { background: var(--red-bg); color: var(--red); }

/* logo firmy inline (w nagłówkach detail) */
.company-logo-inline { height: 22px; width: auto; vertical-align: middle; margin-right: .35rem; border-radius: 3px; }

/* ---------- motion ---------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
main > * { animation: fadeUp .45s cubic-bezier(.2,.7,.2,1) both; }
main > *:nth-child(2) { animation-delay: .04s; }
main > *:nth-child(3) { animation-delay: .08s; }
main > *:nth-child(4) { animation-delay: .12s; }
main > *:nth-child(n+5) { animation-delay: .16s; }
@media (prefers-reduced-motion: reduce) { main > * { animation: none; } * { transition: none !important; } }

/* przycisk menu mobilnego — ukryty na desktopie */
.nav-toggle { display: none; background: none; border: none; color: var(--ink); cursor: pointer; padding: .3rem; border-radius: var(--radius); }
.nav-toggle:hover { background: var(--green-50); color: var(--green-700); }

.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin: 1.25rem 0 0; }

@media (max-width: 820px) {
  .detail-layout { grid-template-columns: 1fr; }
  .detail-side { order: -1; }
  .detail-side .photo-card { position: static; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: .75rem; padding: .75rem 1rem; }
  main { padding: 1.25rem 1rem 3rem; }
  .form .row { flex-direction: column; gap: 0; }
  .spec-grid-head { display: none; }
  .spec-row { grid-template-columns: 1fr 1fr; }

  /* menu mobilne: pokaż hamburger, nawigację zwiń do rozwijanej kolumny */
  .nav-toggle { display: inline-flex; align-items: center; }
  .topbar nav { display: none; flex-basis: 100%; flex-direction: column; gap: .15rem; }
  .topbar.nav-open nav { display: flex; }
  .topbar .user { flex-basis: 100%; }

  /* tabele jako karty — każda komórka w osobnym wierszu z etykietą (data-label) */
  .table-wrap { overflow-x: visible; border: none; box-shadow: none; }
  table.grid thead { display: none; }
  table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
  table.grid tr { margin-bottom: .75rem; border: 1px solid var(--line-2); border-radius: var(--radius); padding: .5rem .8rem; background: var(--surface); }
  table.grid td { border: none; padding: .3rem 0; display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
  table.grid td::before { content: attr(data-label); font-weight: 600; color: var(--muted); flex: 0 0 auto; }
  table.grid td.thumb-cell, table.grid td.actions { justify-content: flex-start; }
  table.grid td.thumb-cell::before, table.grid td.actions::before { content: none; }
  table.grid td:empty { display: none; }
}
