:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --text: #1c2333;
  --muted: #6b7489;
  --border: #e2e6ee;
  --side-bg: #16213a;
  --side-text: #c9d1e3;
  --side-active: #25345a;
  --accent: #2f6fdb;
  --accent-soft: #e6eefc;
  --red: #d33a2c;    --red-soft: #fde8e6;
  --orange: #e07b12; --orange-soft: #fdf0e1;
  --green: #1f9d55;  --green-soft: #e3f5ea;
  --gray: #8a93a6;   --gray-soft: #eef0f4;
  --yellow-soft: #fff6d6;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 30, 60, .07);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.spacer { flex: 1; }
.mobile-only { display: none; }

/* ---------- Przyciski i pola ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--red); }
.btn-green { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.btn-green:hover { background: var(--green); filter: brightness(1.08); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; font-size: 13px; padding: 0; }

input, select, textarea {
  font: inherit; font-size: 15px; color: var(--text);
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 40px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.form-error { color: var(--red); font-size: 13px; min-height: 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); font: inherit; font-size: 14px; cursor: pointer; color: var(--text);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.p-awaria.on { background: var(--red); border-color: var(--red); }
.chip.p-pilne.on { background: var(--orange); border-color: var(--orange); }
.chip.p-normalne.on { background: var(--green); border-color: var(--green); }
.chip.p-kiedys.on { background: var(--gray); border-color: var(--gray); }

/* ---------- Układ ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex-shrink: 0; background: var(--side-bg); color: var(--side-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-logo { font-size: 28px; }
.brand-name { font-weight: 700; font-size: 17px; color: #fff; }
.brand-sub { font-size: 12px; opacity: .65; }
.menu { display: flex; flex-direction: column; padding: 12px 10px; gap: 2px; }
.menu a {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 8px;
  color: var(--side-text); text-decoration: none; font-size: 15px;
}
.menu a:hover { background: rgba(255,255,255,.05); }
.menu a.active { background: var(--side-active); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.menu .ico { width: 22px; text-align: center; }
.menu .badge { margin-left: auto; background: var(--red); color: #fff; border-radius: 999px; font-size: 12px; padding: 1px 7px; font-weight: 700; }
.user-box { margin-top: auto; padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.07); }
.user-name { color: #fff; font-weight: 600; font-size: 14px; }
.user-role { font-size: 12px; opacity: .65; margin-bottom: 10px; }
.user-buttons { display: flex; gap: 6px; }
.btn-side {
  flex: 1; padding: 7px; border: 1px solid rgba(255,255,255,.18); border-radius: 8px;
  background: none; color: var(--side-text); cursor: pointer; font: inherit; font-size: 12px;
}
.btn-side:hover { background: rgba(255,255,255,.06); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 12px 28px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 20px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.burger { display: none; border: 0; background: none; font-size: 24px; cursor: pointer; padding: 0 4px; }
.content { padding: 24px 28px 100px; max-width: 1400px; width: 100%; }
.backdrop { display: none; }
.fab { display: none; }

/* Stoper w pasku */
.timer-chip {
  display: flex; align-items: center; gap: 10px; padding: 5px 6px 5px 12px;
  background: var(--green-soft); border: 1px solid #bfe5cd; border-radius: 999px; font-size: 14px; max-width: 420px;
}
.timer-chip .tc-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--green); }
.timer-chip .tc-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.timer-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: pulse 1.4s infinite; flex-shrink: 0; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- Logowanie ---------- */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #16213a, #2f4b80); }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: var(--radius);
  padding: 32px 28px; box-shadow: 0 10px 30px rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 14px;
}
.login-brand { font-size: 40px; text-align: center; }
.login-card h1 { margin: 0; text-align: center; font-size: 24px; }
.login-sub { margin: -8px 0 6px; text-align: center; color: var(--muted); font-size: 14px; }
.login-card .btn { padding: 11px; }

/* ---------- Karty, sekcje ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.section-head { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
.section-head h2 { font-size: 16px; }
.section-head .count { background: var(--gray-soft); border-radius: 999px; padding: 1px 9px; font-size: 13px; color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; }
.empty { color: var(--muted); padding: 14px 16px; font-size: 14px; }
.banner { padding: 12px 16px; border-radius: 10px; background: var(--yellow-soft); border: 1px solid #f1df9c; margin-bottom: 18px; font-size: 14px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 22px; }
.kpi { padding: 14px 16px; }
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.kpi-hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.red .kpi-value { color: var(--red); }
.kpi.orange .kpi-value { color: var(--orange); }
a.kpi { text-decoration: none; color: inherit; }

.dash { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.dash-col { display: flex; flex-direction: column; gap: 20px; }

/* ---------- Lista zadań ---------- */
.task-list { display: flex; flex-direction: column; }
.task-row {
  display: grid; grid-template-columns: 6px auto minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; background: var(--surface);
}
.task-list > .task-row:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.task-list > .task-row:last-child { border-bottom: 0; border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.task-row:hover { background: var(--surface-2); }
.task-row .prio-bar { width: 6px; align-self: stretch; border-radius: 3px; }
.task-row .t-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.task-row .t-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.task-row .t-side { display: flex; align-items: center; gap: 8px; }
.task-row.done .t-title { text-decoration: line-through; color: var(--muted); }
.late { color: var(--red) !important; font-weight: 600; }

.prio-awaria { background: var(--red); }
.prio-pilne { background: var(--orange); }
.prio-normalne { background: var(--green); }
.prio-kiedys { background: var(--gray); }

.cbadge {
  display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 700;
  color: #fff; letter-spacing: .02em; white-space: nowrap;
}
.status {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--gray-soft); color: var(--muted);
}
.status.s-nowe { background: var(--accent-soft); color: var(--accent); }
.status.s-zaplanowane { background: #ece9fd; color: #6247d6; }
.status.s-w_trakcie { background: var(--green-soft); color: var(--green); }
.status.s-czeka { background: var(--orange-soft); color: var(--orange); }
.status.s-zrobione { background: var(--gray-soft); color: var(--muted); }
.play {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-size: 13px; display: grid; place-items: center; flex-shrink: 0;
}
.play:hover { background: var(--green-soft); border-color: #bfe5cd; }
.play.on { background: var(--green); color: #fff; border-color: var(--green); }

/* Obciążenie dni */
.load { display: flex; flex-direction: column; gap: 9px; }
.load-row { display: grid; grid-template-columns: 74px 1fr 92px; gap: 10px; align-items: center; font-size: 13px; }
.load-bar { height: 10px; background: var(--gray-soft); border-radius: 5px; overflow: hidden; }
.load-bar > div { height: 100%; background: var(--green); border-radius: 5px; }
.load-bar.warn > div { background: var(--orange); }
.load-bar.over > div { background: var(--red); }

.mini-list { display: flex; flex-direction: column; }
.mini-list > div { display: flex; gap: 10px; align-items: center; padding: 9px 16px; border-top: 1px solid var(--border); font-size: 14px; }
.mini-list > div:first-child { border-top: 0; }
.mini-list .ml-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-list > div[data-href] { cursor: pointer; }
.mini-list > div[data-href]:hover { background: var(--surface-2); }

/* ---------- Tabele ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr[data-href], .tbl tbody tr[data-edit] { cursor: pointer; }
.tbl tbody tr[data-href]:hover, .tbl tbody tr[data-edit]:hover { background: var(--surface-2); }
.tbl tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }
.tbl .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl tr.inactive td { color: var(--muted); }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* ---------- Klienci ---------- */
.client-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.client-card { padding: 16px 18px; text-decoration: none; color: inherit; border-top: 4px solid; display: flex; flex-direction: column; gap: 8px; }
.client-card:hover { box-shadow: 0 4px 14px rgba(20, 30, 60, .1); }
.client-card h3 { font-size: 17px; }
.client-card .cc-line { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.client-card.inactive { opacity: .55; }
.client-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; padding: 18px 20px; border-left: 6px solid; margin-bottom: 16px; }
.client-head h2 { font-size: 22px; }
.client-head .ch-info { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 14px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  border: 0; background: none; font: inherit; font-size: 14px; padding: 10px 14px; cursor: pointer;
  color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.pre { white-space: pre-wrap; word-break: break-word; }
.progress { height: 6px; background: var(--gray-soft); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--accent); }

/* ---------- Plan tygodnia ---------- */
.plan { display: grid; grid-template-columns: repeat(8, minmax(150px, 1fr)); gap: 10px; overflow-x: auto; padding-bottom: 10px; }
.plan-col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 300px; }
.plan-col.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.plan-col.drop { background: var(--accent-soft); }
.plan-col.weekend { opacity: .8; }
.plan-head { padding: 10px 12px 8px; border-bottom: 1px solid var(--border); }
.plan-head .ph-day { font-weight: 700; font-size: 14px; }
.plan-head .ph-load { font-size: 12px; color: var(--muted); margin-top: 4px; }
.plan-head .load-bar { height: 6px; margin-top: 5px; }
.plan-cards { padding: 8px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.plan-card {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid; border-radius: 8px;
  padding: 7px 9px; font-size: 13px; cursor: grab;
}
.plan-card .pc-title { font-weight: 600; line-height: 1.3; }
.plan-card .pc-meta { display: flex; gap: 6px; align-items: center; margin-top: 4px; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }
.plan-card.dragging { opacity: .4; }

/* ---------- Dialogi ---------- */
.dialog {
  border: 0; border-radius: var(--radius); padding: 0; width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 24px); box-shadow: 0 20px 50px rgba(0,0,0,.25); color: var(--text);
}
.dialog-wide { width: min(860px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(15, 22, 40, .5); }
.dialog-form { padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.dialog-form h2 { font-size: 19px; }
.dialog-buttons { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.field-hint { font-size: 12px; color: var(--muted); }
.client-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.client-pick button {
  padding: 9px 6px; border: 2px solid transparent; border-radius: 8px; color: #fff; font: inherit;
  font-weight: 700; font-size: 13px; cursor: pointer; opacity: .55;
}
.client-pick button.on { opacity: 1; border-color: var(--text); box-shadow: 0 0 0 2px #fff inset; }
.task-dlg-head { display: flex; gap: 10px; align-items: center; padding: 16px 22px 0; }
.task-sub { border-top: 1px solid var(--border); padding-top: 14px; }
.task-sub h3 { font-size: 15px; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.time-add { display: grid; grid-template-columns: 140px 110px 1fr auto; gap: 8px; align-items: end; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; }
details summary { cursor: pointer; color: var(--accent); font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: #1c2333; color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: calc(100vw - 32px);
}

/* ---------- Telefon ---------- */
@media (max-width: 900px) {
  .dash { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
  .burger { display: block; }
  .topbar { padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  .topbar-add { display: none; }
  .timer-chip { order: 3; width: 100%; max-width: none; }
  .content { padding: 16px 14px 110px; }
  .fab {
    display: grid; place-items: center; position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
    width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
    font-size: 30px; box-shadow: 0 6px 18px rgba(47, 111, 219, .45); z-index: 30; cursor: pointer;
  }
  .form-grid { grid-template-columns: 1fr; }
  .time-add { grid-template-columns: 1fr 1fr; }
  .time-add .ta-note { grid-column: 1 / -1; }
  .dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
  .task-row { grid-template-columns: 5px minmax(0, 1fr) auto; }
  .task-row .t-client { display: none; }
  .mobile-only { display: inline; }
  .plan { grid-template-columns: 1fr; }
  .plan-col { min-height: 0; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .toolbar input[type=search] { max-width: none; }
}

/* ---------- Wydruk (raport dla klienta) ---------- */
@media print {
  .sidebar, .topbar, .fab, .toolbar, .no-print { display: none !important; }
  body, .card { background: #fff; box-shadow: none; }
  .content { padding: 0; }
}
