/* KW Handel — arkusz stylów. Grafit / antracyt / złote akcenty. Motyw ciemny i jasny. */

:root, [data-theme='dark'] {
  --bg: #141519;
  --bg-soft: #191b20;
  --surface: #1f2127;
  --surface-2: #24262e;
  --surface-offset: #2a2d36;
  --border: #34363e;
  --border-strong: #42454f;
  --text: #e9eaee;
  --text-muted: #9b9daa;
  --text-faint: #6d707c;
  --gold: #d4af37;
  --gold-strong: #e5c558;
  --gold-ink: #141519;
  --ok: #3fb96b;
  --ok-soft: rgba(63, 185, 107, .12);
  --bad: #e05a5a;
  --bad-soft: rgba(224, 90, 90, .12);
  --warn: #e0a63f;
  --warn-soft: rgba(224, 166, 63, .12);
  --info: #5aa7e0;
  --info-soft: rgba(90, 167, 224, .12);
  --shadow: 0 8px 28px rgba(0, 0, 0, .38);
  --radius: 12px;
}
[data-theme='light'] {
  --bg: #f2f3f6;
  --bg-soft: #eceef2;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-offset: #eef0f4;
  --border: #dde0e6;
  --border-strong: #c9cdd6;
  --text: #23252b;
  --text-muted: #5d6069;
  --text-faint: #93969f;
  --gold: #a8841f;
  --gold-strong: #8a6c14;
  --gold-ink: #ffffff;
  --ok: #2c8a4f;
  --ok-soft: rgba(44, 138, 79, .1);
  --bad: #c74444;
  --bad-soft: rgba(199, 68, 68, .1);
  --warn: #b07c17;
  --warn-soft: rgba(176, 124, 23, .1);
  --info: #2f6ea3;
  --info-soft: rgba(47, 110, 163, .1);
  --shadow: 0 8px 24px rgba(35, 37, 43, .12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100dvh;
}
a { color: var(--gold-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--surface-offset); padding: 1px 5px; border-radius: 5px; font-size: .86em; }

/* ---------- ekran startowy ---------- */
.boot-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100dvh; gap: 18px; }
.boot-logo { width: 64px; height: 64px; border-radius: 16px; background: linear-gradient(135deg, var(--gold), var(--gold-strong)); color: var(--gold-ink); font-weight: 800; font-size: 24px; display: flex; align-items: center; justify-content: center; }
.boot-spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--gold); animation: spin .8s linear infinite; }
.boot-text { color: var(--text-muted); font-size: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- logowanie ---------- */
.login-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; background:
  radial-gradient(1200px 500px at 80% -10%, rgba(212,175,55,.07), transparent 60%),
  radial-gradient(900px 420px at -10% 110%, rgba(212,175,55,.05), transparent 55%); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 34px 30px; box-shadow: var(--shadow); }
.login-card .mark { width: 52px; height: 52px; border-radius: 13px; background: linear-gradient(135deg, var(--gold), var(--gold-strong)); color: var(--gold-ink); font-weight: 800; font-size: 19px; display: flex; align-items: center; justify-content: center; margin-bottom: 18px; }
.login-card h1 { font-size: 21px; margin-bottom: 2px; letter-spacing: -.01em; }
.login-card .sub { color: var(--text-muted); font-size: 13.5px; margin-bottom: 22px; }

/* ---------- układ aplikacji ---------- */
.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100dvh; }
.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.brand .mark { width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, var(--gold), var(--gold-strong)); color: var(--gold-ink); font-weight: 800; font-size: 14px; display: flex; align-items: center; justify-content: center; flex: none; }
.brand b { font-size: 15px; letter-spacing: -.01em; }
.brand span { display: block; font-size: 11.5px; color: var(--text-muted); font-weight: 500; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 9px; color: var(--text-muted);
  font-weight: 500; font-size: 14px; border: 1px solid transparent;
  transition: background .15s, color .15s; cursor: pointer; user-select: none;
}
.nav-item svg { width: 19px; height: 19px; flex: none; opacity: .85; }
.nav-item:hover { background: var(--surface-offset); color: var(--text); text-decoration: none; }
.nav-item.active { background: linear-gradient(90deg, rgba(212,175,55,.16), rgba(212,175,55,.05)); color: var(--gold-strong); border-color: rgba(212,175,55,.28); }
[data-theme='light'] .nav-item.active { color: var(--gold); }
.nav-item.active svg { opacity: 1; }
.sidebar .spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 10px 10px; border-top: 1px solid var(--border); margin-top: 8px; }
.user-chip .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-offset); color: var(--text-muted); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex: none; }
.user-chip .meta { min-width: 0; flex: 1; }
.user-chip .meta b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .meta span { font-size: 11.5px; color: var(--text-muted); }

.main { padding: 26px 30px 90px; max-width: 1280px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 23px; letter-spacing: -.02em; }
.page-head .sub { color: var(--text-muted); font-size: 13.5px; margin-top: 2px; }

/* ---------- komponenty ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 13.5px;
  cursor: pointer; transition: background .15s, border-color .15s; text-decoration: none;
  min-height: 40px;
}
.btn:hover { background: var(--surface-offset); text-decoration: none; }
.btn.gold { background: linear-gradient(135deg, var(--gold), var(--gold-strong)); color: var(--gold-ink); border-color: transparent; }
.btn.gold:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: rgba(224,90,90,.4); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; min-height: 32px; }
.btn svg { width: 16px; height: 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
.card h2 { font-size: 16px; margin-bottom: 4px; }
.card .desc { color: var(--text-muted); font-size: 13px; margin-bottom: 14px; }

.kpi-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 3px; background: linear-gradient(180deg, var(--gold), transparent); opacity: .55; }
.kpi .k-label { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 12.5px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase; }
.kpi .k-label svg { width: 16px; height: 16px; }
.kpi .k-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .k-hint { color: var(--text-faint); font-size: 12px; margin-top: 2px; }
.kpi .k-value.pos { color: var(--ok); }
.kpi .k-value.neg { color: var(--bad); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.status-badge { display: inline-flex; align-items: center; gap: 7px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.status-badge .dot { width: 7px; height: 7px; border-radius: 50%; }
.st-blue { background: rgba(90,140,224,.12); color: #7fabf0; } [data-theme='light'] .st-blue { color: #2d5fae; }
.st-green { background: var(--ok-soft); color: var(--ok); }
.st-orange { background: var(--warn-soft); color: var(--warn); }
.st-teal { background: rgba(63,185,167,.12); color: #4fc4b0; } [data-theme='light'] .st-teal { color: #17807a; }
.st-purple { background: rgba(167,122,235,.12); color: #a98cf2; } [data-theme='light'] .st-purple { color: #6f3fc0; }
.st-gray { background: var(--surface-offset); color: var(--text-muted); }
.st-slate { background: rgba(120,130,150,.14); color: var(--text-faint); }
.st-gold { background: rgba(212,175,55,.13); color: var(--gold-strong); } [data-theme='light'] .st-gold { color: var(--gold); }

.table-wrap { overflow-x: auto; }
td, th, .alert-row, .card, .kpi, .sub, .toast { overflow-wrap: break-word; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; color: var(--text-muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border-strong); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--ok); } .neg { color: var(--bad); }

.empty { text-align: center; color: var(--text-muted); padding: 38px 10px; }
.empty svg { width: 34px; height: 34px; opacity: .4; margin-bottom: 10px; }

/* ---------- formularze ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12.5px; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--bg-soft); color: var(--text); font-size: 14px; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.field textarea { min-height: 84px; resize: vertical; }
.field .err { color: var(--bad); font-size: 12.5px; margin-top: 5px; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.checkline input { width: auto; }

/* ---------- modale ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(8,9,12,.62); display: flex; align-items: center; justify-content: center; padding: 18px; z-index: 60; backdrop-filter: blur(3px); }
.modal { background: var(--surface); border: 1px solid var(--border-strong); border-radius: 14px; width: 100%; max-width: 620px; max-height: 90dvh; overflow-y: auto; box-shadow: var(--shadow); animation: pop .16s ease-out; }
.modal.wide { max-width: 860px; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }
.icon-btn { background: none; border: 0; color: var(--text-muted); cursor: pointer; padding: 6px; border-radius: 7px; display: inline-flex; }
.icon-btn:hover { background: var(--surface-offset); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- alerty / toasty ---------- */
.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 13px; border-radius: 9px; font-size: 13.5px; border: 1px solid transparent; }
.alert-row svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.alert-row.warning { background: var(--warn-soft); color: var(--warn); border-color: rgba(224,166,63,.3); }
.alert-row.danger { background: var(--bad-soft); color: var(--bad); border-color: rgba(224,90,90,.3); }
.alert-row.info { background: var(--info-soft); color: var(--info); border-color: rgba(90,167,224,.3); }
.alert-row a { color: inherit; font-weight: 600; }

.toasts { position: fixed; bottom: 76px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(92vw, 380px); }
.toast { background: var(--surface); border: 1px solid var(--border-strong); border-left: 3px solid var(--ok); border-radius: 9px; padding: 11px 14px; font-size: 13.5px; box-shadow: var(--shadow); animation: slide-in .18s ease-out; }
.toast.error { border-left-color: var(--bad); }
@keyframes slide-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- zdjęcia ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.photo-tile { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); aspect-ratio: 4/3; background: var(--bg-soft); }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile .tools { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; }
.photo-tile .tools button { background: rgba(10,10,14,.72); border: 0; color: #fff; border-radius: 7px; padding: 5px 7px; cursor: pointer; display: inline-flex; align-items: center; }
.photo-tile .tools button svg { width: 14px; height: 14px; }
.photo-tile .main-flag { position: absolute; left: 6px; bottom: 6px; background: rgba(212,175,55,.92); color: #17181c; font-size: 10.5px; font-weight: 700; border-radius: 5px; padding: 2px 7px; }
.thumb { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); display: block; }

/* ---------- mobile ---------- */
.mobile-top { display: none; }
.bottom-nav { display: none; }

@media (max-width: 1020px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 14px 14px 110px; }
  .mobile-top {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 40;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    padding: 12px 14px; margin: -14px -14px 16px; width: calc(100% + 28px);
  }
  .mobile-top .brand { padding: 0; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: color-mix(in srgb, var(--bg-soft) 94%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a, .bottom-nav button {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    color: var(--text-muted); font-size: 10.5px; font-weight: 600;
    background: none; border: 0; cursor: pointer; padding: 7px 2px; border-radius: 9px;
  }
  .bottom-nav svg { width: 21px; height: 21px; }
  .bottom-nav a.active, .bottom-nav button.active { color: var(--gold-strong); }
  .form-grid { grid-template-columns: 1fr; }
  .page-head { align-items: flex-start; }
  .page-head .actions { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }

  /* ---- tabele list jako karty (etykieta: wartość) ---- */
  .table-wrap { overflow-x: visible; }
  .table-wrap table { font-size: 13px; }
  .table-wrap thead { display: none; }
  .table-wrap tbody tr {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px 13px;
    margin-bottom: 10px;
  }
  .table-wrap tbody tr:hover { background: var(--surface); }
  .table-wrap tbody td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
    overflow-wrap: break-word;
    text-align: right;
  }
  .table-wrap tbody tr:last-child td { border-bottom: 0; }
  .table-wrap tbody td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    text-align: left;
    flex: none;
  }
  /* wiersz "brak danych" i inne z colspan */
  .table-wrap tbody td[colspan] { display: block; text-align: center; }
  .table-wrap tbody td[colspan]::before { content: none; }
  /* miniatury w kartach */
  .table-wrap tbody td .thumb { width: 40px; height: 40px; }
}

/* tabele klucz-wartość (szczegóły, bez thead) – też elastyczne na wąskich ekranach */
@media (max-width: 560px) {
  .kv-table tbody tr { display: flex; gap: 10px; }
  .kv-table tbody td:first-child { flex: 0 0 42%; color: var(--text-muted); font-size: 12.5px; }
  .kv-table tbody td:last-child { flex: 1; text-align: right; overflow-wrap: break-word; }
  .kv-table tbody td { border-bottom: 0; padding: 6px 0; }
}
