/* NP CRM Dashboard - Nie Przelewki */
/* Design: jasny z brązowym akcentem */

:root {
  --bg: #f5f5f0;
  --white: #ffffff;
  --brown: #7B3F00;
  --brown-light: #a0622a;
  --brown-bg: #faf6f0;
  --text: #1a1a1a;
  --text-secondary: #666666;
  --text-muted: #999999;
  --border: #e5e5e0;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 8px;
  --sidebar-w: 220px;
  --panel-w: 400px;
  /* statuses */
  --status-nowy: #3b82f6;
  --status-aktywny: #10b981;
  --status-wstrzymany: #f59e0b;
  --status-zakonczone: #6b7280;
  /* followup */
  --fu-wyslany: #10b981;
  --fu-zaplanowany: #f59e0b;
  --fu-blad: #ef4444;
  --fu-anulowany: #d1d5db;
  --fu-oczekuje: #8b5cf6;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ======== AUTH ======== */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.auth-box {
  background: var(--white);
  padding: 40px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 360px;
  width: 100%;
}
.auth-box h1 {
  font-family: Georgia, 'Times New Roman', serif;
  color: var(--brown);
  font-size: 32px;
  margin-bottom: 4px;
}
.auth-box p {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 24px;
}
.auth-box input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.2s;
}
.auth-box input:focus { border-color: var(--brown); }
.auth-box button {
  width: 100%;
  padding: 12px;
  background: var(--brown);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.auth-box button:hover { background: var(--brown-light); }
.auth-error { color: #ef4444; font-size: 13px; margin-top: 12px; }

/* ======== APP LAYOUT ======== */
.app {
  display: flex;
  min-height: 100vh;
}

/* ======== SIDEBAR ======== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
}
.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand h2 {
  font-family: Georgia, 'Times New Roman', serif;
  color: var(--brown);
  font-size: 22px;
  font-weight: 400;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}
.nav-links {
  list-style: none;
  padding: 12px 8px;
  flex: 1;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.15s;
  margin-bottom: 2px;
}
.nav-link:hover { background: var(--brown-bg); color: var(--text); }
.nav-link.active { background: var(--brown); color: white; }
.nav-link.active svg { stroke: white; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}
.btn-sync {
  width: 100%;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-sync:hover { border-color: var(--brown); color: var(--brown); }

/* ======== CONTENT ======== */
.content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 24px 32px;
  max-width: calc(100vw - var(--sidebar-w));
  transition: max-width 0.3s;
}
.page-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 24px;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.total-badge {
  font-family: -apple-system, Helvetica, Arial, sans-serif;
  font-size: 13px;
  background: var(--brown);
  color: white;
  padding: 2px 10px;
  border-radius: 12px;
  font-weight: 600;
}

/* ======== STATS CARDS ======== */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-card.accent {
  background: var(--brown);
  color: white;
}
.stat-card.accent .stat-label { color: rgba(255,255,255,0.7); }
.stat-num {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}
.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-top: 2px;
}

/* ======== GRID ======== */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 14px;
  font-weight: 600;
}

/* ======== BRANZA CHART ======== */
.branza-chart {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.branza-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: var(--brown-bg);
  color: var(--brown);
  cursor: pointer;
  transition: all 0.15s;
}
.branza-item:hover { transform: scale(1.05); }
.branza-count {
  background: var(--brown);
  color: white;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
}

/* ======== MIASTA CHART ======== */
.city-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.city-name {
  width: 100px;
  font-size: 12px;
  text-align: right;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.city-bar {
  flex: 1;
  height: 18px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}
.city-fill {
  height: 100%;
  background: var(--brown);
  border-radius: 3px;
  transition: width 0.5s;
}
.city-num {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 24px;
}

/* ======== ACTIVITY LOG ======== */
.activity-log { max-height: 300px; overflow-y: auto; }
.log-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--bg);
  font-size: 13px;
}
.log-time { color: var(--text-muted); font-size: 11px; font-family: monospace; min-width: 130px; }
.log-action {
  font-weight: 600;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.log-action.mail_wyslany { background: #dcfce7; color: #166534; }
.log-action.mail_blad { background: #fee2e2; color: #991b1b; }
.log-action.nowy_lead { background: #dbeafe; color: #1e40af; }
.log-action.lead_edytowany { background: #fef3c7; color: #92400e; }
.log-action.batch_zatwierdzony { background: #ede9fe; color: #5b21b6; }
.log-details { color: var(--text-secondary); font-size: 12px; }

/* ======== FILTER BAR ======== */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.filter-bar input {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  width: 240px;
  outline: none;
  transition: border-color 0.2s;
}
.filter-bar input:focus { border-color: var(--brown); }
.filter-bar select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: white;
  outline: none;
  cursor: pointer;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}
.checkbox-label input { accent-color: var(--brown); }

/* ======== TABLE ======== */
.table-wrap {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; }
th {
  background: #fafaf8;
  padding: 10px 12px;
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}
td {
  padding: 8px 12px;
  border-bottom: 1px solid #f5f5f2;
  font-size: 13px;
}
tbody tr { cursor: pointer; transition: background 0.1s; }
tbody tr:hover { background: var(--brown-bg); }

.col-id { color: var(--text-muted); font-size: 12px; width: 50px; }
.col-firma { font-weight: 600; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-email { font-family: monospace; font-size: 11px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-email.placeholder { color: #d1d5db; }

/* Status badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 600;
  color: white;
}
.badge-nowy { background: var(--status-nowy); }
.badge-aktywny { background: var(--status-aktywny); }
.badge-wstrzymany { background: var(--status-wstrzymany); }
.badge-zakonczone { background: var(--status-zakonczone); }

/* Tier badge */
.tier-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  color: white;
  background: #6b7280;
}
.tier-0 { background: #dc2626; }
.tier-1a { background: #2563eb; }
.tier-1b { background: #7c3aed; }
.tier-1c { background: #0891b2; }
.tier-1d { background: #059669; }
.tier-1e { background: #d97706; }
.tier-2a { background: #be185d; }
.tier-2b { background: #9333ea; }
.tier-3 { background: #6b7280; }

/* FU dots */
.fu-dots {
  display: flex;
  gap: 4px;
}
.fu-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.fu-dot.wyslany { background: var(--fu-wyslany); }
.fu-dot.zaplanowany { background: var(--fu-zaplanowany); }
.fu-dot.blad { background: var(--fu-blad); }
.fu-dot.anulowany { background: var(--fu-anulowany); }
.fu-dot.oczekuje { background: var(--fu-oczekuje); }
.fu-dot.empty { background: #e5e5e0; }

/* ======== PAGINATION ======== */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  font-size: 13px;
}
.pagination button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.pagination button:hover { border-color: var(--brown); color: var(--brown); }
.pagination button:disabled { opacity: 0.3; cursor: default; }
.pagination .page-info { color: var(--text-muted); }

/* ======== LEAD PANEL ======== */
.lead-panel {
  position: fixed;
  top: 0;
  right: -440px;
  width: var(--panel-w);
  height: 100vh;
  background: var(--white);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 12px rgba(0,0,0,0.08);
  z-index: 20;
  transition: right 0.3s ease;
  overflow-y: auto;
}
.lead-panel.open { right: 0; }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--white);
  z-index: 1;
}
.panel-header h2 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 18px;
  font-weight: 400;
  color: var(--brown);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.panel-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
}
.panel-close:hover { color: var(--text); }

.panel-body { padding: 16px 20px; }
.panel-section {
  margin-bottom: 20px;
}
.panel-section h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.panel-section label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.panel-field {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
  margin-top: 2px;
  margin-bottom: 4px;
  font-family: inherit;
}
.panel-field:focus { border-color: var(--brown); }
textarea.panel-field { resize: vertical; }

.btn-save {
  width: 100%;
  padding: 10px;
  background: var(--brown);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  margin-bottom: 8px;
}
.btn-save:hover { background: var(--brown-light); }
.save-msg {
  font-size: 13px;
  text-align: center;
  margin-bottom: 16px;
  min-height: 20px;
}
.save-msg.success { color: var(--status-aktywny); }
.save-msg.error { color: #ef4444; }

.panel-meta {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ======== PANEL FOLLOWUPS ======== */
.panel-followups {}
.fu-step {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--bg);
}
.fu-step:last-child { border-bottom: none; }
.fu-step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}
.fu-step-info { flex: 1; }
.fu-step-status { font-size: 12px; font-weight: 600; }
.fu-step-date { font-size: 11px; color: var(--text-muted); }
.fu-step-subject { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }

/* ======== RESPONSIVE ======== */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .content { margin-left: 0; padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .lead-panel { width: 100%; right: -100%; }
  .filter-bar input { width: 100%; }
}
