/* ============================================================
   Panel CSS — B2B CRM Frontend
   ============================================================ */

:root {
  /* Tokeny z frontend/style.css */
  --ink: #0A0A0A;
  --paper: #FAF9F6;
  --champagne: #C1A68D;
  --champagne-deep: #A8896B;
  --champagne-soft: #ECE3D7;
  --champagne-glow: rgba(193, 166, 141, 0.4);

  --smoke: #8C8479;
  --mist: #E7E1D8;
  --cloud: #F1EDE6;
  --pearl: #FFFFFF;

  --love: #2F7A55;
  --love-bg: #E9F2EC;
  --nope: #C0473F;
  --nope-bg: #F7ECEA;

  --font-display: "Playfair Display", Georgia, serif;
  --font-ui: "Inter", "Segoe UI", system-ui, sans-serif;

  --shadow-card: 0 2px 8px rgba(10, 10, 10, 0.04), 0 8px 24px rgba(10, 10, 10, 0.06);
  --shadow-float: 0 8px 24px -6px rgba(10, 10, 10, 0.2);

  --ease-lux: cubic-bezier(0.22, 1, 0.36, 1);
  --radius-bubble: 18px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

.panel-body {
  font-family: var(--font-ui);
  background-color: var(--paper);
  color: var(--ink);
  line-height: 1.5;
}

/* ============================================================
   Login Screen
   ============================================================ */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--paper) 0%, var(--cloud) 100%);
}

.login-card {
  background: var(--pearl);
  border-radius: var(--radius-bubble);
  padding: 4rem 2rem;
  max-width: 400px;
  box-shadow: var(--shadow-float);
}

.login-card h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--champagne);
  margin: 0 0 0.5rem 0;
}

.login-card p {
  color: var(--smoke);
  margin: 0 0 2rem 0;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2rem;
}

.login-label {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--smoke);
  margin: 0 0 -0.5rem 0;
}

.login-fixed {
  font-family: var(--font-ui);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: var(--cloud);
  color: var(--ink);
}

.login-input,
.login-button {
  font-family: var(--font-ui);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--mist);
}

.login-input {
  background: var(--paper);
  color: var(--ink);
}

.login-input::placeholder {
  color: var(--smoke);
}

.login-button {
  background: var(--champagne);
  color: var(--pearl);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
}

.login-button:hover {
  background: var(--champagne-deep);
}

.error-message {
  background: var(--nope-bg);
  color: var(--nope);
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.login-help {
  font-size: 0.85rem;
  color: var(--smoke);
  background: var(--cloud);
  padding: 1rem;
  border-radius: 8px;
}

.login-help code {
  background: var(--paper);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-family: monospace;
}

/* ============================================================
   Panel Container
   ============================================================ */

.panel-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--mist);
  background: var(--pearl);
  box-shadow: var(--shadow-card);
  flex-shrink: 0;
}

.header-left .header-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
  color: var(--champagne);
}

.header-center .tab-nav {
  display: flex;
  gap: 0.5rem;
}

.tab-button {
  font-family: var(--font-ui);
  padding: 0.5rem 1.5rem;
  border: none;
  background: transparent;
  color: var(--smoke);
  cursor: pointer;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab-button.active {
  color: var(--champagne);
  border-bottom-color: var(--champagne);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.demo-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.logout-button {
  font-family: var(--font-ui);
  padding: 0.5rem 1rem;
  border: 1px solid var(--mist);
  background: var(--paper);
  color: var(--ink);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

/* ============================================================
   CRM View (Sidebar + Content)
   ============================================================ */

.view-crm,
.view-analytics {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.crm-sidebar {
  width: 220px;
  background: var(--cloud);
  border-right: 1px solid var(--mist);
  padding: 2rem 0;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-nav {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-item {
  display: block;
  padding: 0.75rem 1.5rem;
  color: var(--smoke);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all 0.2s;
}

.nav-item:hover {
  color: var(--ink);
  background: var(--mist);
}

.nav-item.active {
  color: var(--champagne);
  background: rgba(193, 166, 141, 0.1);
  border-left-color: var(--champagne);
}

.nav-item.disabled {
  color: var(--smoke);
  opacity: 0.5;
  cursor: not-allowed;
}

.crm-content {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
}

.view-analytics {
  /* .view-crm i .view-analytics dzielą display:flex (wiersz) wyżej — tam poprawne
     (sidebar+content obok siebie), tu nadpisane na kolumnę: h2 → filtr → embed host.
     min-height:0 wymagane żeby flex-item respektował wysokość rodzica zamiast rosnąć
     do wysokości treści (klasyczna pułapka flexbox — bez tego overflow-y:auto nic nie robi). */
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: 2rem;
}

.content-section {
  background: var(--pearl);
  border-radius: var(--radius-bubble);
  padding: 2rem;
  box-shadow: var(--shadow-card);
}

.content-section h2 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  margin: 0 0 2rem 0;
  color: var(--ink);
}

.content-section h3 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  margin: 1.5rem 0 1rem 0;
  color: var(--champagne);
}

/* ============================================================
   KPI Grid
   ============================================================ */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1.5rem;
  margin-bottom: 3rem;
}

.kpi-card {
  background: linear-gradient(135deg, var(--paper) 0%, var(--champagne-soft) 100%);
  border-radius: var(--radius-bubble);
  padding: 1.5rem;
  text-align: center;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--champagne-glow);
}

.kpi-label {
  font-size: 0.85rem;
  color: var(--smoke);
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.kpi-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--champagne-deep);
}

/* ============================================================
   Access Requests Box
   ============================================================ */

.access-requests-box,
.export-box {
  background: var(--cloud);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.access-requests-box h3 {
  margin-top: 0;
}

.request-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.request-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--pearl);
  padding: 1rem;
  border-radius: 8px;
  border-left: 3px solid var(--champagne);
}

.request-email {
  font-weight: 600;
  color: var(--ink);
}

.request-date {
  font-size: 0.85rem;
  color: var(--smoke);
}

.btn-small {
  font-family: var(--font-ui);
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-approve {
  background: var(--love);
  color: var(--pearl);
}

.btn-approve:hover {
  opacity: 0.85;
}

.btn-reject {
  background: var(--nope);
  color: var(--pearl);
}

.btn-reject:hover {
  opacity: 0.85;
}

/* ============================================================
   Filters & Table
   ============================================================ */

.filters-panel {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

.filter-input,
.filter-select {
  font-family: var(--font-ui);
  padding: 0.75rem;
  border: 1px solid var(--mist);
  border-radius: 8px;
  background: var(--pearl);
  color: var(--ink);
}

.filter-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-weight: 500;
}

.btn-primary {
  font-family: var(--font-ui);
  padding: 0.75rem 1.5rem;
  background: var(--champagne);
  color: var(--pearl);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--champagne-deep);
}

.leads-table-wrapper {
  overflow-x: auto;
  margin-bottom: 2rem;
}

.leads-table {
  width: 100%;
  border-collapse: collapse;
}

.leads-table thead {
  background: var(--cloud);
  border-bottom: 2px solid var(--champagne);
}

.leads-table th {
  padding: 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--ink);
}

.leads-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--mist);
}

.lead-row.clickable {
  cursor: pointer;
  transition: background 0.2s;
}

.lead-row:hover {
  background: var(--champagne-soft);
}

.empty-state,
.loading-state {
  text-align: center;
  padding: 2rem;
  color: var(--smoke);
  font-style: italic;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  padding: 1.5rem;
  background: var(--cloud);
  border-radius: 12px;
}

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

/* ============================================================
   Analytics View
   ============================================================ */

.analytics-content {
  background: var(--pearl);
  border-radius: var(--radius-bubble);
  padding: 2rem;
  box-shadow: var(--shadow-card);
}

.analytics-embed-host {
  /* Bez overflow:hidden — to przycinało prawdziwą treść (Shadow DOM), nie tylko rogi
     jak przy dawnym <iframe>. Fragment ma własne zaokrąglone karty w swoim CSS. */
  display: block;
  margin-top: 1.5rem;
}

/* ============================================================
   Modal (Lead Detail)
   ============================================================ */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 10, 10, 0.4);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  z-index: 1000;
}

.modal-content {
  background: var(--pearl);
  width: 40%;
  max-width: 600px;
  height: 100%;
  overflow-y: auto;
  padding: 2rem;
  position: relative;
  box-shadow: -8px 0 24px rgba(10, 10, 10, 0.2);
  animation: slideIn 0.3s var(--ease-lux);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--smoke);
}

.detail-sections {
  margin-top: 2rem;
}

.detail-section {
  margin-bottom: 2rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--mist);
}

.detail-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.detail-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.detail-row .label {
  font-weight: 600;
  color: var(--champagne);
}

.wishlist-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.wishlist-table th {
  padding: 0.75rem;
  text-align: left;
  background: var(--cloud);
  font-weight: 600;
  border-bottom: 1px solid var(--mist);
}

.wishlist-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--mist);
}

/* ============================================================
   Campaign Studio (Etap 2)
   ============================================================ */

.btn-primary:disabled,
.btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--mist);
}

.btn-danger {
  font-family: var(--font-ui);
  padding: 0.75rem 1.5rem;
  background: var(--nope);
  color: var(--pearl);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: opacity 0.2s;
}

.btn-danger:hover {
  opacity: 0.85;
}

.btn-ghost {
  font-family: var(--font-ui);
  padding: 0.75rem 1.5rem;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--mist);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-ghost:hover {
  border-color: var(--champagne);
  color: var(--champagne-deep);
}

.panel-card {
  background: var(--cloud);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.segment-builder {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.segment-preview-count {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.segment-preview-count .count {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--champagne-deep);
}

.segment-preview-sample {
  font-size: 0.85rem;
  color: var(--smoke);
  word-break: break-word;
}

.campaign-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
}

.campaign-form input,
.campaign-form textarea {
  font-family: var(--font-ui);
  padding: 0.75rem;
  border: 1px solid var(--mist);
  border-radius: 8px;
  background: var(--pearl);
  color: var(--ink);
  width: 100%;
  box-sizing: border-box;
}

.campaign-form textarea {
  min-height: 140px;
  resize: vertical;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
}

.campaign-form-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.token-hint {
  font-size: 0.8rem;
  color: var(--smoke);
  margin: -0.5rem 0 0 0;
}

.token-hint code {
  background: var(--champagne-soft);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.status-badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.status-badge--draft { background: var(--mist); color: var(--ink); }
.status-badge--dry_run { background: var(--champagne-soft); color: var(--champagne-deep); }
.status-badge--sending { background: var(--champagne-glow); color: var(--champagne-deep); }
.status-badge--sent { background: var(--love); color: var(--pearl); }
.status-badge--partial { background: #E0A85C; color: var(--pearl); }
.status-badge--failed,
.status-badge--error { background: var(--nope); color: var(--pearl); }
.status-badge--ok { background: var(--love); color: var(--pearl); }
.status-badge--running { background: var(--champagne-glow); color: var(--champagne-deep); }

.campaign-row {
  cursor: pointer;
  transition: background 0.2s;
}

.campaign-row:hover {
  background: var(--champagne-soft);
}

.automation-card {
  background: var(--cloud);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.automation-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.automation-toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  cursor: pointer;
}

.automation-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.automation-note {
  font-size: 0.8rem;
  color: var(--smoke);
  margin-top: 0.75rem;
}

.automation-runs-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  font-size: 0.85rem;
}

.automation-runs-table th {
  padding: 0.6rem;
  text-align: left;
  background: var(--pearl);
  border-bottom: 1px solid var(--mist);
}

.automation-runs-table td {
  padding: 0.6rem;
  border-bottom: 1px solid var(--mist);
}

.modal-content--wide {
  width: 60%;
  max-width: 900px;
}

/* ============================================================
   Brand Hub (Etap 3)
   ============================================================ */

.brand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.25rem;
}

.brand-card {
  background: var(--pearl);
  border: 1px solid var(--mist);
  border-radius: 12px;
  padding: 1.25rem;
  cursor: pointer;
  transition: all 0.2s;
}

.brand-card:hover {
  border-color: var(--champagne);
  box-shadow: var(--shadow-card);
  transform: translateY(-2px);
}

.brand-card__name {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.75rem;
}

.brand-card__stats {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.brand-card__stats > div {
  display: flex;
  flex-direction: column;
}

.brand-card__stats .val {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--champagne-deep);
}

.brand-card__stats .lbl {
  font-size: 0.7rem;
  color: var(--smoke);
}

/* ============================================================
   Lejek akwizycji (Etap 3)
   ============================================================ */

.funnel-steps {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2rem;
}

.funnel-step__label {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--ink);
}

.funnel-step__count {
  color: var(--champagne-deep);
  font-family: var(--font-display);
}

.funnel-step__track {
  background: var(--cloud);
  border-radius: 8px;
  height: 14px;
  overflow: hidden;
}

.funnel-step__bar {
  background: linear-gradient(90deg, var(--champagne) 0%, var(--champagne-deep) 100%);
  height: 100%;
  border-radius: 8px;
  transition: width 0.4s var(--ease-lux, ease);
}

.funnel-step__bar--secondary {
  background: var(--champagne-soft);
}

.funnel-step__drop {
  font-size: 0.8rem;
  color: var(--smoke);
  margin-top: 0.3rem;
}

.drop-badge {
  display: inline-block;
  background: var(--nope);
  color: var(--pearl);
  padding: 0.1rem 0.5rem;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.75rem;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 1280px) {
  .modal-content {
    width: 50%;
  }
}

@media (max-width: 768px) {
  .panel-header {
    flex-direction: column;
    gap: 1rem;
  }

  .header-right {
    flex-direction: column;
    width: 100%;
    gap: 1rem;
  }

  .crm-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--mist);
  }

  .modal-content {
    width: 100%;
  }
}
