/* Kolor przycisku po najechaniu: uzywany w kilku miejscach, wczesniej nigdzie niezdefiniowany
   (tlo znikalo i bialy napis na bialym tle byl niewidoczny). */
:root {
  --primary-hover: #2D523C;
  --card: #ffffff;
  --radius: 6px;
  --shadow-modal: 0 20px 50px rgba(23, 42, 58, 0.25);
}

/* Admin shell */
.admin-shell { max-width: 1100px; margin: 0 auto; padding: 24px; }

.admin-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.admin-topbar h1 { margin: 0; font-size: 18px; }

/* Nav (Sprawy / Firmy) */
.admin-nav { display: flex; gap: 4px; }
.admin-nav a {
  display: inline-flex; align-items: center;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  color: var(--fg-muted);
  border: 1px solid transparent;
}
.admin-nav a:hover { background: var(--bg-subtle); color: var(--fg); }
.admin-nav a.active { background: var(--bg-subtle); color: var(--fg); border-color: var(--border); }

/* Page header (used on companies.html) */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.page-header h1 { margin: 0; font-size: 22px; }

/* Segmented view switch (Obsługiwane / Zarchiwizowane) */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border, #e4e4e7);
  border-radius: 9px;
  background: var(--bg-subtle, #FBFAF7);
}
.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--fg-muted, #6b7a72);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.seg-btn:hover { color: var(--fg, #1a2a20); }
.seg-btn.active {
  background: var(--brand-green-dark, #38654A);
  color: #fff;
}
.seg-btn:focus-visible { outline: 2px solid var(--brand-green-dark, #38654A); outline-offset: 1px; }

/* Empty state */
.empty-state {
  padding: 32px;
  text-align: center;
  color: var(--fg-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-subtle);
}

/* Login */
.admin-login-card { max-width: 360px; padding: 24px; }
.admin-login-card h1 { margin-top: 0; font-size: 20px; }

/* Filters */
.admin-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.admin-filters select, .admin-filters input {
  width: auto;
  min-width: 160px;
  font-size: 14px;
}

/* Cases table */
.cases-table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.cases-table th, .cases-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: top;
}
.cases-table tr:last-child td { border-bottom: 0; }
.cases-table th {
  font-weight: 600;
  color: var(--fg-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-subtle);
}
.cases-table tbody tr { transition: background 100ms ease; }
.cases-table tbody tr:hover { background: var(--bg-subtle); cursor: pointer; }

/* Row actions inside table — equal icon+label buttons, single row */
.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  white-space: nowrap;
}
.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 104px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border, #e4e4e7);
  border-radius: 7px;
  background: #fff;
  color: var(--fg, #1a2a20);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn-action svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-action:hover { background: var(--bg-subtle, #FBFAF7); border-color: #cdd5d0; text-decoration: none; }
.btn-action:active { transform: translateY(1px); }
.btn-action:focus-visible { outline: 2px solid var(--brand-green-dark, #38654A); outline-offset: 1px; }

.btn-action--primary {
  background: var(--brand-green-dark, #38654A);
  border-color: var(--brand-green-dark, #38654A);
  color: #fff;
}
.btn-action--primary:hover {
  background: #2d5239;
  border-color: #2d5239;
  color: #fff;
}
.btn-action--danger:hover {
  background: #fdf3ef;
  border-color: #e7c3b1;
  color: #8a3a1e;
}

@media (max-width: 720px) {
  .row-actions { flex-wrap: wrap; justify-content: flex-start; }
  .btn-action { min-width: 0; }
}

/* Status badges */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.status-nowe { background: #fef3c7; color: #92400e; }
.status-w_analizie { background: #dbeafe; color: #1e3a8a; }
.status-wymaga_uzupelnienia { background: #fee2e2; color: #991b1b; }
.status-u_eksperta { background: #f3e8ff; color: #6b21a8; }
.status-do_firmy { background: #d1fae5; color: #065f46; }
.status-zamkniete_zasadne { background: #dcfce7; color: #14532d; }
.status-zamkniete_bezzasadne { background: #fce7f3; color: #831843; }

/* Case page sections */
.case-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.case-section h2 { margin-top: 0; font-size: 16px; }
.case-section h3 { margin-top: 0; }

.case-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions-help {
  margin: 0 0 12px;
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1.5;
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 10, 10, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal-card {
  background: var(--card);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-card h2 { margin-top: 0; font-size: 18px; }
.modal-help {
  margin: 0 0 16px;
  color: var(--fg-muted);
  font-size: 14px;
  line-height: 1.5;
}
.optional-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--bg-subtle);
}
.optional-box summary {
  cursor: pointer;
  color: var(--fg);
  font-size: 14px;
  font-weight: 500;
}

/* Timeline */
.timeline-event {
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
  color: var(--fg);
}
.timeline-event:last-child { border-bottom: 0; }
.timeline-event .muted-small { margin-top: 2px; }

/* AI analysis section */
.ai-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.badge-analysis {
  background: #ede9fe;
  color: #5b21b6;
  font-weight: 500;
  text-transform: capitalize;
  border-color: transparent;
}
.ai-content {
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin: 12px 0;
}
.ai-analysis { border-left: 3px solid #8b5cf6; }
.markdown-content {
  color: var(--fg);
  font-size: 14px;
  line-height: 1.65;
}
.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
  margin: 0 0 12px;
  line-height: 1.3;
}
.markdown-content h1 { font-size: 24px; }
.markdown-content h2 {
  font-size: 18px;
  margin-top: 24px;
}
.markdown-content h3 {
  font-size: 15px;
  margin-top: 18px;
}
.markdown-content p,
.markdown-content ul {
  margin: 0 0 12px;
}
.markdown-content ul {
  padding-left: 20px;
}
.markdown-content li {
  margin-bottom: 6px;
}
.markdown-content hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}
.markdown-content strong {
  font-weight: 700;
}
.markdown-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95em;
  background: #f3f4f6;
  padding: 1px 6px;
  border-radius: 6px;
}
.markdown-content-nested {
  margin-top: 12px;
  padding-top: 8px;
}

/* Simplified case view */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.case-description {
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  background: #fafafa;
  border-left: 3px solid var(--border);
  padding: 12px 16px;
  border-radius: 6px;
}
.legacy-fields { margin-top: 16px; }
.legacy-fields summary { cursor: pointer; color: var(--fg-muted); font-size: 14px; }

/* Rich timeline (Task 4.3) */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-left: 2px solid #e4e4e7;
  padding-left: 16px;
  margin-top: 12px;
}
.timeline-event-rich {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
  background: #fafafa;
  border-radius: 6px;
  position: relative;
}
.timeline-event-rich::before {
  content: '';
  position: absolute;
  left: -22px;
  top: 14px;
  width: 8px;
  height: 8px;
  background: #18181b;
  border-radius: 50%;
}
.event-header {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
  color: #71717a;
}
.event-date { font-weight: 500; color: #52525b; }
.event-actor { padding: 1px 6px; background: #e4e4e7; border-radius: 4px; }
.event-status .badge { font-size: 11px; padding: 1px 6px; }
.event-body { font-size: 14px; color: #18181b; }
.event-reason {
  margin-top: 4px;
  padding: 4px 8px;
  background: white;
  border-left: 2px solid #71717a;
  font-size: 13px;
  color: #52525b;
  font-style: italic;
}

.case-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.case-section-header h2 {
  margin: 0;
}
.status-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.status-select {
  padding: 8px 10px;
  border: 1px solid #e4e4e7;
  border-radius: 6px;
  background: white;
  font-size: 14px;
  flex: 0 1 240px;
  min-width: 180px;
  text-transform: capitalize;
}
.status-select:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Zalaczniki — grid w widoku sprawy */
.attachments-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.attachment-tile {
  border: 1px solid #e4e4e7;
  border-radius: 8px;
  overflow: hidden;
  background: white;
  display: flex;
  flex-direction: column;
}
.attachment-tile img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
}
.attachment-pdf {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 140px;
  background: #fafafa;
  text-decoration: none;
  color: #18181b;
  gap: 4px;
}
.pdf-icon { font-size: 32px; }
.pdf-name { font-size: 12px; font-weight: 600; color: #71717a; }
.attachment-info {
  padding: 8px 12px;
  border-top: 1px solid #e4e4e7;
  font-size: 12px;
}
.attachment-link {
  color: #18181b;
  text-decoration: none;
  font-weight: 500;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attachment-link:hover { text-decoration: underline; }

/* === Multi-user auth pages (login, forgot, reset, change, users, account) === */

/* Login / forgot / reset / change-password — centered card */
.admin-login {
  min-height: 100vh;
  background: var(--bg, #f8f9fb);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-shell {
  width: 100%;
  max-width: 400px;
  padding: 32px;
  background: var(--card, #fff);
  border: 1px solid var(--border, #e3e6ea);
  border-radius: var(--radius-lg, 12px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.login-shell h1 { margin: 0 0 8px; font-size: 22px; color: var(--fg, #172A3A); }
.login-shell > p { margin: 0 0 20px; color: var(--fg-muted, #4A5859); font-size: 14px; }
.login-shell form > * + * { margin-top: 14px; }
.login-shell label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg, #172A3A);
}
.login-shell label input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border, #e3e6ea);
  border-radius: var(--radius, 6px);
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
}
.login-shell label input:focus {
  outline: none;
  border-color: var(--brand-green-dark);
  box-shadow: 0 0 0 3px rgba(80, 137, 145, 0.15);
}
.login-shell button[type="submit"] {
  width: 100%;
  padding: 10px 16px;
  background: var(--brand-green-dark);
  color: #fff;
  border: 0;
  border-radius: var(--radius, 6px);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.login-shell button[type="submit"]:hover { background: var(--primary-hover); }
.login-shell .error {
  margin-top: 12px;
  padding: 8px 12px;
  background: #fef2f2;
  border-left: 3px solid #c53030;
  color: #991b1b;
  font-size: 13px;
  border-radius: var(--radius, 6px);
}
.login-shell .muted {
  margin: 20px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--fg-muted, #4A5859);
}
.login-shell .muted a { color: var(--brand-green-dark); text-decoration: none; }
.login-shell .muted a:hover { text-decoration: underline; }

/* Admin panel pages (users, account) — topbar + content */
.admin-panel { background: var(--bg, #f8f9fb); min-height: 100vh; }
.admin-panel .topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--card, #fff);
  border-bottom: 1px solid var(--border, #e3e6ea);
}
.admin-panel .topbar .brand {
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
  color: var(--fg, #172A3A);
}
.admin-panel .topbar nav {
  display: flex;
  gap: 20px;
  align-items: center;
}
.admin-panel .topbar nav a {
  text-decoration: none;
  color: var(--fg-muted, #4A5859);
  font-size: 14px;
}
.admin-panel .topbar nav a:hover { color: var(--fg, #172A3A); }
.admin-panel .topbar nav button {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border, #e3e6ea);
  border-radius: var(--radius, 6px);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}
.admin-panel .topbar nav button:hover { background: var(--bg-subtle, #f4f5f7); }
.admin-panel .content { max-width: 1100px; margin: 0 auto; padding: 24px; }
.admin-panel .content h1 { margin: 0 0 8px; font-size: 24px; }
.admin-panel .content h2 { margin: 28px 0 12px; font-size: 16px; }
.admin-panel .content section + section { margin-top: 28px; }

/* Users table */
#users-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card, #fff);
  border: 1px solid var(--border, #e3e6ea);
  border-radius: var(--radius-lg, 12px);
  margin-top: 16px;
  overflow: hidden;
}
#users-table th, #users-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border, #e3e6ea);
  font-size: 14px;
}
#users-table tr:last-child td { border-bottom: 0; }
#users-table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted, #4A5859);
  background: var(--bg-subtle, #f4f5f7);
  font-weight: 600;
}
#users-table tr.disabled { opacity: 0.55; }
#users-table td button {
  padding: 4px 10px;
  margin-right: 4px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--border, #e3e6ea);
  background: var(--card, #fff);
  border-radius: var(--radius, 6px);
  font-family: inherit;
}
#users-table td button:hover { background: var(--bg-subtle, #f4f5f7); }

#add-btn {
  padding: 8px 14px;
  background: var(--brand-green-dark);
  color: #fff;
  border: 0;
  border-radius: var(--radius, 6px);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  margin-top: 8px;
}
#add-btn:hover { background: var(--primary-hover); }

/* Add user dialog */
#add-dialog {
  max-width: 440px;
  width: calc(100% - 32px);
  padding: 28px;
  border: 1px solid var(--border, #e3e6ea);
  border-radius: var(--radius-lg, 12px);
  background: var(--card, #fff);
}
#add-dialog::backdrop { background: rgba(23, 42, 58, 0.4); }
#add-dialog h3 { margin: 0 0 16px; font-size: 18px; }
#add-dialog label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 500;
}
#add-dialog label input,
#add-dialog label select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 12px;
  border: 1px solid var(--border, #e3e6ea);
  border-radius: var(--radius, 6px);
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
}
#add-dialog label input[type="checkbox"] {
  display: inline;
  width: auto;
  margin: 0 6px 0 0;
}
#add-dialog menu {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 0;
  margin: 16px 0 0;
}
#add-dialog menu button {
  padding: 8px 16px;
  border-radius: var(--radius, 6px);
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
}
#add-dialog menu button[type="submit"] {
  background: var(--brand-green-dark);
  color: #fff;
  border: 0;
}
#add-dialog menu button[type="submit"]:hover { background: var(--primary-hover); }
#add-dialog menu button[type="button"] {
  background: var(--card, #fff);
  color: var(--fg, #172A3A);   /* bez tego dziedziczy bialy napis po .admin-panel form button */
  border: 1px solid var(--border, #e3e6ea);
}
#add-dialog menu button[type="button"]:hover { background: var(--bg-subtle, #f4f5f7); }

/* Account page forms */
.admin-panel form button {
  padding: 8px 14px;
  background: var(--brand-green-dark);
  color: #fff;
  border: 0;
  border-radius: var(--radius, 6px);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  margin-top: 8px;
}
.admin-panel form button:hover { background: var(--primary-hover); }
.admin-panel form label {
  display: block;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 500;
}
.admin-panel form label input {
  display: block;
  width: 100%;
  max-width: 360px;
  margin-top: 4px;
  padding: 8px 12px;
  border: 1px solid var(--border, #e3e6ea);
  border-radius: var(--radius, 6px);
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
}
.admin-panel form .error {
  margin-top: 10px;
  padding: 8px 12px;
  background: #fef2f2;
  border-left: 3px solid #c53030;
  color: #991b1b;
  font-size: 13px;
  border-radius: var(--radius, 6px);
  max-width: 360px;
}

/* === Company detail page === */
.details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px 24px;
  font-size: 14px;
}
.details-grid > div { padding: 4px 0; }
.details-grid code { background: var(--bg-subtle, #f4f5f7); padding: 2px 6px; border-radius: 4px; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--card, #fff);
  border: 1px solid var(--border, #e3e6ea);
  border-radius: var(--radius-lg, 12px);
  padding: 16px 18px;
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--fg, #172A3A);
  line-height: 1;
}
.stat-label {
  margin-top: 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-muted, #4A5859);
}

/* === Tabs for cases (Nowe / W toku / Zamkniete) === */
.cases-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border, #e3e6ea);
  margin-bottom: 16px;
}
.cases-tabs .tab {
  padding: 10px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-muted, #4A5859);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}
.cases-tabs .tab:hover {
  color: var(--fg, #172A3A);
}
.cases-tabs .tab.active {
  color: var(--fg, #172A3A);
  border-bottom-color: var(--accent, #1a1a1a);
  font-weight: 600;
}
.cases-tabs .tab-count {
  font-size: 12px;
  color: var(--fg-muted, #4A5859);
  margin-left: 4px;
}
.cases-tabs .tab.active .tab-count {
  color: var(--accent, #1a1a1a);
}

/* Uzytkownicy i Konto: ten sam naglowek co Sprawy i Firmy */
.admin-panel .admin-shell--naglowek { padding-bottom: 0; }
.admin-panel .admin-shell--naglowek .admin-topbar { margin-bottom: 0; }
