:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #e2e5ea;
    --border-strong: #cfd4dc;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #2563eb;
    --danger: #dc2626;
    --current: #fff7e0;
    --current-head: #fde68a;
    --drop: #dbeafe;
    --emp-col: 220px;
    --week-col: 88px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font: 14px/1.4 "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--text);
    background: var(--bg);
}

a { color: var(--primary); }
.muted { color: var(--muted); }

/* ---------- Nagłówek ---------- */
.topbar {
    display: flex;
    align-items: center;
    gap: 32px;
    padding: 0 24px;
    height: 52px;
    background: #111827;
    color: #fff;
}
.brand { font-weight: 600; font-size: 16px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
    color: #cbd5e1;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
}
.topbar nav a:hover { background: #1f2937; color: #fff; }
.topbar nav a.active { background: #374151; color: #fff; }

.container { max-width: 960px; margin: 24px auto; padding: 0 16px; }
.container-wide { margin: 16px; }

.flash {
    background: #dcfce7;
    border: 1px solid #86efac;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 16px;
}

h1 { font-size: 22px; margin: 0 0 16px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.page-head h1 { margin: 0; }

/* ---------- Przyciski i formularze ---------- */
.btn {
    display: inline-block;
    padding: 6px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font: inherit;
    cursor: pointer;
}
.btn:hover { background: #f3f4f6; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }

.form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.form small { color: var(--muted); font-weight: 400; }
.form input[type=text], select {
    padding: 7px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    font: inherit;
}
.form input[type=color] { width: 56px; height: 34px; padding: 2px; border: 1px solid var(--border-strong); border-radius: 6px; }
.color-row { display: flex; align-items: center; gap: 12px; }
.swatches { display: flex; flex-wrap: wrap; gap: 4px; }
.swatch { width: 22px; height: 22px; border-radius: 4px; border: 1px solid rgba(0,0,0,.15); cursor: pointer; }
.error { color: var(--danger); font-size: 13px; margin-top: -8px; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }

/* ---------- Listy ---------- */
.list {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.list th, .list td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.list th { background: #f9fafb; font-weight: 600; color: var(--muted); font-size: 13px; }
.list .num { text-align: right; }
.list .actions { display: flex; gap: 6px; justify-content: flex-end; }
.list .actions form { margin: 0; }
.list .empty { text-align: center; color: var(--muted); padding: 24px; }

/* ---------- Bloczek projektu ---------- */
.chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    cursor: grab;
    user-select: none;
    box-shadow: 0 1px 1px rgba(0,0,0,.15);
}
.chip.static { cursor: default; }
.chip:focus { outline: 2px solid #111827; outline-offset: 1px; }
.chip.drag-src { opacity: .4; }
.chip-del {
    display: none;
    position: absolute;
    top: -7px;
    right: -7px;
    width: 16px;
    height: 16px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: #111827;
    color: #fff;
    font-size: 12px;
    line-height: 16px;
    cursor: pointer;
}
.cell .chip:hover .chip-del, .cell .chip:focus .chip-del { display: block; }
body.dragging .chip-del { display: none !important; }

.flash-in { animation: flash-in .5s ease-out; }
@keyframes flash-in {
    from { transform: scale(1.25); box-shadow: 0 0 0 4px rgba(37,99,235,.4); }
    to   { transform: scale(1); }
}

/* ---------- Grafik ---------- */
.schedule-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.nav-weeks { display: flex; gap: 6px; align-items: center; }
.nav-weeks form.inline { margin: 0 0 0 8px; }
.hint { color: var(--muted); font-size: 13px; }
kbd {
    padding: 1px 5px;
    border: 1px solid var(--border-strong);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: var(--surface);
    font: 12px monospace;
}

.palette {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 12px;
}
.palette-label { font-weight: 600; color: var(--muted); margin-right: 4px; }
.palette .chip { font-size: 13px; padding: 4px 10px; cursor: grab; }
.palette .chip.selected { outline: 2px solid #111827; outline-offset: 2px; }
.trash {
    margin-left: auto;
    padding: 6px 14px;
    border: 2px dashed var(--border-strong);
    border-radius: 6px;
    color: var(--muted);
    transition: all .15s;
}
body.dragging .trash { border-color: var(--danger); color: var(--danger); }
.trash.drop-target { background: #fee2e2; transform: scale(1.05); }

.grid-wrap {
    overflow: auto;
    max-height: calc(100vh - 210px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.grid {
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
}
.grid th, .grid td {
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.grid thead th {
    position: sticky;
    background: #f9fafb;
    font-weight: 600;
    z-index: 2;
}
.grid thead tr.months th { top: 0; height: 28px; font-size: 12px; text-transform: capitalize; color: var(--muted); }
.grid thead tr.weeks th { top: 28px; width: var(--week-col); min-width: var(--week-col); padding: 4px; text-align: center; }
.grid thead th.current { background: var(--current-head); }
.wk-no { font-size: 13px; }
.wk-date { font-size: 11px; color: var(--muted); font-weight: 400; }

.grid .emp-col {
    position: sticky;
    left: 0;
    width: var(--emp-col);
    min-width: var(--emp-col);
    padding: 6px 10px;
    text-align: left;
    background: var(--surface);
    z-index: 1;
    border-right: 1px solid var(--border-strong);
}
.grid thead .emp-col { z-index: 3; top: 0; background: #f9fafb; vertical-align: bottom; color: var(--muted); }
.emp-name { font-weight: 600; }
.emp-pos { font-size: 12px; color: var(--muted); font-weight: 400; }

.grid td.cell {
    vertical-align: top;
    padding: 6px 5px;
    height: 48px;
}
.grid td.cell.current { background: var(--current); }
.grid td.cell .chip { margin: 2px; }
.grid tbody tr:hover th.emp-col, .grid tbody tr:hover td.cell { box-shadow: inset 0 0 0 9999px rgba(0,0,0,.02); }

.grid td.cell.drop-target { background: var(--drop); box-shadow: inset 0 0 0 2px var(--primary); }
body.drag-copy .grid td.cell.drop-target { background: #dcfce7; box-shadow: inset 0 0 0 2px #16a34a; }

.grid.dimmed .chip { opacity: .2; }
.grid.dimmed .chip.hl { opacity: 1; box-shadow: 0 0 0 2px #111827; }

/* ---------- Dymek ---------- */
.tip {
    --arrow-x: 50%;
    position: fixed;
    z-index: 50;
    min-width: 240px;
    max-width: 320px;
    background: var(--surface);
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .18), 0 2px 6px rgba(15, 23, 42, .08);
    border: 1px solid var(--border);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity .12s, transform .12s;
}
.tip.show { opacity: 1; transform: translateY(0); }
.tip::before {
    content: "";
    position: absolute;
    top: -6px;
    left: calc(var(--arrow-x) - 6px);
    width: 12px;
    height: 12px;
    background: var(--tip-arrow, var(--surface));
    transform: rotate(45deg);
}
.tip.above::before {
    background: var(--surface);
    top: auto;
    bottom: -6px;
    border: none;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.tip-head {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 9px 9px 0 0;
}
.tip-code { font-weight: 700; font-size: 14px; letter-spacing: .3px; }
.tip-client { font-size: 12px; opacity: .9; }
.tip-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.tip-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.tip-row { display: flex; justify-content: space-between; gap: 16px; font-size: 12px; }
.tip-row span { color: var(--muted); }
.tip-row b { font-weight: 600; text-align: right; }
.tip-foot {
    padding: 6px 12px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--muted);
    background: #f9fafb;
    border-radius: 0 0 9px 9px;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 10px 16px;
    border-radius: 6px;
    background: #111827;
    color: #fff;
    opacity: 0;
    pointer-events: none;
    transition: all .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
