/* ============================================================
   FlotAI — arkusz głównych stylów
   Aesthetic: refined editorial, granat + niebiesko-cyjanowy akcent (z logo FLOTA AI)
   ============================================================ */

:root {
  --c-bg:        #f5f7fa;
  --c-bg-card:   #ffffff;
  --c-ink:       #062951;
  --c-ink-soft:  #3a4a68;
  --c-mute:      #8590a6;
  --c-line:      #dce3ec;
  --c-line-soft: #eef2f7;
  --c-accent:    #1192d8;
  --c-accent-d:  #0d6fa6;
  --c-teal:      #13bdb4;
  --c-teal-d:    #0f8a82;
  --c-ok:        #2d7a55;
  --c-warn:      #c98a1f;
  --c-err:       #c14040;
  --c-tag-bg:    #e7eef6;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 18px;

  --shadow-sm: 0 1px 2px rgba(14,30,58,.06);
  --shadow-md: 0 4px 16px rgba(14,30,58,.08);

  --f-sans:  'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  --f-mono:  'JetBrains Mono', 'Courier New', monospace;
  --f-serif: 'Fraunces', Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: var(--f-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--c-accent-d); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Layout ===== */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #ffffff;
  color: var(--c-ink-soft);
  padding: 22px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--c-line);
}

.brand {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 4px 4px 18px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--c-line-soft);
}

.brand-logo {
  max-width: 100%;
  width: auto;
  height: auto;
  max-height: 130px;
  object-fit: contain;
  display: block;
}

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  padding: 10px 12px;
  border-radius: var(--r-sm);
  color: var(--c-ink-soft);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
  border: none;
  background: transparent;
  text-align: left;
  width: 100%;
}

.nav-item:hover { background: var(--c-line-soft); color: var(--c-ink); }

.nav-item.active {
  background: var(--c-ink);
  color: #fff;
}

.main {
  padding: 36px 48px 80px;
  max-width: 1400px;
  width: 100%;
}

/* ===== Headings ===== */
h1, h2, h3 { font-family: var(--f-serif); font-weight: 600; letter-spacing: -0.015em; }
h1 { font-size: 34px; margin: 0 0 4px; }
h2 { font-size: 22px; margin: 0 0 14px; }
h3 { font-size: 17px; margin: 0 0 10px; }

.page-sub {
  color: var(--c-ink-soft);
  font-size: 14px;
  margin-bottom: 32px;
}

/* ===== Cards ===== */
.card {
  background: var(--c-bg-card);
  border: 1px solid var(--c-line);
  border-radius: var(--r-lg);
  padding: 26px;
  box-shadow: var(--shadow-sm);
}

.card + .card { margin-top: 20px; }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.card-head h2 { margin: 0; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-family: var(--f-sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
}

.btn-primary {
  background: var(--c-ink);
  color: #fff;
}
.btn-primary:hover { background: #1a2c4f; }

.btn-accent {
  background: var(--c-accent);
  color: #fff;
}
.btn-accent:hover { background: var(--c-accent-d); }

.btn-ghost {
  background: transparent;
  color: var(--c-ink);
  border-color: var(--c-line);
}
.btn-ghost:hover { background: var(--c-line-soft); }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== Forms ===== */
.field { margin-bottom: 14px; }

.label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--c-ink-soft);
  margin-bottom: 6px;
}

.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--c-line);
  border-radius: var(--r-sm);
  font-family: var(--f-sans);
  font-size: 14px;
  background: #fff;
  color: var(--c-ink);
  transition: border-color .15s;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--c-accent);
}

.textarea { resize: vertical; min-height: 60px; }

details > summary {
  list-style: none;
  padding: 8px 0;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: '▸ ';
  color: var(--c-accent);
  font-size: 14px;
}
details[open] > summary::before { content: '▾ '; }

/* Input number: bez strzałek (mniej wizualnego szumu w tabelach) */
input[type=number].input::-webkit-outer-spin-button,
input[type=number].input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type=number].input { -moz-appearance: textfield; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ===== Drop zone ===== */
.dropzone {
  border: 2px dashed var(--c-line);
  border-radius: var(--r-md);
  padding: 38px 24px;
  text-align: center;
  background: var(--c-line-soft);
  cursor: pointer;
  transition: all .15s;
}

.dropzone:hover, .dropzone.drag {
  border-color: var(--c-accent);
  background: #fff;
}

.dropzone-icon {
  font-family: var(--f-serif);
  font-size: 44px;
  color: var(--c-accent);
  margin-bottom: 4px;
}

.dropzone-title { font-weight: 600; margin-bottom: 4px; }
.dropzone-hint { color: var(--c-mute); font-size: 13px; }

input[type="file"] { display: none; }

/* ===== Doc type toggle ===== */
.toggle {
  display: inline-flex;
  background: var(--c-line-soft);
  border-radius: var(--r-sm);
  padding: 3px;
  gap: 2px;
}

.toggle-btn {
  padding: 7px 14px;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--f-sans);
  color: var(--c-ink-soft);
  cursor: pointer;
  border-radius: 5px;
  transition: all .15s;
}

.toggle-btn.active {
  background: #fff;
  color: var(--c-ink);
  box-shadow: var(--shadow-sm);
}

/* ===== Table ===== */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--r-md);
  border: 1px solid var(--c-line);
  background: #fff;
}

table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.tbl th {
  background: #fafaf6;
  text-align: left;
  padding: 12px 14px;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-ink-soft);
  border-bottom: 1px solid var(--c-line);
  white-space: nowrap;
}

.tbl td {
  padding: 14px;
  border-bottom: 1px solid var(--c-line-soft);
  vertical-align: middle;
}

.tbl tr:last-child td { border-bottom: none; }

.tbl tbody tr:hover { background: #fcfaf3; }

.tbl .mono {
  font-family: var(--f-mono);
  font-size: 12.5px;
  letter-spacing: -0.02em;
}

.tbl .reg {
  font-family: var(--f-mono);
  font-weight: 700;
  background: var(--c-tag-bg);
  padding: 3px 8px;
  border-radius: 4px;
  display: inline-block;
  letter-spacing: 0.05em;
}

/* ===== Tags / chips ===== */
.tag {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--c-line-soft);
  color: var(--c-ink-soft);
}

.tag-ok { background: #e0f0e8; color: var(--c-ok); }
.tag-warn { background: #f7eed1; color: var(--c-warn); }
.tag-err { background: #f7dcdc; color: var(--c-err); }

/* ===== Status / alerts ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--r-sm);
  margin-bottom: 16px;
  font-size: 14px;
  border-left: 3px solid;
}

.alert-ok   { background: #ebf5ef; color: var(--c-ok);   border-color: var(--c-ok); }
.alert-err  { background: #fbecec; color: var(--c-err);  border-color: var(--c-err); }
.alert-info { background: #ecf0f8; color: var(--c-ink);  border-color: var(--c-ink); }

/* ===== Spinner ===== */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
.spinner-dark {
  border-color: rgba(14,30,58,.2);
  border-top-color: var(--c-ink);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Stats ===== */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat {
  background: var(--c-bg-card);
  border: 1px solid var(--c-line);
  border-radius: var(--r-md);
  padding: 18px;
}

.stat-label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--c-mute);
  margin-bottom: 6px;
}

.stat-value {
  font-family: var(--f-serif);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.stat-value .unit {
  font-size: 13px;
  color: var(--c-mute);
  margin-left: 4px;
  font-family: var(--f-sans);
  font-weight: 500;
}

/* ===== JSON preview ===== */
.json-preview {
  background: #1a2c4f;
  color: #d6dbe8;
  padding: 16px;
  border-radius: var(--r-sm);
  font-family: var(--f-mono);
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
}

/* ===== Helpers ===== */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-gap-8 { display: flex; gap: 8px; }
.flex-gap-12 { display: flex; gap: 12px; }
.mt-12 { margin-top: 12px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.muted { color: var(--c-mute); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ===== Client list — clickable rows ===== */
.tbl tbody tr.clickable {
  cursor: pointer;
}
.tbl tbody tr.clickable:hover {
  background: #fcfaf3;
}
.tbl tbody tr.clickable td:first-child {
  font-weight: 600;
}

/* ===== Back link ===== */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--c-ink-soft);
  margin-bottom: 18px;
  text-decoration: none;
  font-weight: 500;
}
.back-link:hover {
  color: var(--c-accent);
  text-decoration: none;
}

/* ===== Client header (panel klienta) ===== */
.client-header {
  background: linear-gradient(135deg, #ffffff 0%, #fcfaf3 100%);
}

.client-header h1 {
  font-size: 28px;
  margin: 0 0 4px;
}

.client-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px 24px;
  margin: 16px 0;
}

.client-meta-item {
  font-size: 13px;
}

.client-meta-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-mute);
  margin-bottom: 2px;
}

.client-meta-value {
  color: var(--c-ink);
  word-break: break-word;
}

.client-meta-value.mono { font-family: var(--f-mono); font-size: 13px; }

.client-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--c-line-soft);
}

.client-stats-inline {
  display: flex;
  gap: 14px;
  font-size: 13px;
  color: var(--c-ink-soft);
  margin-top: 6px;
}

.client-stats-inline strong { color: var(--c-ink); }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--c-line);
}

.tab {
  background: transparent;
  border: none;
  padding: 12px 20px;
  font-family: var(--f-sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--c-ink-soft);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all .15s;
}

.tab:hover {
  color: var(--c-ink);
}

.tab.active {
  color: var(--c-accent-d);
  border-bottom-color: var(--c-accent);
}

.tab-count {
  display: inline-block;
  background: var(--c-line-soft);
  color: var(--c-ink-soft);
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  margin-left: 4px;
}

.tab.active .tab-count {
  background: var(--c-accent);
  color: #fff;
}

/* ===== Empty states ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--c-ink-soft);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: .6;
}

.empty-state h3 {
  margin: 8px 0;
  font-size: 18px;
  color: var(--c-ink);
}

.empty-state p {
  margin: 4px 0;
  font-size: 14px;
}

.empty-state ul {
  font-size: 13.5px;
  margin: 0;
}

.empty-state ul li {
  margin: 4px 0;
}

/* ===== Inline edit (klient) ===== */
.edit-mode .client-meta-value-text { display: none; }
.edit-mode .client-meta-value-input { display: block; }
.client-meta-value-input { display: none; width: 100%; padding: 4px 8px; }

/* ===== Insurers grid (szkodowość) ===== */
.insurers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.insurer-btn {
  background: var(--c-bg-card);
  border: 1px solid var(--c-line);
  border-radius: var(--r-sm);
  padding: 14px 12px;
  font-family: var(--f-sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--c-ink);
  cursor: pointer;
  transition: all .15s;
  text-align: center;
}

.insurer-btn:hover {
  border-color: var(--c-accent);
  background: #fff;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* ===== Mail preview ===== */
.mail-field {
  margin-bottom: 12px;
}

.mail-content {
  background: var(--c-line-soft);
  border: 1px solid var(--c-line);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  font-size: 13.5px;
  white-space: pre-wrap;
  color: var(--c-ink);
}

.mail-body {
  font-family: var(--f-sans);
  line-height: 1.6;
  max-height: 420px;
  overflow-y: auto;
  margin: 0;
}

/* ===== Claims summary table ===== */
.claims-summary {
  font-size: 13px;
}

.claims-summary th,
.claims-summary td {
  text-align: center;
  padding: 10px 12px;
  vertical-align: middle;
}

.claims-summary th:first-child,
.claims-summary td:first-child {
  text-align: left;
  padding-left: 14px;
}

.claims-summary .total-col {
  background: #fcfaf3;
  border-left: 2px solid var(--c-line);
  font-weight: 600;
}

.claims-summary .cell-count {
  font-family: var(--f-mono);
  font-size: 13.5px;
  color: var(--c-ink);
  margin-bottom: 2px;
}

.claims-summary .cell-amount {
  font-family: var(--f-mono);
  font-size: 12px;
  color: var(--c-ink-soft);
}

.claims-summary .row-total {
  background: #f8f3e8;
  border-top: 2px solid var(--c-line);
}

.claims-summary .row-total td {
  font-size: 13.5px;
}

/* ===== Komórka SU z podpowiedzią AI ===== */
.su-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.su-suggest {
  background: transparent;
  border: 1px dashed var(--c-teal);
  border-radius: var(--r-sm);
  padding: 2px 8px;
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--c-teal-d);
  cursor: pointer;
  transition: all .12s;
  white-space: nowrap;
}

.su-suggest:hover {
  background: var(--c-teal);
  color: #fff;
  border-style: solid;
}

.period-cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.period-input {
  font-size: 11.5px;
  padding: 4px 6px;
  width: 132px;
}

.actions-cell {
  white-space: nowrap;
}

.actions-cell .btn-sm {
  padding: 4px 8px;
  min-width: 0;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 22, 45, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn .15s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--c-bg-card);
  border-radius: var(--r-md);
  box-shadow: 0 24px 60px rgba(0,0,0,0.3);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--c-line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-head h2 {
  margin: 0;
  font-size: 17px;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 26px;
  line-height: 1;
  color: var(--c-ink-soft);
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover {
  color: var(--c-ink);
}

.modal-body {
  padding: 18px 22px;
  overflow-y: auto;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 18px; }
  .brand-logo { max-height: 90px; }
  .main { padding: 24px 18px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
}
