/* Harmonogram dyżurów – wspólny arkusz stylów (panel + logowanie) */

:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #e3e8ef;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0b5cd5;
  --primary-hover: #0a4fb8;
  --primary-soft: #e8f0fe;
  --primary-text: #ffffff;
  --success: #15803d;
  --success-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --dot-empty: #cbd5e1;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .06);
  --radius: 14px;
  --radius-sm: 10px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111a2e;
  --surface-2: #16213a;
  --border: #22304d;
  --text: #e6ebf5;
  --muted: #93a3bf;
  --primary: #4c8dff;
  --primary-hover: #6aa1ff;
  --primary-soft: rgba(76, 141, 255, .14);
  --primary-text: #06122b;
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, .12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .12);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, .12);
  --dot-empty: #334463;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

button, input, select { font: inherit; color: inherit; }

svg.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Pasek górny ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.brand > div { min-width: 0; }
.brand img { width: 34px; height: 34px; border-radius: 9px; object-fit: contain; background: #fff; padding: 3px; }
.brand-title { font-weight: 700; font-size: 16px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { color: var(--muted); font-size: 12px; margin-top: -2px; }
.topbar .spacer { flex: 0 0 0; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 12px 4px 4px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px; font-weight: 600; max-width: 200px;
}
.user-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--primary); color: var(--primary-text);
  font-size: 12px; font-weight: 700; text-transform: uppercase;
}

/* ---------- Przyciski ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .chip:focus-visible, .month:focus-visible, .dropzone:focus-within { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-icon { width: 38px; padding: 0; }
.btn-block { width: 100%; }
.btn .spinner { display: none; }
.btn.loading .spinner { display: inline-block; }
.btn.loading .btn-label-idle { display: none; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Układ ---------- */
.layout {
  display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 20px;
  max-width: 1600px; margin: 0 auto; padding: 20px;
}
.sidebar { display: flex; flex-direction: column; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-body { padding: 16px; }
.card-title {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 12px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}

/* ---------- Miasta ---------- */
.chips { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.chip {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  height: 40px; padding: 0 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; font-weight: 600; font-size: 14px;
  transition: background .15s, border-color .15s, color .15s;
}
.chip:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.chip .home { font-size: 11px; font-weight: 700; opacity: .75; }

/* ---------- Miesiące ---------- */
.months { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.month {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  height: 58px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; font-weight: 600; font-size: 13px;
  transition: background .15s, border-color .15s, color .15s;
}
.month:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
.month .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dot-empty); transition: background .2s; }
.month.has-schedule .dot { background: var(--success); }
.month.is-current::after {
  content: ""; position: absolute; top: 6px; right: 6px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--warning);
}
.month[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.month[aria-pressed="true"] .dot { background: var(--primary-text); opacity: .6; }
.month[aria-pressed="true"].has-schedule .dot { opacity: 1; }
.legend { display: flex; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

/* ---------- Upload ---------- */
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 132px; padding: 16px; text-align: center;
  border: 1.5px dashed var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--muted); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary); background: var(--primary-soft); color: var(--text); }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone svg.icon { width: 28px; height: 28px; color: var(--primary); }
.dropzone strong { color: var(--text); font-size: 14px; }
.dropzone small { font-size: 12px; }
.file-picked {
  display: none; align-items: center; gap: 10px;
  margin-top: 10px; padding: 8px 10px;
  border-radius: var(--radius-sm); background: var(--primary-soft);
  font-size: 13px;
}
.file-picked.show { display: flex; }
.file-picked .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.file-picked button { border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 2px; display: grid; }
.upload-target { margin: 12px 0; font-size: 13px; color: var(--muted); }
.upload-target b { color: var(--text); }

/* ---------- Podgląd ---------- */
.viewer { display: flex; flex-direction: column; min-height: calc(100vh - 110px); }
.viewer-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.viewer-title { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin: 0; }
.viewer-title .sep { color: var(--muted); font-weight: 400; margin: 0 6px; }
.meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
}
.badge-ok { background: var(--success-soft); color: var(--success); }
.badge-none { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.viewer-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.viewer-body {
  position: relative; flex: 1; overflow: auto;
  padding: 16px; display: flex; align-items: flex-start; justify-content: center;
  background:
    radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--muted) 18%, transparent) 1px, transparent 0) 0 0 / 18px 18px;
  border-radius: 0 0 var(--radius) var(--radius);
}
#preview-img {
  display: block; max-width: 100%; height: auto;
  max-height: calc(100vh - 210px);
  border-radius: 8px; background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .12);
  cursor: zoom-in; opacity: 0; transition: opacity .2s;
}
#preview-img.loaded { opacity: 1; }
#preview-img.zoomed { max-width: none; max-height: none; cursor: zoom-out; }
.empty {
  display: none; flex-direction: column; align-items: center; gap: 8px;
  margin: auto; padding: 40px 16px; color: var(--muted); text-align: center;
}
.empty svg.icon { width: 40px; height: 40px; }
.skeleton {
  position: absolute; inset: 16px; border-radius: 8px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite; opacity: .6;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  min-width: 260px; max-width: 420px; padding: 12px 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); box-shadow: var(--shadow);
  font-size: 14px; font-weight: 500;
  animation: toast-in .25s ease-out;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.danger { border-left: 4px solid var(--danger); }
.toast .close { margin-left: auto; border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0; display: grid; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

/* ---------- Okno potwierdzenia ---------- */
dialog.modal {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 0; width: min(440px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog.modal::backdrop { background: rgba(8, 12, 24, .55); backdrop-filter: blur(2px); }
.modal-body { padding: 20px; }
.modal-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--danger-soft); color: var(--danger); margin-bottom: 12px; }
.modal h3 { margin: 0 0 6px; font-size: 18px; }
.modal p { margin: 0; color: var(--muted); font-size: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 20px; }

/* ---------- Logowanie ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .card-body { padding: 28px; }
.auth-head { text-align: center; margin-bottom: 22px; }
.auth-head img { width: 64px; height: 64px; border-radius: 16px; background: #fff; padding: 6px; object-fit: contain; box-shadow: var(--shadow); }
.auth-head h1 { margin: 14px 0 4px; font-size: 22px; letter-spacing: -.01em; }
.auth-head p { margin: 0; color: var(--muted); font-size: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; }
.input-wrap { position: relative; }
.input {
  width: 100%; height: 44px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input-wrap .input { padding-right: 44px; }
.input-wrap button {
  position: absolute; right: 4px; top: 4px; width: 36px; height: 36px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 8px; display: grid; place-items: center;
}
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 14px; }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.auth-foot { display: flex; justify-content: center; margin-top: 16px; }
.auth-foot .btn { height: 32px; font-size: 13px; color: var(--muted); }

/* ---------- Responsywność ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 320px minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .layout { display: flex; flex-direction: column; padding: 12px; gap: 12px; }
  /* na telefonie: wybór → podgląd → wgrywanie */
  .sidebar { display: contents; }
  .card-cities { order: 1; }
  .card-months { order: 2; }
  .viewer { order: 3; }
  .card-upload { order: 4; }
  .viewer { min-height: 0; }
  #preview-img { max-height: none; }
  .chips { grid-template-columns: repeat(4, 1fr); }
  .chip { justify-content: center; padding: 0 6px; font-size: 13px; }
  .chip .home { display: none; }
  .months { grid-template-columns: repeat(6, 1fr); }
  .month { height: 52px; font-size: 12px; }
  .brand-sub, .user-chip span { display: none; }
  .user-chip { padding: 4px; }
}
@media (max-width: 520px) {
  .topbar { padding: 8px 12px; gap: 8px; }
  .brand-title { font-size: 15px; }
  .chips { grid-template-columns: repeat(2, 1fr); }
  .months { grid-template-columns: repeat(4, 1fr); }
  .viewer-title { font-size: 17px; }
  .viewer-actions { margin-left: 0; width: 100%; }
  .viewer-actions .btn { flex: 1; }
  .btn .hide-sm { display: none; }
}

/* ---------- Nawigacja (admin) ---------- */
a.brand { color: inherit; text-decoration: none; flex: 0 1 auto; }
.nav { display: flex; gap: 4px; margin-left: 16px; }
.nav-link {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px;
  border-radius: var(--radius-sm); color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }
.topbar .spacer { flex: 1 1 0; }

.branch-fixed {
  display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px;
  border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--primary); font-weight: 700;
}
.layout-single { grid-template-columns: 1fr; max-width: 640px; }
.empty-state { text-align: center; padding: 40px 24px; color: var(--muted); }
.empty-state svg.icon { width: 40px; height: 40px; color: var(--primary); }
.empty-state h2 { color: var(--text); margin: 10px 0 6px; font-size: 18px; }
.empty-state p { margin: 0; }

/* ---------- Użytkownicy ---------- */
.layout-users { grid-template-columns: minmax(0, 1fr) 380px; }
.page-head { display: flex; align-items: center; gap: 12px; padding: 16px; border-bottom: 1px solid var(--border); }
.page-head h1 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.page-head .count { color: var(--muted); font-size: 14px; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 700; padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.editing td { background: var(--primary-soft); }
.user-cell { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.show-sm { display: none; }
.admin-mark { color: var(--primary); display: none; }
.user-cell .me { font-size: 11px; font-weight: 700; color: var(--muted); margin-left: 4px; }
.badge-admin { background: var(--primary-soft); color: var(--primary); }
.badge-user { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions .btn { height: 32px; padding: 0 10px; font-size: 13px; }
.form-grid { display: flex; flex-direction: column; gap: 2px; }
.select {
  width: 100%; height: 44px; padding: 0 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); outline: none;
}
.select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.hint { font-size: 12px; color: var(--muted); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.segmented label {
  position: relative;
  display: flex; align-items: center; justify-content: center; gap: 6px; height: 40px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; font-weight: 600; font-size: 14px;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented input:checked + span { color: var(--primary-text); }
.segmented label:has(input:checked) { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.form-actions .btn { flex: 1; }

@media (max-width: 1100px) {
  .layout-users { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .nav { margin-left: 4px; }
  .nav-link span { display: none; }
  .layout-users { display: flex; flex-direction: column; }
  .layout-users .user-form-card { order: -1; }
  table.data th.hide-sm, table.data td.hide-sm { display: none; }
  .show-sm { display: inline-flex; }
  table.data td, table.data th { padding-left: 12px; padding-right: 12px; }
}
.topbar .btn, .topbar .user-chip { flex: none; }

/* ---------- Changelog ---------- */
.cl-page { max-width: 900px; }
.cl-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px;
  padding: 16px; border-bottom: 1px solid var(--border);
}
.cl-row:last-child { border-bottom: 0; }
.cl-actions { display: flex; gap: 6px; align-items: flex-start; }
.cl-actions .btn { height: 32px; padding: 0 10px; font-size: 13px; }
.cl-meta { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
dialog.modal.modal-wide { width: min(640px, calc(100vw - 24px)); }
.modal-wide h3 { margin-bottom: 14px; }
.cl-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.textarea { height: auto; min-height: 180px; padding: 10px 14px; resize: vertical; line-height: 1.5; font-family: inherit; }
.cl-preview {
  padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px dashed var(--border); background: var(--surface-2);
  max-height: 220px; overflow: auto;
}
@media (max-width: 520px) {
  .cl-form-row { grid-template-columns: 1fr; gap: 0; }
  .cl-row { grid-template-columns: 1fr; }
}
:root { --note: #4d7c0f; --note-soft: #ecfccb; }
:root[data-theme="dark"] { --note: #a3e635; --note-soft: rgba(163, 230, 53, .1); }
.modal p.cl-note { color: var(--note); }
