/* ==========================================================================
   Startpage — arkusz stylów wspólny dla dashboardu i panelu administratora.
   Zasada: interfejs jest neutralny, kolor wnoszą same strony (ikony)
   oraz barwa kategorii widoczna jako cienki pasek przy karcie.
   ========================================================================== */

:root {
  --bg: #f5f6f8;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e0e4ea;
  --border-strong: #cdd3dd;
  --text: #10141b;
  --text-muted: #67717f;
  --text-faint: #98a1af;
  --accent: #2f6bff;
  --accent-soft: rgba(47, 107, 255, .12);
  --star: #e8a013;
  --danger: #d33a3a;
  --danger-soft: rgba(211, 58, 58, .1);
  --ok: #1f9254;
  --shadow-1: 0 1px 2px rgba(16, 20, 27, .05);
  --shadow-2: 0 6px 20px -6px rgba(16, 20, 27, .18);
  --radius: 11px;
  --radius-sm: 8px;
  --topbar-h: 60px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #0d1016;
  --bg-elevated: #141922;
  --surface: #141922;
  --surface-2: #1b212c;
  --border: #242c39;
  --border-strong: #333d4d;
  --text: #e6ecf4;
  --text-muted: #8f9bad;
  --text-faint: #6c7789;
  --accent: #5b8dff;
  --accent-soft: rgba(91, 141, 255, .16);
  --star: #f0b429;
  --danger: #ef5f5f;
  --danger-soft: rgba(239, 95, 95, .14);
  --ok: #38b676;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-2: 0 8px 24px -8px rgba(0, 0, 0, .6);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #0d1016;
    --bg-elevated: #141922;
    --surface: #141922;
    --surface-2: #1b212c;
    --border: #242c39;
    --border-strong: #333d4d;
    --text: #e6ecf4;
    --text-muted: #8f9bad;
    --text-faint: #6c7789;
    --accent: #5b8dff;
    --accent-soft: rgba(91, 141, 255, .16);
    --star: #f0b429;
    --danger: #ef5f5f;
    --danger-soft: rgba(239, 95, 95, .14);
    --ok: #38b676;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-2: 0 8px 24px -8px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

a { color: inherit; text-decoration: none; }

:where(a, button, input, select, textarea):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 16px;
  min-height: var(--topbar-h);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }

.brand-mark {
  width: 13px; height: 13px; border-radius: 4px;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 40%, var(--star)));
}

.brand-name {
  font-weight: 650;
  letter-spacing: -.012em;
  font-size: 15.5px;
  white-space: nowrap;
}

.search { position: relative; display: flex; align-items: center; min-width: 0; }

.search-icon {
  position: absolute; left: 11px; width: 16px; height: 16px;
  color: var(--text-faint); pointer-events: none;
}

.search input {
  width: 100%;
  padding: 9px 40px 9px 34px;
  font: inherit;
  font-size: 14.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  transition: border-color .15s, box-shadow .15s;
}

.search input::placeholder { color: var(--text-faint); }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.search input::-webkit-search-cancel-button { display: none; }

.search-key {
  position: absolute; right: 9px;
  font: 500 11px/1 var(--font);
  color: var(--text-faint);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 6px;
  pointer-events: none;
}

.topbar-actions { display: flex; gap: 6px; align-items: center; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }

.ico-moon { display: none; }
:root[data-theme="dark"] .ico-sun { display: none; }
:root[data-theme="dark"] .ico-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .ico-sun { display: none; }
  :root[data-theme="auto"] .ico-moon { display: block; }
}

/* ------------------------------------------------------------------- board */

.board {
  max-width: 1400px;
  margin: 0 auto;
  padding: 22px 16px 40px;
}

.section { margin-bottom: 30px; scroll-margin-top: 80px; }

.section-head {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin: 0 0 11px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--border);
}

.section-title {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -.005em;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--cat-color, var(--accent));
  flex-shrink: 0;
}

.section-count { font-size: 12px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.section-desc { font-size: 12.5px; color: var(--text-faint); margin-left: auto; text-align: right; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 9px;
}

/* -------------------------------------------------------------------- card */

.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 11px 10px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  min-width: 0;
  transition: border-color .14s ease, transform .14s ease, box-shadow .14s ease;
}

.card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--cat-color, var(--border-strong));
  opacity: .85;
}

.card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-2);
}

@media (prefers-reduced-motion: reduce) {
  .card, .card:hover { transition: none; transform: none; }
}

.card-icon {
  width: 26px; height: 26px;
  flex-shrink: 0;
  border-radius: 6px;
  object-fit: contain;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-size: 12.5px;
  font-weight: 600;
  color: #fff;
  overflow: hidden;
}

img.card-icon { padding: 3px; background: var(--surface-2); }

.card-body { min-width: 0; flex: 1; }

.card-name {
  font-size: 13.4px;
  font-weight: 520;
  letter-spacing: -.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-sub {
  font-size: 11.4px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.card-star {
  position: absolute;
  top: 6px; right: 7px;
  width: 11px; height: 11px;
  color: var(--star);
}
.card-star svg { fill: currentColor; stroke: none; }

.card.is-active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ------------------------------------------------------------ stany, stopka */

.skeleton { display: grid; gap: 26px; }
.sk-row { height: 96px; border-radius: var(--radius); background: var(--surface-2); opacity: .55; }

.empty { max-width: 1400px; margin: 0 auto; padding: 40px 16px; text-align: center; }
.empty-title { font-weight: 600; margin: 0 0 4px; }
.empty-hint { color: var(--text-muted); font-size: 13.5px; margin: 0; }

.foot {
  max-width: 1400px;
  margin: 0 auto;
  padding: 18px 16px 34px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12.5px;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
}
.foot a:hover { color: var(--text); }

/* ============================== PANEL ADMINISTRATORA ====================== */

.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }

.page-title { font-size: 21px; font-weight: 650; letter-spacing: -.015em; margin: 0 0 4px; }
.page-sub { color: var(--text-muted); font-size: 13.5px; margin: 0 0 22px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 26px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 13px 15px; }
.stat-n { font-size: 23px; font-weight: 640; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat-l { font-size: 12.5px; color: var(--text-muted); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 20px; overflow: hidden; }
.panel-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 13px 15px; border-bottom: 1px solid var(--border); }
.panel-title { font-size: 14.5px; font-weight: 600; margin: 0; }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 15px; }

.btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .14s, border-color .14s, color .14s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 9px; font-size: 12.5px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12.8px; font-weight: 550; margin-bottom: 5px; color: var(--text-muted); }
.field .hint { font-size: 11.8px; color: var(--text-faint); margin-top: 4px; }

input[type="text"], input[type="url"], input[type="password"], input[type="search"], select, textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 9px 11px;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .14s, box-shadow .14s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
textarea { resize: vertical; min-height: 68px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }

/* --- lista linków w panelu --- */

.admin-toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.admin-toolbar .grow { flex: 1 1 220px; }
.admin-toolbar select { flex: 0 1 190px; }

.cat-block { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.cat-block-head {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px;
  background: var(--surface-2);
  font-size: 13px; font-weight: 600;
}
.cat-block-head .count { color: var(--text-faint); font-weight: 400; font-variant-numeric: tabular-nums; }
.cat-block-head .spacer { flex: 1; }

.item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.item:first-child { border-top: none; }
.item.drag-over { box-shadow: inset 0 2px 0 var(--accent); }
.item.dragging { opacity: .4; }

.grip { color: var(--text-faint); cursor: grab; width: 15px; height: 15px; flex-shrink: 0; touch-action: none; }
.grip:active { cursor: grabbing; }

.item-icon { width: 22px; height: 22px; border-radius: 5px; flex-shrink: 0; object-fit: contain; background: var(--surface-2); display: grid; place-items: center; font-size: 11px; font-weight: 600; color: #fff; overflow: hidden; }
.item-main { min-width: 0; flex: 1; }
.item-name { font-size: 13.5px; font-weight: 520; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-url { font-size: 11.6px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-actions { display: flex; gap: 4px; flex-shrink: 0; }

.star-btn { color: var(--text-faint); }
.star-btn[aria-pressed="true"] { color: var(--star); }
.star-btn[aria-pressed="true"] svg { fill: currentColor; stroke: none; }
.star-btn svg { width: 15px; height: 15px; }

/* --- modal --- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(8, 11, 16, .55);
  display: grid; place-items: center;
  padding: 16px;
  overflow-y: auto;
}
.modal {
  width: 100%; max-width: 520px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-2);
  max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; padding: 15px 17px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 15.5px; font-weight: 620; margin: 0; flex: 1; }
.modal-body { padding: 17px; overflow-y: auto; }
.modal-foot { display: flex; gap: 9px; justify-content: flex-end; padding: 13px 17px; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* --- komunikaty --- */

.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 13px; border: 1px solid; }
.alert-err { color: var(--danger); background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.alert-ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.alert-warn { color: var(--star); background: color-mix(in srgb, var(--star) 12%, transparent); border-color: color-mix(in srgb, var(--star) 35%, transparent); }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 80;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px;
  font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow-2);
  max-width: calc(100vw - 32px);
}

/* --- logowanie --- */

.login-wrap { max-width: 380px; margin: 12vh auto 0; padding: 0 16px 40px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 22px; box-shadow: var(--shadow-1); }
.login-card h1 { font-size: 18px; font-weight: 640; margin: 0 0 3px; }
.login-card p.sub { color: var(--text-muted); font-size: 13.4px; margin: 0 0 18px; }

/* ------------------------------------------------------------- responsywność */

@media (max-width: 720px) {
  .topbar-inner {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand actions" "search search";
    row-gap: 9px;
    padding: 9px 12px;
  }
  .brand { grid-area: brand; }
  .topbar-actions { grid-area: actions; }
  .search { grid-area: search; }
  .search-key { display: none; }
  .board { padding: 16px 12px 32px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  .section-desc { display: none; }
  .admin-wrap { padding: 18px 12px 50px; }
  .item { flex-wrap: wrap; }
  .item-main { flex: 1 1 60%; }
  .item-actions { width: 100%; justify-content: flex-end; }
  .modal { max-width: 100%; }
}

@media (min-width: 1024px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 10px; }
  .board { padding: 26px 28px 48px; }
  .topbar-inner { padding: 10px 28px; gap: 20px; }
  .search { max-width: 520px; }
  .foot { padding-left: 28px; padding-right: 28px; }
}

@media (min-width: 1600px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
}

.brand-sub { font-size: 12.5px; color: var(--text-faint); white-space: nowrap; }
@media (max-width: 900px) { .brand-sub { display: none; } }

/* ------------------------------------------------------------- ekran PIN-u */

.unlock-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

.unlock-card {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.unlock-card h1 { font-size: 19px; font-weight: 640; letter-spacing: -.015em; margin: 16px 0 5px; }
.unlock-sub { color: var(--text-muted); font-size: 13.4px; margin: 0 0 22px; }

.pin-dots { display: flex; justify-content: center; gap: 10px; min-height: 14px; margin-bottom: 12px; }
.pin-dot {
  width: 11px; height: 11px; border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  transition: background .12s, border-color .12s, transform .12s;
}
.pin-dot.filled { background: var(--accent); border-color: var(--accent); transform: scale(1.06); }

.pin-msg { min-height: 20px; font-size: 13px; color: var(--text-muted); margin-bottom: 14px; }
.pin-msg-err { color: var(--danger); }
.pin-msg-ok { color: var(--ok); }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad button {
  font: inherit;
  font-size: 21px;
  font-weight: 450;
  font-variant-numeric: tabular-nums;
  height: 62px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s, border-color .1s, transform .06s;
}
.keypad button:hover { background: var(--surface-2); }
.keypad button:active { transform: scale(.96); background: var(--surface-2); }
.keypad .key-alt { font-size: 18px; color: var(--text-muted); }
.keypad .key-ok { background: var(--accent); border-color: var(--accent); color: #fff; }
.keypad .key-ok:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }

.unlock-admin { display: inline-block; margin-top: 22px; font-size: 12.8px; color: var(--text-faint); }
.unlock-admin:hover { color: var(--text); text-decoration: underline; }

@media (prefers-reduced-motion: reduce) {
  .pin-dot, .keypad button { transition: none; }
  .keypad button:active { transform: none; }
}

@media (max-height: 620px) {
  .keypad button { height: 52px; font-size: 19px; }
  .unlock-sub { margin-bottom: 14px; }
}

.foot-links { display: flex; gap: 14px; align-items: center; }
.link-btn {
  font: inherit; font-size: 12.5px;
  color: var(--text-faint);
  background: none; border: none; padding: 0; cursor: pointer;
}
.link-btn:hover { color: var(--text); }
