/* Mgen – interfejs WWW. Bez frameworka; kolory w zmiennych, tryb ciemny wg ustawień systemu. */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e7ee;
  --text: #17202b;
  --muted: #5d6b7c;
  --brand: #0b5cab;
  --brand-strong: #084785;
  --brand-soft: #e6f0fb;
  --ok: #1b7f4b;
  --ok-soft: #e3f4ea;
  --warn: #b4530a;
  --warn-soft: #fdf0e3;
  --danger: #c0262d;
  --danger-soft: #fde8e8;
  --license: #6a3fb5;
  --license-soft: #efe8fb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 20px 40px rgba(16, 24, 40, .18);
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #171e26;
    --surface-2: #1c242e;
    --border: #2a3440;
    --text: #e6ebf1;
    --muted: #9aa7b6;
    --brand: #5aa2ec;
    --brand-strong: #84bbf2;
    --brand-soft: #1a2c40;
    --ok: #4cc488;
    --ok-soft: #173225;
    --warn: #f0a050;
    --warn-soft: #3a2a17;
    --danger: #f27178;
    --danger-soft: #3d1c20;
    --license: #b393ef;
    --license-soft: #2a2140;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; font-weight: 650; }
h2 { font-size: 1.05rem; font-weight: 650; }
.mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- nagłówek --- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 1.1rem; letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.brand img { width: 34px; height: 34px; border-radius: 8px; }
.brand b { color: var(--brand); }
.nav { display: flex; gap: 4px; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 550; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--brand); background: var(--brand-soft); }
.user-menu { margin-left: auto; position: relative; }
.user-menu summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 6px 10px; border-radius: 8px; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: var(--surface-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; }
.menu a, .menu button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0; background: none; color: var(--text); border-radius: 6px; font: inherit; cursor: pointer; text-align: left; }
.menu a:hover, .menu button:hover { background: var(--surface-2); text-decoration: none; }

/* --- układ --- */
.container { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 16px; }
main.container { padding-top: 24px; padding-bottom: 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-body { padding: 16px 18px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 18px; align-items: start; }
.stack { display: grid; gap: 18px; }
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); margin-bottom: 10px; font-weight: 550; }

/* --- przyciski i pola --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible, .chip:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-danger { color: var(--danger); }
.btn-sm { height: 32px; padding: 0 10px; font-size: .88rem; }
.btn-ghost { border-color: transparent; background: none; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { resize: vertical; }
.field { margin-bottom: 14px; }
.field .help { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.errors, .field .error { color: var(--danger); font-size: .85rem; margin: 4px 0 0; padding: 0; list-style: none; }
.form-errors { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.checks { display: grid; gap: 8px; }
.check { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-weight: 500; cursor: pointer; margin: 0; }
.check:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.check input { width: 17px; height: 17px; accent-color: var(--brand); }
.check .tok { margin-left: auto; color: var(--muted); font-size: .85rem; }

/* --- pasek narzędzi listy --- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px; }
.search { position: relative; flex: 1 1 280px; }
.search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 36px; height: 38px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-weight: 550; cursor: pointer; margin: 0; }
.chip input { accent-color: var(--warn); }
.chip:has(input:checked) { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.htmx-request .spinner, .spinner.htmx-request { opacity: 1; }
.spinner { opacity: 0; transition: opacity .2s; color: var(--muted); font-size: .85rem; }

/* --- lista urządzeń --- */
.dlist { border-top: 1px solid var(--border); }
.drow-grid { display: grid; grid-template-columns: 170px 120px minmax(0, 1.3fr) minmax(0, 1.3fr) 120px 96px 28px; gap: 12px; align-items: center; padding: 10px 16px; }
.dhead { color: var(--muted); font-size: .8rem; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.dhead a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.dhead a:hover { color: var(--text); text-decoration: none; }
.dhead a.active { color: var(--brand); }
details.drow { border-bottom: 1px solid var(--border); }
details.drow > summary { list-style: none; cursor: pointer; }
details.drow > summary::-webkit-details-marker { display: none; }
details.drow > summary:hover { background: var(--surface-2); }
details.drow[open] > summary { background: var(--brand-soft); }
details.drow.service > summary { box-shadow: inset 3px 0 0 var(--danger); }
.cell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { transition: transform .15s; color: var(--muted); }
details[open] .chev { transform: rotate(90deg); }
.preview { padding: 16px; background: var(--surface-2); border-top: 1px solid var(--border); }
.preview-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.count { color: var(--muted); font-size: .9rem; padding: 10px 16px; }

/* --- plakietki --- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 650; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-service { background: var(--danger-soft); color: var(--danger); }
.badge-module { background: var(--license-soft); color: var(--license); }
.badge-neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* --- dane urządzenia --- */
dl.props { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 18px; margin: 0; }
dl.props dt { color: var(--muted); font-size: .88rem; }
dl.props dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.device-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.device-title h1 { font-family: var(--mono); font-size: 1.45rem; }

/* --- licencja --- */
.license-big { display: flex; align-items: baseline; gap: 8px; }
.license-big .num { font-size: 2.2rem; font-weight: 750; color: var(--license); line-height: 1; }
.modules { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.keybox { font-family: var(--mono); font-size: .78rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; overflow-wrap: anywhere; max-height: 92px; overflow: auto; margin: 10px 0; }
.total { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-radius: 8px; background: var(--license-soft); color: var(--license); font-weight: 650; margin: 6px 0 14px; }
.total .num { font-size: 1.5rem; }
.total.invalid { background: var(--danger-soft); color: var(--danger); }

/* --- historia --- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.tl-icon { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; }
.tl-license .tl-icon { background: var(--license-soft); color: var(--license); }
.tl-comment .tl-icon { background: var(--brand-soft); color: var(--brand); }
.tl-service .tl-icon { background: var(--danger-soft); color: var(--danger); }
.tl-meta { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.tl-text { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.comments { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.comments li { border-left: 3px solid var(--brand); padding: 2px 0 2px 10px; }
.comments li.service { border-left-color: var(--danger); }

/* --- tabela kont --- */
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }

/* --- okna dialogowe --- */
dialog.modal { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog.modal::backdrop { background: rgba(10, 16, 24, .45); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px 20px 4px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 14px 14px; }

/* --- logowanie --- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: min(400px, 100%); }
.auth .brand { justify-content: center; margin-bottom: 18px; font-size: 1.4rem; }
.auth .brand img { width: 44px; height: 44px; }

/* --- komunikaty --- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); animation: toast-in .2s ease-out; }
.toast-success { border-left: 4px solid var(--ok); }
.toast-error { border-left: 4px solid var(--danger); }
.toast.hide { opacity: 0; transform: translateY(8px); transition: all .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --- telefon / wąskie okno --- */
@media (max-width: 960px) {
  .grid-2, .preview-grid { grid-template-columns: 1fr; }
  .drow-grid { grid-template-columns: minmax(0, 1fr) auto 20px; gap: 4px 10px; }
  .drow-grid .c-vpn, .drow-grid .c-user, .drow-grid .c-date { display: none; }
  .drow-grid .c-buyer { grid-column: 1 / 2; grid-row: 2; color: var(--muted); font-size: .88rem; }
  .dhead { display: none; }
  .nav a span { display: none; }
}
@media (max-width: 560px) {
  .fields-2 { grid-template-columns: 1fr; }
  .topbar-inner { gap: 10px; }
  .brand span { display: none; }
  .user-menu .who { display: none; }
}
