/* CRM Zadania – prosty, jasny interfejs biznesowy */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .18);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
code { font-family: var(--mono); font-size: 12px; }

/* ---------- Przyciski ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 6px; padding: 7px 14px;
  font-weight: 600; font-size: 13px; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-alt); }
.btn-outline { background: var(--surface); color: var(--primary); border-color: #bfdbfe; }
.btn-outline:hover:not(:disabled) { background: var(--primary-soft); }
.btn-danger-outline { background: var(--surface); color: var(--danger); border-color: #fecaca; }
.btn-danger-outline:hover:not(:disabled) { background: #fef2f2; }
.btn-xs { padding: 3px 9px; font-size: 12px; border-radius: 5px; }
.btn-block { width: 100%; padding: 10px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font-size: 12px; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
.icon-btn { background: none; border: 0; font-size: 24px; line-height: 1; cursor: pointer; color: var(--text-muted); padding: 2px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-alt); color: var(--text); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Pola formularzy ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea,
.picker-input, .notes-input, .users input, .users select {
  border: 1px solid var(--border-strong); border-radius: 6px; padding: 7px 10px; background: #fff; min-width: 0;
}
.field textarea, .notes-input { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
.field-inline { flex-direction: row; align-items: center; gap: 6px; margin: 0; }
.field-inline > span { white-space: nowrap; }
.req { color: var(--danger); font-style: normal; }
.hint { font-size: 12px; color: var(--text-muted); margin: 2px 0 10px; }
.form-error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; border-radius: 6px; padding: 8px 12px; margin: 0 0 12px; }
.form-error.info { background: var(--primary-soft); border-color: #bfdbfe; color: #1e3a8a; }
.counter { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.counter.warn { color: #b45309; font-weight: 600; }
.counter.over { color: var(--danger); font-weight: 700; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0 12px; }

/* ---------- Logowanie ---------- */
.login-view { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 32px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 18px; margin: 18px 0 18px; }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand-mark { background: var(--primary); color: #fff; border-radius: 6px; padding: 3px 7px; font-size: 12px; letter-spacing: .5px; }
.brand-lg { font-size: 20px; }

/* ---------- Układ aplikacji ---------- */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.me { display: flex; align-items: center; gap: 8px; }
.me-name { font-weight: 600; }
.role-badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; padding: 2px 8px; border-radius: 999px; background: #e2e8f0; color: #334155; }
.role-admin { background: #fee2e2; color: #991b1b; }
.role-manager { background: #fef3c7; color: #92400e; }
.role-user { background: #dbeafe; color: #1e40af; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 14px 20px; }
.field-search { margin: 0; flex: 1 1 260px; max-width: 420px; }
.field-search input { width: 100%; }

.table-card { flex: 1; min-height: 0; display: flex; flex-direction: column; margin: 0 20px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-card.loading .table-scroll { opacity: .6; transition: opacity .2s; }
.table-scroll { flex: 1; min-height: 0; overflow: auto; }

/* ---------- Tabela zadań ---------- */
table.tasks { width: 100%; min-width: 1440px; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
col.c-lp { width: 54px; } col.c-date { width: 104px; } col.c-subject { width: 24%; } col.c-user { width: 150px; }
col.c-status { width: 258px; } col.c-notes { width: 22%; } col.c-att { width: 280px; } col.c-transfer { width: 240px; }
.tasks thead th {
  position: sticky; top: 0; z-index: 2; background: #f1f5f9; text-align: left; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .3px; color: #475569; padding: 10px 12px; border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.tasks thead th .sort { background: none; border: 0; padding: 0; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.tasks thead th .sort:hover, .tasks thead th .sort.active { color: var(--primary); }
.sort-ind { font-size: 10px; opacity: .8; }
.tasks td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.tasks tbody tr:nth-child(even) td { background: var(--surface-alt); }
.tasks tbody tr:hover td { background: #f0f7ff; }
.tasks tbody tr.flash td { animation: flash 2.4s ease-out; }
@keyframes flash { 0%, 30% { background: #fef9c3; } }
.c-lp { font-variant-numeric: tabular-nums; color: var(--text-muted); font-weight: 600; text-align: right; }
.tasks thead th:first-child { text-align: right; }
.c-date { font-variant-numeric: tabular-nums; white-space: nowrap; }

.subject-text { white-space: pre-wrap; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; font-weight: 500; }
.subject-text.expanded { display: block; -webkit-line-clamp: unset; overflow: visible; }
.cell-actions { display: flex; gap: 12px; margin-top: 6px; }

.user-name { font-weight: 600; display: block; }
.tag-inactive { display: inline-block; margin-top: 2px; font-size: 11px; color: #9a3412; background: #ffedd5; border-radius: 4px; padding: 0 6px; }

/* Statusy – etykiety kolorystyczne */
.status-select, .status-pill {
  border-radius: 999px; font-weight: 600; font-size: 12px; padding: 5px 10px; border: 1px solid; max-width: 100%;
}
.status-select { width: 100%; cursor: pointer; }
.status-pill { display: inline-block; }
.s-todo,        .status-pill[data-status="Do zrobienia"] { background: #f1f5f9; color: #334155; border-color: #cbd5e1; }
.s-progress    { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.s-transferred { background: #ede9fe; color: #5b21b6; border-color: #c4b5fd; }
.s-done        { background: #dcfce7; color: #166534; border-color: #86efac; }
.s-waiting     { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.status-select option { background: #fff; color: var(--text); }

/* Uwagi */
.notes-input { width: 100%; min-height: 58px; font-size: 13px; }
.notes-input.dirty { border-color: #f59e0b; background: #fffbeb; }
.notes-foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: 4px; min-height: 24px; }
.notes-actions { display: inline-flex; gap: 4px; }

/* Załączniki */
.att-block { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.att-list { list-style: none; margin: 0; padding: 0; width: 100%; display: flex; flex-direction: column; gap: 6px; }
.att { border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; background: #fff; display: grid; gap: 2px; }
.att-head { display: flex; align-items: center; gap: 6px; min-width: 0; }
.att-ext { flex: none; font-size: 10px; font-weight: 700; color: #fff; background: #64748b; border-radius: 3px; padding: 1px 4px; }
.att-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-meta { font-size: 11px; color: var(--text-muted); }
.att-path { font-size: 11px; color: #475569; background: #f1f5f9; border-radius: 3px; padding: 1px 4px; overflow-wrap: anywhere; }
.att .btn { justify-self: start; margin-top: 2px; }

/* Przekazywanie */
.transfer { display: flex; gap: 6px; align-items: flex-start; }
.picker { flex: 1; min-width: 0; }
.picker-input { width: 100%; font-size: 13px; padding: 5px 8px; }
.picker-input.chosen { border-color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.picker-menu {
  position: fixed; z-index: 1000; max-height: 260px; overflow-y: auto; background: #fff;
  border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--shadow-lg); padding: 4px;
}
.picker-item { display: flex; flex-direction: column; padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.picker-item.hi { background: var(--primary-soft); }
.picker-item.sel .pi-name::after { content: " ✓"; color: var(--primary); }
.pi-name { font-weight: 600; }
.pi-login { font-size: 11px; color: var(--text-muted); }
.picker-empty { padding: 8px 10px; color: var(--text-muted); font-size: 13px; }

.empty { padding: 40px; text-align: center; color: var(--text-muted); }

/* Stronicowanie */
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 14px; border-top: 1px solid var(--border); background: var(--surface); }
.pager-info { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.pager-controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.pages { display: flex; gap: 4px; align-items: center; }
.page-btn { min-width: 32px; height: 32px; border: 1px solid var(--border-strong); background: #fff; border-radius: 6px; cursor: pointer; font-weight: 600; }
.page-btn:hover:not(:disabled) { background: var(--surface-alt); }
.page-btn.current { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: default; }
.page-gap { padding: 0 4px; color: var(--text-muted); }

/* ---------- Okna dialogowe ---------- */
.dialog { border: 0; border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: var(--shadow-lg); color: var(--text); }
.dialog-wide { width: min(1080px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(15, 23, 42, .45); }
.dialog > form, .dialog { display: flex; flex-direction: column; }
.dialog:not([open]) { display: none; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { margin: 0; font-size: 17px; }
.dialog-body { padding: 18px 20px; overflow: auto; }
.dialog-body .field textarea, .dialog-body .field input, .dialog-body .field select { width: 100%; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-alt); border-radius: 0 0 12px 12px; }

.meta { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin: 0 0 16px; padding: 12px; background: var(--surface-alt); border: 1px solid var(--border); border-radius: 8px; }
.meta dt { font-size: 11px; text-transform: uppercase; letter-spacing: .3px; color: var(--text-muted); font-weight: 700; }
.meta dd { margin: 2px 0 0; font-weight: 600; }
.det-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; }
.det-section { margin-bottom: 18px; }
.det-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: #475569; margin: 0 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.field-status select { max-width: 280px; }
.form-actions { display: flex; justify-content: flex-end; }

.history { list-style: none; margin: 0; padding: 0; }
.history li { display: grid; grid-template-columns: 130px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.h-time { font-variant-numeric: tabular-nums; color: var(--text-muted); font-size: 13px; }
.h-detail { color: #334155; }
.h-user { font-size: 12px; color: var(--text-muted); }

/* Użytkownicy */
.user-form { padding: 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-alt); margin-bottom: 18px; }
.user-form h3 { margin: 0 0 10px; font-size: 14px; }
.users-scroll { border: 1px solid var(--border); border-radius: 8px; max-height: 50vh; }
table.users { width: 100%; min-width: 900px; border-collapse: separate; border-spacing: 0; }
.users th { position: sticky; top: 0; background: #f1f5f9; text-align: left; font-size: 12px; text-transform: uppercase; color: #475569; padding: 8px 10px; border-bottom: 1px solid var(--border-strong); }
.users td { padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users tbody tr:nth-child(even) td { background: var(--surface-alt); }
.users tr.inactive td { color: var(--text-muted); }
.users input { width: 100%; padding: 4px 8px; }
.users select { padding: 4px 8px; }
.users .actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pw-box { display: inline-flex; gap: 4px; }
.pw-input { width: 140px !important; }
.tag { font-size: 11px; font-weight: 700; border-radius: 999px; padding: 2px 8px; }
.tag-ok { background: #dcfce7; color: #166534; }
.tag-off { background: #f1f5f9; color: #64748b; }

/* Powiadomienia */
.toasts { position: fixed; top: 16px; right: 16px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; max-width: min(440px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: 10px; background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--success); border-radius: 8px; padding: 10px 12px; box-shadow: var(--shadow-lg); animation: tin .2s ease-out; transition: opacity .4s, transform .4s; }
.toast.hide { opacity: 0; transform: translateX(20px); }
.toast-error { border-left-color: var(--danger); }
.toast-icon { flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 800; color: #fff; background: var(--success); }
.toast-error .toast-icon { background: var(--danger); }
.toast > span:nth-child(2) { flex: 1; }
.toast-close { background: none; border: 0; cursor: pointer; font-size: 18px; line-height: 1; color: var(--text-muted); }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } }

/* ---------- Małe ekrany ---------- */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; padding: 10px 12px; }
  .toolbar { padding: 12px; }
  .table-card { margin: 0 8px 8px; }
  .grid-5 { grid-template-columns: 1fr 1fr; }
  .det-grid, .grid-2 { grid-template-columns: 1fr; }
  .meta { grid-template-columns: 1fr 1fr; }
  .history li { grid-template-columns: 1fr; gap: 2px; }
  .me-name { display: none; }
  .app { height: auto; min-height: 100vh; }
  .table-card { flex: none; }
  .table-scroll { max-height: 78vh; }
}
