:root {
  color-scheme: light;
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-soft: #f7f8fa;
  --line: #dfe5ea;
  --text: #151b22;
  --muted: #66717d;
  --accent: #14796f;
  --accent-dark: #0f5f58;
  --danger: #b83f3a;
  --ok: #16835d;
  --shadow: 0 18px 50px rgba(18, 28, 38, .09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.login-card { width: min(460px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.login-card h1 { margin: 26px 0 10px; }
.login-card p { color: var(--muted); line-height: 1.55; }
.login-card form { display: grid; gap: 14px; margin-top: 20px; }
.login-card .brand { color: var(--text); padding: 0; }
.login-card .brand span { display: block; color: var(--muted); font-size: 13px; }
.small { color: var(--muted); font-size: 13px; }

.shell { display: grid; grid-template-columns: 272px minmax(0, 1fr); min-height: 100vh; }
.sidebar { display: flex; flex-direction: column; gap: 24px; padding: 22px; background: #111a20; color: #f6fbfb; }
.brand { display: flex; gap: 12px; align-items: center; padding: 8px 2px; }
.brand strong, .brand small { display: block; }
.brand small, .sidebar-card span { color: #aab7bd; font-size: 12px; }
.nav { display: grid; gap: 6px; }
.nav a { padding: 12px 14px; border-radius: 8px; color: #dce6e7; font-weight: 750; }
.nav a:hover, .nav a.active { background: rgba(255,255,255,.1); color: #fff; }
.sidebar-card { margin-top: auto; padding: 14px; border: 1px solid rgba(255,255,255,.12); border-radius: 8px; background: rgba(255,255,255,.06); }
.sidebar-card strong { display: block; margin-top: 4px; }

.main { min-width: 0; padding: 28px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 22px; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0; font-weight: 800; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 32px; }
h2 { margin-bottom: 0; font-size: 20px; }
.muted { color: var(--muted); line-height: 1.55; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: 0 14px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 800; cursor: pointer; }
.button:hover { background: var(--accent-dark); }
.button.ghost { border: 1px solid var(--line); background: #fff; color: var(--text); }
.button.danger { background: var(--danger); }
.button.small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.alert { margin-bottom: 14px; padding: 12px 14px; border: 1px solid #f0c9c6; border-radius: 8px; background: #fff3f2; color: #8f2924; }
.alert.success { border-color: #bfe3d2; background: #eefaf4; color: #126442; }
.alert a { font-weight: 900; text-decoration: underline; }
.reminder-alert { background: #fff8e6; border-color: #efd28c; color: #7a5208; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.metric { padding: 18px; }
.metric span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; font-weight: 900; }
.metric strong { display: block; margin-top: 6px; font-size: 25px; letter-spacing: 0; }
.metric.danger strong, .negative { color: var(--danger); }
.positive { color: var(--ok); }

.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.panel { padding: 18px; margin-bottom: 16px; }
.panel.wide { grid-column: 1 / -1; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.panel-head a, .tabs a { color: var(--accent); font-weight: 800; }
.list { display: grid; gap: 8px; }
.list-row { display: flex; justify-content: space-between; gap: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.list-row strong, .list-row small { display: block; }
.list-row small { margin-top: 3px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.list-row em { color: var(--muted); font-style: normal; white-space: nowrap; }
.compact-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.compact-stats div { padding: 14px; border-radius: 8px; background: var(--surface-soft); border: 1px solid var(--line); }
.compact-stats span { display: block; color: var(--muted); font-size: 12px; }
.compact-stats strong { display: block; margin-top: 4px; font-size: 20px; }

.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.form-grid.compact { grid-template-columns: repeat(6, minmax(0, 1fr)); align-items: end; }
.span-2 { grid-column: span 2; }
.span-4 { grid-column: 1 / -1; }
label { display: grid; gap: 6px; color: #3a4650; font-size: 12px; font-weight: 900; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; background: #fff; color: var(--text); }
textarea { min-height: 76px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.check input { width: auto; }
.form-actions { display: flex; align-items: end; }
.filters { display: grid; grid-template-columns: minmax(0, 1fr) 220px auto; gap: 10px; margin-bottom: 12px; }
.filters.laptop-filters { grid-template-columns: minmax(240px, 1fr) 170px 190px 190px auto auto; }
.tabs { display: flex; flex-wrap: wrap; gap: 10px; }
.tabs a.active { color: var(--text); }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f6f8fa; color: var(--muted); font-size: 12px; text-transform: uppercase; font-weight: 900; }
td small { display: block; margin-top: 4px; color: var(--muted); }
.badge { display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 999px; background: #edf5f3; color: #0e625b; font-size: 12px; font-weight: 900; }
.badge.status-wystawiony { background: #e4f0ff; color: #185ea8; }
.badge.status-dostepny { background: #e3f7ed; color: #146c47; }
.badge.status-rezerwacja { background: #f0e8ff; color: #6d3bbd; }
.badge.status-serwis { background: #fff3cf; color: #8a5b05; }
.badge.status-sprzedany { background: #dff5e8; color: #0f5d3f; }
.badge.status-odeslany { background: #fde7e5; color: #a8322d; }
.grade-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 42px; min-height: 30px; margin-top: 8px; padding: 0 10px; border-radius: 8px; font-size: 14px; font-weight: 950; border: 1px solid var(--line); background: #fff; color: var(--text); }
.grade-A { background: #e3f7ed; color: #126442; border-color: #bbe5cf; }
.grade-Aminus { background: #edf5f3; color: #0f5f58; border-color: #cfe4df; }
.grade-B { background: #fff3cf; color: #8a5b05; border-color: #f1d889; }
.grade-Bminus { background: #fde7e5; color: #a8322d; border-color: #efb4ae; }
.row-actions { display: flex; justify-content: flex-end; gap: 8px; white-space: nowrap; }
.row-actions form { margin: 0; }
.laptop-metrics { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.laptop-table { table-layout: fixed; min-width: 1260px; }
.laptop-table th:nth-child(1), .laptop-table td:nth-child(1) { width: 120px; }
.laptop-table th:nth-child(2), .laptop-table td:nth-child(2) { width: 30%; }
.laptop-table th:nth-child(3), .laptop-table td:nth-child(3) { width: 115px; }
.laptop-table th:nth-child(4), .laptop-table td:nth-child(4) { width: 300px; }
.laptop-table th:nth-child(5), .laptop-table td:nth-child(5) { width: 130px; }
.laptop-table th:nth-child(6), .laptop-table td:nth-child(6) { width: 130px; }
.laptop-table th:nth-child(7), .laptop-table td:nth-child(7) { width: 230px; position: sticky; right: 0; z-index: 2; background: inherit; box-shadow: none; }
.laptop-table th:nth-child(7) { z-index: 3; background: #f6f8fa; }
.laptop-name { display: block; max-width: 680px; font-weight: 750; line-height: 1.35; }
.price-col { min-width: 300px; }
.price-cells { display: grid; grid-template-columns: repeat(3, minmax(85px, 1fr)); gap: 8px; min-width: 280px; }
.price-cells span { display: grid; gap: 2px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.price-cells small { margin: 0; color: var(--muted); font-size: 11px; font-weight: 900; text-transform: uppercase; }
.price-cells strong { font-size: 15px; white-space: nowrap; }
.laptop-actions { align-items: center; flex-wrap: wrap; min-width: 210px; }
.quick-sell { display: inline-grid; grid-template-columns: 62px 78px auto; gap: 6px; align-items: center; }
.quick-sell input { height: 32px; padding: 6px 8px; font-size: 13px; }
.stack-form { display: grid; gap: 12px; max-width: 520px; }
.backup-list { margin-top: 14px; }
.settings-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 12px 0 16px; }
.settings-list { display: grid; gap: 8px; }
.settings-list div { display: flex; justify-content: space-between; gap: 16px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.settings-list span { color: var(--muted); }
.settings-list strong { text-align: right; }
.settings-list .breakable { overflow-wrap: anywhere; word-break: break-word; }
.settings-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.backup-table { display: grid; gap: 8px; margin-top: 16px; }
.backup-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.backup-row strong, .backup-row small { display: block; }
.backup-row small { margin-top: 3px; color: var(--muted); }
.reminder-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.reminder-form { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.reminder-list { display: grid; gap: 10px; }
.reminder-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 14px; border: 1px solid var(--line); border-left: 5px solid #94a3b8; border-radius: 8px; background: #fff; }
.reminder-card.priority-high, .reminder-preview.priority-high { border-left-color: var(--danger); }
.reminder-card.priority-normal, .reminder-preview.priority-normal { border-left-color: var(--accent); }
.reminder-card.priority-low, .reminder-preview.priority-low { border-left-color: #94a3b8; }
.reminder-card.overdue { background: #fff8f7; }
.reminder-title { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 6px; }
.reminder-card p { margin: 0 0 6px; color: var(--muted); line-height: 1.45; }
.reminder-card small { color: var(--muted); }
.reminder-preview { border-left: 5px solid var(--accent); }
.notice-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); color: var(--muted); }
.customer-metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.customer-add-bar { display: flex; justify-content: flex-end; margin: -4px 0 16px; }
.customer-form { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.customer-layout { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 16px; align-items: start; }
.customer-list-panel, .customer-card-panel { margin-bottom: 0; }
.customer-filters { grid-template-columns: 1fr; }
.customer-list { display: grid; gap: 8px; max-height: 780px; overflow: auto; padding-right: 2px; }
.customer-row { display: grid; gap: 6px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.customer-row:hover, .customer-row.active { border-color: #b8d9d5; background: #edf7f5; }
.customer-row strong, .customer-row small { display: block; }
.customer-row small { color: var(--muted); }
.customer-row em { color: var(--accent); font-style: normal; font-size: 12px; font-weight: 900; }
.customer-card-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 14px; }
.customer-card-head h2 { margin-top: 10px; font-size: 26px; }
.customer-card-head p { margin: 4px 0 0; color: var(--muted); }
.customer-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.customer-summary div { padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.customer-summary span { display: block; color: var(--muted); font-size: 12px; font-weight: 900; }
.customer-summary strong { display: block; margin-top: 4px; overflow-wrap: anywhere; }
.customer-notes { padding: 12px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fffdf4; }
.customer-notes p { margin: 0; line-height: 1.55; }
.customer-notes p + p { margin-top: 8px; }
.customer-sections, .customer-history { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.customer-case-form, .customer-file-form { grid-template-columns: repeat(4, minmax(0, 1fr)); }
#customer-case-form { scroll-margin-top: 18px; }
.case-edit-notice { margin-bottom: 12px; background: #edf7f5; color: var(--accent-dark); }
.timeline, .file-list { display: grid; gap: 10px; }
.timeline-item, .file-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.timeline-item strong, .timeline-item small, .file-row strong, .file-row small { display: block; }
.timeline-item small, .file-row small { margin-top: 4px; color: var(--muted); }
.timeline-item p { margin: 8px 0 0; color: #3a4650; line-height: 1.5; }
.wfirma-panel { padding: 0; overflow: hidden; }
.wfirma-panel .panel-head { padding: 18px; margin-bottom: 0; border-bottom: 1px solid var(--line); }
.wfirma-frame { display: block; width: 100%; min-height: calc(100vh - 190px); border: 0; background: #eef1f4; }

@media (max-width: 1500px) {
  .laptop-table { min-width: 1180px; }
  .laptop-table th:nth-child(2), .laptop-table td:nth-child(2) { width: 27%; }
  .laptop-table th:nth-child(4), .laptop-table td:nth-child(4) { width: 280px; }
  .laptop-table th:nth-child(7), .laptop-table td:nth-child(7) { width: 220px; }
  .customer-layout { grid-template-columns: 1fr; }
  .customer-list { max-height: none; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .customer-sections, .customer-history { grid-template-columns: 1fr; }
  .customer-case-form, .customer-file-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .customer-card-panel { overflow: hidden; }
}

@media (max-width: 1280px) {
  .laptop-table { min-width: 1080px; }
  .laptop-table th:nth-child(1), .laptop-table td:nth-child(1) { width: 105px; }
  .laptop-table th:nth-child(2), .laptop-table td:nth-child(2) { width: 25%; }
  .laptop-table th:nth-child(4), .laptop-table td:nth-child(4) { width: 255px; }
  .laptop-table th:nth-child(5), .laptop-table td:nth-child(5) { width: 115px; }
  .laptop-table th:nth-child(6), .laptop-table td:nth-child(6) { width: 110px; }
  .price-cells { grid-template-columns: repeat(3, minmax(76px, 1fr)); min-width: 240px; }
  .price-cells span { padding: 7px; }
  .price-cells strong { font-size: 14px; }
  .customer-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .customer-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1100px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; }
  .nav { display: flex; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .sidebar-card { display: none; }
  .metric-grid, .dashboard-grid, .compact-stats, .laptop-metrics, .reminder-metrics, .reminder-form, .customer-metrics, .customer-summary, .customer-sections, .customer-history { grid-template-columns: 1fr 1fr; }
  .customer-layout { grid-template-columns: 1fr; }
  .form-grid, .form-grid.compact, .filters { grid-template-columns: 1fr; }
  .filters.laptop-filters, .customer-filters { grid-template-columns: 1fr; }
  .backup-row, .reminder-card, .notice-row, .timeline-item, .file-row, .customer-card-head { grid-template-columns: 1fr; align-items: start; }
  .span-2, .span-4 { grid-column: auto; }
}

@media (max-width: 640px) {
  .main { padding: 14px; }
  .topbar { align-items: flex-start; }
  .metric-grid, .dashboard-grid, .compact-stats, .laptop-metrics, .reminder-metrics, .reminder-form, .customer-metrics, .customer-summary, .customer-sections, .customer-history { grid-template-columns: 1fr; }
  .customer-list, .customer-form, .customer-case-form, .customer-file-form { grid-template-columns: 1fr; }
  .panel, .metric { padding: 14px; }
  table { min-width: 760px; }
}
