/* ============================================================
   CzatBot — styles.css
   Jasny, profesjonalny panel; ciemny sidebar; zero frameworków.
   ============================================================ */

:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --border: #e3e8f0;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-d: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --sidebar: #1b2233;
  --sidebar-hover: #26304a;
  --sidebar-text: #c4cbdd;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
code { font-family: Consolas, "Courier New", monospace; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.mono { font-family: Consolas, monospace; font-size: 12px; }

/* ---------- przyciski ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  font-size: 13.5px; font-weight: 600; font-family: inherit;
  cursor: pointer; background: #eef1f7; color: var(--text);
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #e2e8f2; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: #f1f5f9; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
}
.sidebar-logo { padding: 18px 20px; font-size: 18px; font-weight: 700; color: #fff; letter-spacing: .5px; }
.org-switch { padding: 0 14px 14px; }
.org-select {
  width: 100%; background: #0f1522; color: #e5e9f5;
  border: 1px solid #2c3650; border-radius: 8px; padding: 8px; font-size: 13px;
}
.nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.nav-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 8px; color: var(--sidebar-text);
  margin-bottom: 2px; font-weight: 500; font-size: 13.5px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-badge {
  margin-left: auto; background: #ef4444; color: #fff;
  border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 700;
}
.sidebar-foot { padding: 12px 14px; border-top: 1px solid #2c3650; font-size: 12.5px; display: flex; flex-direction: column; gap: 4px; }
.sidebar-foot a { color: #93c5fd; }
.sidebar-foot a.logout { color: #f87171; }

.main { flex: 1; margin-left: 240px; min-width: 0; display: flex; flex-direction: column; }
.imp-bar {
  background: #7c3aed; color: #fff; padding: 8px 20px;
  display: flex; align-items: center; gap: 12px; font-size: 13px;
  position: sticky; top: 0; z-index: 60;
}
.imp-bar .btn { margin-left: auto; }
.page-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 26px; background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.has-imp .page-head { top: 37px; }
.page-title { font-size: 20px; }
.page-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.page-body { padding: 24px 26px; max-width: 1240px; width: 100%; }
.hamburger { display: none; }

/* ---------- karty / KPI ---------- */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 18px;
}
.card-title { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi-label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.kpi-val { font-size: 24px; font-weight: 700; margin-top: 4px; }
.kpi-sub { margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.detail-grid { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; font-size: 13.5px; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; }

/* ---------- tabele ---------- */
.tbl-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 18px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; padding: 10px 12px; background: #f8fafc;
  color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover td { background: #f8fafc; }

/* ---------- badge ---------- */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  font-size: 11.5px; font-weight: 600; background: #e2e8f0; color: #334155; white-space: nowrap;
}
.badge-active, .badge-ready, .badge-paid, .badge-ok, .badge-done, .badge-accepted { background: #dcfce7; color: #15803d; }
.badge-trial { background: #dbeafe; color: #1d4ed8; }
.badge-draft, .badge-pending, .badge-archived, .badge-ended, .badge-disabled,
.badge-cancelled, .badge-spam, .badge-deleted, .badge-refunded, .badge-expired, .badge-revoked { background: #e2e8f0; color: #475569; }
.badge-paused, .badge-processing, .badge-past_due, .badge-expiring,
.badge-needs_update, .badge-retry, .badge-partially_refunded { background: #fef3c7; color: #b45309; }
.badge-blocked, .badge-error, .badge-failed, .badge-suspended, .badge-escalated, .badge-timeout { background: #fee2e2; color: #b91c1c; }

/* ---------- progress ---------- */
.progress { height: 8px; background: #e5e9f2; border-radius: 6px; overflow: hidden; min-width: 80px; }
.progress-fill { height: 100%; background: var(--ok); border-radius: 6px; transition: width .3s; }
.progress-fill.warn { background: var(--warn); }
.progress-fill.danger { background: var(--danger); }
.progress-wrap { display: flex; align-items: center; gap: 8px; }
.progress-label { font-size: 11px; color: var(--muted); min-width: 36px; }

/* ---------- formularze ---------- */
.form-row { margin-bottom: 14px; }
.form-label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: #374151; }
.form-input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13.5px; font-family: inherit;
  background: #fff; color: var(--text);
}
.form-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
textarea.form-input { min-height: 80px; resize: vertical; }
input[type="color"].form-input { padding: 2px; height: 38px; }
input[type="range"].form-input { padding: 0; }
input[type="checkbox"].form-input { width: auto; }
.form-hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.check-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13.5px; cursor: pointer; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters .form-row { margin-bottom: 0; min-width: 150px; }
.list-editor .le-row { display: flex; gap: 8px; margin-bottom: 6px; }
.list-editor .le-row .form-input { flex: 1; }
.faq-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 8px; align-items: start; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  z-index: 500; display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto;
}
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal.modal-lg { max-width: 880px; }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-x { margin-left: auto; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; padding: 0 4px; }
.modal-x:hover { color: var(--text); }
.modal-body { padding: 18px; max-height: 72vh; overflow-y: auto; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- toasty ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; z-index: 900; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1f2937; color: #f9fafb; padding: 11px 16px; border-radius: 9px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
  opacity: 0; transform: translateY(8px); transition: all .25s; max-width: 360px;
}
.toast.show { opacity: 1; transform: none; }
.toast-ok { background: #15803d; }
.toast-err { background: #b91c1c; }
.toast-info { background: #1f2937; }

/* ---------- zakładki ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 9px 14px; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- auth ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: linear-gradient(135deg, #eef2ff, #f8fafc);
}
.auth-card { background: #fff; border-radius: 14px; box-shadow: 0 10px 40px rgba(15, 23, 42, .12); padding: 32px; width: 100%; max-width: 420px; }
.auth-logo { font-size: 24px; font-weight: 700; text-align: center; color: var(--primary); }
.auth-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 4px 0 20px; }
.auth-links { margin-top: 16px; text-align: center; font-size: 13px; }
.auth-links a { margin: 0 6px; }

/* ---------- różne ---------- */
.empty { padding: 30px; text-align: center; color: var(--muted); }
.error-box { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; border-radius: 10px; padding: 16px; margin-bottom: 14px; }
.info-box { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; font-size: 13px; }
.success-box { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; border-radius: 10px; padding: 16px; margin-bottom: 14px; }
.dev-token { background: #fffbeb; border: 1px dashed #f59e0b; border-radius: 8px; padding: 10px 12px; margin-top: 10px; font-size: 12.5px; word-break: break-all; }
.spinner { width: 26px; height: 26px; border: 3px solid #dbe3ef; border-top-color: var(--primary); border-radius: 50%; animation: cbspin .8s linear infinite; margin: 30px auto; }
@keyframes cbspin { to { transform: rotate(360deg); } }
.codebox { display: flex; gap: 8px; align-items: center; background: #0f172a; border-radius: 9px; padding: 10px 12px; margin: 8px 0; }
.codebox code { flex: 1; color: #a5f3fc; font-size: 12px; word-break: break-all; }
.codebox .btn { flex-shrink: 0; }

/* ---------- kreator ---------- */
.wiz-steps { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.wiz-step { font-size: 11.5px; padding: 3px 10px; border-radius: 12px; background: #e5e9f2; color: var(--muted); font-weight: 600; }
.wiz-step.active { background: var(--primary); color: #fff; }
.wiz-step.done { background: #dcfce7; color: #15803d; }
.plan-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.plan-card { border: 2px solid var(--border); border-radius: 10px; padding: 14px; cursor: pointer; transition: border-color .15s, background .15s; }
.plan-card:hover { border-color: #bfdbfe; }
.plan-card.selected { border-color: var(--primary); background: #eff6ff; }
.plan-card h4 { font-size: 14px; margin-bottom: 4px; }
.plan-price { font-size: 20px; font-weight: 700; margin: 6px 0; }
.plan-feats { font-size: 12px; color: var(--muted); }

/* ---------- tester czatu ---------- */
.chat-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .3); z-index: 400; }
.chat-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 400px; max-width: 95vw;
  background: #fff; z-index: 401; display: flex; flex-direction: column;
  box-shadow: -10px 0 30px rgba(0, 0, 0, .2);
}
.chat-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: #f8fafc; }
.chat-msg { max-width: 85%; padding: 9px 12px; border-radius: 12px; font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.chat-msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-msg.err { align-self: flex-start; background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.chat-src { font-size: 11px; color: var(--muted); margin-top: 6px; border-top: 1px dashed var(--border); padding-top: 5px; }
.chat-thumb { max-width: 160px; max-height: 160px; border-radius: 10px; display: block; margin: 6px 0; object-fit: contain; background: #fff; }
.chat-rate { margin-top: 6px; display: flex; gap: 6px; }
.chat-rate button { background: none; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 13px; padding: 2px 7px; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }

/* ---------- podgląd widgetu ---------- */
.widget-preview { position: relative; height: 320px; background: #f1f5f9; border-radius: 10px; border: 1px dashed var(--border); overflow: hidden; }
.wprev-bubble {
  position: absolute; width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px; box-shadow: 0 6px 16px rgba(0, 0, 0, .25);
}
.wprev-window { position: absolute; bottom: 70px; width: 240px; background: #fff; box-shadow: 0 10px 30px rgba(0, 0, 0, .18); overflow: hidden; font-size: 12px; }
.wprev-head { padding: 10px 12px; color: #fff; font-weight: 600; }
.wprev-body { padding: 12px; color: var(--text); }
.wprev-greet { background: #f1f5f9; border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; }
.wprev-input { border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; color: var(--muted); }

/* ---------- powiadomienia ---------- */
.notif { padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; background: #fff; display: flex; gap: 12px; align-items: flex-start; }
.notif.unread { border-left: 4px solid var(--primary); background: #f8fbff; }
.notif-body { flex: 1; }
.notif-title { font-weight: 600; }

/* ---------- źródła / wyniki ---------- */
.src-item { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; font-size: 13px; }
.chunk-item { border-bottom: 1px solid var(--border); padding: 10px 4px; font-size: 12.5px; }
.chunk-item:last-child { border-bottom: none; }
.chunk-seq { font-size: 11px; color: var(--muted); margin-bottom: 4px; }

/* ---------- responsywność ---------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .hamburger { display: inline-flex; }
  .grid-2 { grid-template-columns: 1fr; }
  .page-body { padding: 16px; }
  .chat-drawer { width: 100vw; max-width: 100vw; }
}
