:root {
  --brand: #1a6dff;
  --brand-soft: #e8f0ff;
  --ink: #18202e;
  --muted: #6b7486;
  --line: #e3e7ee;
  --bg: #f5f7fa;
  --card: #ffffff;
  --side: #121826;
  --ok: #1f9d55;
  --warn: #d97706;
  --bad: #d64545;
  --radius: 10px;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --surface-2: #fafbfc;
  --hover: #f7f9ff;
  --col: #eceff4;
  --border-strong: #c5ccd8;
  --primary-hover: #0f5be0;
  --overlay: rgba(15, 20, 30, .45);
  --shadow: rgba(0, 0, 0, .18);
  --toast-bg: #18202e;
  --toast-ink: #ffffff;
  --other-day: #b0b7c4;
  --pill-bg: #eef1f5; --pill-ink: #3b4456;
  --studio-bg: #e8f0ff; --studio-ink: #1748a8;
  --trip-bg: #fff0e0; --trip-ink: #9a4a00; --trip-line: #f08a24;
  --ok-bg: #e3f6ea; --ok-ink: #136c3a;
  --warn-bg: #fff4db; --warn-ink: #8a5a00;
  --bad-bg: #fde8e8; --bad-ink: #9b2c2c;
  --dl-bg: #f4f1fb;
  --banner-bg: #fff4e5; --banner-line: #f5c98a; --banner-ink: #8a4b00;
  color-scheme: light;
}
/* Tryb ciemny: wybrany ręcznie albo systemowy (gdy w aplikacji wybrano „Systemowy”) */
:root[data-theme="dark"] {
  --brand: #3d85ff;
  --brand-soft: #1b2a47;
  --ink: #e6e9ef;
  --muted: #98a1b3;
  --line: #2b3343;
  --bg: #0f131b;
  --card: #171c26;
  --side: #0a0d13;
  --ok: #3cc477;
  --warn: #f0a33a;
  --bad: #f06b6b;
  --series-1: #3987e5;
  --series-2: #d95926;
  --surface-2: #1c2230;
  --hover: #1f2738;
  --col: #131822;
  --border-strong: #3b4558;
  --primary-hover: #2f74ea;
  --overlay: rgba(0, 0, 0, .6);
  --shadow: rgba(0, 0, 0, .5);
  --toast-bg: #e6e9ef;
  --toast-ink: #0f131b;
  --other-day: #4c5568;
  --pill-bg: #252c3a; --pill-ink: #c3cad8;
  --studio-bg: #1b2a47; --studio-ink: #9cc0ff;
  --trip-bg: #3a2614; --trip-ink: #ffbe85; --trip-line: #f08a24;
  --ok-bg: #133524; --ok-ink: #7fe0a8;
  --warn-bg: #3a2c0f; --warn-ink: #f5c86a;
  --bad-bg: #3d1c1c; --bad-ink: #ff9d9d;
  --dl-bg: #241f36;
  --banner-bg: #3a2a12; --banner-line: #6b4a1a; --banner-ink: #f5c98a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
  padding-left: 220px;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.pad { padding: 24px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Sidebar */
.sidebar { background: var(--side); color: #cfd6e4; display: flex; flex-direction: column; width: 220px; height: 100vh; position: fixed; top: 0; left: 0; overflow-y: auto; z-index: 20; }
.brand { padding: 18px 0 8px; text-align: center; }
.brand img { height: 92px; }
#nav { display: flex; flex-direction: column; padding: 8px; gap: 2px; flex: 1; }
#nav a { color: #cfd6e4; padding: 9px 12px; border-radius: 8px; }
#nav a:hover { background: #1e2738; text-decoration: none; }
#nav a.active { background: var(--brand); color: #fff; }
.whoami { padding: 14px; border-top: 1px solid #222b3d; font-size: 12px; }
.whoami label { display: block; margin-bottom: 4px; color: #8a94a8; }
.whoami select { width: 100%; background: #1e2738; color: #fff; border: 1px solid #2c374d; }

/* Layout */
main { padding: 24px 28px 60px; min-width: 0; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head h1 { margin-right: auto; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.stat .v { font-size: 26px; font-weight: 600; }
.stat .l { color: var(--muted); font-size: 12px; }
.banner { background: var(--banner-bg); border: 1px solid var(--banner-line); color: var(--banner-ink); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }

/* Controls */
button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: var(--border-strong); }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: var(--primary-hover); }
button.danger { color: var(--bad); }
button.small { padding: 3px 8px; font-size: 12px; }
input, select, textarea {
  font: inherit; color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 9px; background: var(--card); width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select, .filters input { width: auto; min-width: 150px; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--hover); }
tfoot td { font-weight: 600; background: var(--surface-2); }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }

/* Pills */
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--pill-bg); color: var(--pill-ink); white-space: nowrap; }
.pill.studio { background: var(--studio-bg); color: var(--studio-ink); }
.pill.wyjazd { background: var(--trip-bg); color: var(--trip-ink); }
.pill.ok { background: var(--ok-bg); color: var(--ok-ink); }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill.bad { background: var(--bad-bg); color: var(--bad-ink); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; }
.list li:last-child { border-bottom: 0; }
.list .when { width: 92px; flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.list .grow { flex: 1; min-width: 0; }

/* Kanban */
.kanban { display: grid; grid-template-columns: repeat(6, minmax(190px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--col); border-radius: var(--radius); padding: 10px; min-height: 300px; }
.col.over { outline: 2px dashed var(--brand); }
.col h3 { display: flex; justify-content: space-between; }
.kcard { background: var(--card); border-radius: 8px; padding: 10px; margin-bottom: 8px; border: 1px solid var(--line); cursor: grab; }
.kcard:hover { border-color: var(--brand); }
.kcard .t { font-weight: 600; margin-bottom: 4px; }
.kcard .m { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.late { color: var(--bad); font-weight: 600; }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); gap: 1px; }
.cal .dn { background: var(--surface-2); padding: 6px; font-size: 12px; color: var(--muted); text-align: center; }
.cal .day { background: var(--card); min-height: 104px; padding: 4px 5px; cursor: pointer; min-width: 0; }
.cal .day:hover { background: var(--hover); }
.cal .day.other { background: var(--surface-2); color: var(--other-day); }
.cal .day.today .d { background: var(--brand); color: #fff; border-radius: 99px; padding: 0 6px; }
.cal .d { font-size: 12px; font-weight: 600; display: inline-block; margin-bottom: 3px; }
.ev { font-size: 11.5px; padding: 2px 5px; border-radius: 5px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 3px solid; }
.ev.studio { background: var(--studio-bg); border-color: var(--brand); }
.ev.wyjazd { background: var(--trip-bg); border-color: var(--trip-line); }

/* Modal */
.overlay { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; z-index: 50; }
.modal { background: var(--card); border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 50px var(--shadow); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal header h2 { margin: 0; flex: 1; }
.modal .body { padding: 18px 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.modal .field { display: flex; flex-direction: column; gap: 4px; }
.modal .field.full { grid-column: 1 / -1; }
.modal .field > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.modal footer .sp { flex: 1; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { display: flex; gap: 5px; align-items: center; font-size: 13px; }
.checks input { width: auto; }

/* Toast */
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; }
#toast div { background: var(--toast-bg); color: var(--toast-ink); padding: 10px 16px; border-radius: 8px; margin-top: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
#toast div.err { background: var(--bad); }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.empty { color: var(--muted); padding: 14px 0; text-align: center; }
.team-card { border-top: 4px solid; }

@media (max-width: 900px) {
  body { padding-left: 0; }
  .sidebar { width: auto; height: auto; position: static; }
  .brand { display: none; }
  #nav { flex-direction: row; overflow-x: auto; }
  .g2, .g4 { grid-template-columns: 1fr; }
  .modal .body { grid-template-columns: 1fr; }
  main { padding: 16px; }
}

/* Logowanie, powiadomienia, nowe elementy */
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 99px; background: var(--bad); color: #fff; font-size: 11px; text-align: center; margin-left: 4px; }
.badge:empty { display: none; }
body.montaz [data-admin], body:not(.montaz) [data-employee], body.montaz:not(.leads) [data-leads] { display: none !important; }
body.login { padding-left: 0; }
body.login .sidebar { display: none; }
.login-box { max-width: 360px; margin: 10vh auto; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 12px; }
.login-box img { height: 110px; justify-self: center; background: var(--side); border-radius: 12px; padding: 8px 20px; }
.whoami b { color: #fff; display: block; margin-bottom: 6px; }
.whoami button { background: #1e2738; color: #cfd6e4; border-color: #2c374d; font-size: 12px; padding: 4px 8px; }
.pill.wynajem { background: var(--ok-bg); color: var(--ok-ink); }
.ev.wynajem { background: var(--ok-bg); border-color: var(--ok); }
.notif li { align-items: center; }
.notif .ico { width: 22px; flex: none; text-align: center; }
.files li a { word-break: break-all; }
.videos td select, .videos td input { padding: 3px 6px; font-size: 13px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .tip { position: absolute; pointer-events: none; background: var(--toast-bg); color: var(--toast-ink); font-size: 12px; padding: 6px 9px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%); display: none; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.pos { color: var(--ok); } .neg { color: var(--bad); }

/* Przełącznik kalendarza i terminy montażu */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--card); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--brand); color: #fff; }
.ev.dl { background: var(--dl-bg); border-left: 3px solid; }
.ev.dl.over { background: var(--bad-bg); color: var(--bad-ink); }
.ev.dl.done { text-decoration: line-through; color: var(--muted); }
.ev.faded { opacity: .38; filter: saturate(.25); }
.ev.faded:hover { opacity: .8; }
.code-box { font-size: 34px; font-weight: 700; letter-spacing: .25em; text-align: center; padding: 14px; background: var(--brand-soft); border-radius: 10px; font-variant-numeric: tabular-nums; }

/* Pole klienta z wyszukiwaniem */
.combo { position: relative; }
.combo-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px var(--shadow); max-height: 260px; overflow-y: auto; z-index: 5; }
.combo-item { padding: 7px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.combo-item small { color: var(--muted); white-space: nowrap; }
.combo-item.on { background: var(--brand-soft); }
.combo-item.add { color: var(--brand); font-weight: 600; border-top: 1px solid var(--line); }
.with-btn { display: flex; gap: 8px; }
.with-btn input { flex: 1; }
.field[hidden] { display: none !important; }
.ev.done-ev { opacity: .75; }

/* Wiele pozycji w jednym wpisie */
.lines { display: grid; gap: 6px; margin-bottom: 6px; }
.line { display: grid; grid-template-columns: minmax(0, 1fr) 90px auto; gap: 6px; align-items: center; }
body:not(.montaz) .line { grid-template-columns: minmax(0, 1fr) 70px 135px 135px auto; }
[data-addline] { justify-self: start; }
.field > [data-addline] { align-self: flex-start; }
@media (max-width: 900px) { body:not(.montaz) .line, .line { grid-template-columns: 1fr 1fr; } }

/* Przełącznik motywu */
.theme-switch { display: flex; gap: 0; margin-top: 8px; border: 1px solid #2c374d; border-radius: 8px; overflow: hidden; }
.theme-switch button { flex: 1; border: 0; border-radius: 0; background: #1e2738; color: #cfd6e4; font-size: 12px; padding: 4px 0; }
.theme-switch button + button { border-left: 1px solid #2c374d; }
.theme-switch button.on { background: var(--brand); color: #fff; }
.login-theme { position: fixed; top: 14px; right: 14px; width: 210px; }
.login-theme button { background: var(--card); color: var(--ink); }
.login-theme, .login-theme button + button { border-color: var(--line); }
input[type="date"], input[type="time"] { color-scheme: inherit; }
:root[data-theme="dark"] .sidebar { border-right: 1px solid var(--line); }
