/* Agent Panel — Design System (identyczny z rez.garazkielce.pl) */

:root {
  --bg:       #0e0e0e;
  --surface:  #161616;
  --surface2: #1e1e1e;
  --surface3: #242424;
  --border:   #2a2a2a;
  --border2:  #383838;

  --orange:  #e8533a;
  --green:   #4caf7d;
  --blue:    #4a9eff;
  --yellow:  #f0a500;
  --purple:  #9b6dff;

  --text:     #e8e4dc;
  --text-dim: #666;

  --radius:    6px;
  --radius-lg: 10px;

  --font-head: 'Bebas Neue', sans-serif;
  --font-body: 'DM Sans', sans-serif;
  --font-mono: 'DM Mono', monospace;
}

/* ── Sidebar init — ustawia szerokość przed pierwszym renderem (bez transition) ── */
html.sb-init-expanded .app-sidebar { width: 220px; }

/* ── Reset ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font-body); font-size: 14px; line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; color: inherit; font-family: inherit; font-size: inherit; }
input, textarea, select { font-family: var(--font-body); font-size: 14px; }

/* ── App layout ─────────────────────────────────────── */
#app { display: flex; height: 100vh; height: 100dvh; }

/* ── Sidebar ─────────────────────────────────────────── */
.app-sidebar {
  width: 56px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width .2s ease;
  z-index: 100;
}
.app-sidebar.expanded { width: 220px; }

.sb-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 56px;
  min-height: 56px;
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
  cursor: pointer;
  transition: background .15s;
}
.sb-logo:hover { background: var(--surface3); }
.sb-logo-icon { font-size: 18px; color: var(--text-dim); flex-shrink: 0; width: 24px; text-align: center; }
.sb-brand { font-family: var(--font-head); font-size: 22px; color: var(--orange); letter-spacing: .08em; line-height: 1; }
.sb-sub   { font-family: var(--font-mono); font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .1em; }

.sb-sep { height: 1px; background: var(--border); margin: 4px 0; flex-shrink: 0; }
.sb-fill { flex: 1; }

.sb-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 48px;
  min-height: 48px;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  color: var(--text-dim);
  transition: background .15s, color .15s;
  font-size: 14px;
  font-family: var(--font-body);
  text-decoration: none;
}
.sb-item:hover  { background: var(--surface3); color: var(--text); }
.sb-item.active { color: var(--orange); background: rgba(232,83,58,.08); }
.sb-icon  { width: 24px; font-size: 17px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.sb-label { flex: 1; font-size: 14px; }

.app-sidebar:not(.expanded) .sb-label,
.app-sidebar:not(.expanded) .sb-sub,
.app-sidebar:not(.expanded) .sb-brand { display: none; }

/* ── Main content ─────────────────────────────────────── */
.app-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.page-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 56px;
  min-height: 56px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.page-title {
  font-family: var(--font-head);
  font-size: 22px;
  color: var(--text);
  letter-spacing: .08em;
}
.page-title-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.header-spacer { flex: 1; }

.page-body { flex: 1; overflow-y: auto; padding: 24px; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-family: var(--font-head);
  font-size: 14px;
  letter-spacing: .08em;
  text-transform: uppercase;
  transition: opacity .15s, background .15s;
  cursor: pointer;
  border: none;
  white-space: nowrap;
}
.btn-primary   { background: var(--orange);   color: #fff; }
.btn-secondary { background: var(--surface3); color: var(--text); border: 1px solid var(--border2); }
.btn-danger    { background: rgba(232,83,58,.12); color: var(--orange); border: 1px solid rgba(232,83,58,.3); }
.btn:hover     { opacity: .85; }
.btn:disabled  { opacity: .35; cursor: default; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ── Cards ─────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 24px;
}

/* ── KPI kafelki ─────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-left: 3px solid var(--kpi-color, var(--orange));
  padding: 16px 20px;
}
.kpi-label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.kpi-value {
  font-family: var(--font-head);
  font-size: 36px;
  color: var(--text);
  line-height: 1;
}
.kpi-meta { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* ── Tabela ─────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.data-table th {
  background: var(--surface2);
  padding: 10px 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  text-align: left;
  font-weight: 400;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }

/* ── Tagi/badge ─────────────────────────────────────── */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 500;
}
.tag-green  { background: rgba(76,175,125,.15);  color: var(--green); }
.tag-orange { background: rgba(232,83,58,.15);   color: var(--orange); }
.tag-blue   { background: rgba(74,158,255,.15);  color: var(--blue); }
.tag-yellow { background: rgba(240,165,0,.15);   color: var(--yellow); }
.tag-dim    { background: rgba(255,255,255,.06); color: var(--text-dim); }

/* ── Formularze ─────────────────────────────────────── */
.form-group { margin-bottom: 20px; }
.form-group label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.form-input, .form-textarea, .form-select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.form-input:focus, .form-textarea:focus, .form-select:focus { border-color: var(--orange); }
.form-textarea { resize: vertical; min-height: 100px; line-height: 1.6; }
.form-select { appearance: none; cursor: pointer; }

/* ── Flash messages ─────────────────────────────────── */
.flash {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 20px;
}
.flash-success { background: rgba(76,175,125,.12); border: 1px solid rgba(76,175,125,.3); color: var(--green); }
.flash-error   { background: rgba(232,83,58,.12);  border: 1px solid rgba(232,83,58,.3);  color: var(--orange); }

/* ── Paginacja ─────────────────────────────────────── */
.pagination { display: flex; gap: 4px; align-items: center; margin-top: 16px; }
.pagination a, .pagination span {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  background: var(--surface);
}
.pagination a:hover  { border-color: var(--orange); color: var(--orange); }
.pagination .current { background: var(--orange); color: #fff; border-color: var(--orange); }

/* ── Rozmowa (bańki) ─────────────────────────────────── */
.chat-bubbles { display: flex; flex-direction: column; gap: 12px; padding: 16px 0; }
.bubble { max-width: 70%; }
.bubble-in  { align-self: flex-start; }
.bubble-out { align-self: flex-end; }
.bubble-text {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
}
.bubble-in  .bubble-text { background: var(--surface2); border-bottom-left-radius: 2px; }
.bubble-out .bubble-text { background: rgba(232,83,58,.18); border-bottom-right-radius: 2px; }
.bubble-meta { font-size: 11px; color: var(--text-dim); margin-top: 3px; font-family: var(--font-mono); }
.bubble-in  .bubble-meta { text-align: left; }
.bubble-out .bubble-meta { text-align: right; }

/* ── Empty state ─────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-dim); }
.empty-state-icon { font-size: 48px; margin-bottom: 12px; opacity: .4; }
.empty-state-text { font-size: 14px; }

/* ── Klikalne wiersze tabeli (desktop + mobile) ── */
.tr-link { cursor: pointer; }

/* ── Mobile "Więcej" panel — domyślnie ukryty ── */
.sb-more-btn { display: none; }
.sb-more-panel {
  display: none;
  position: fixed;
  bottom: 56px; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 199;
  flex-direction: column;
}
.sb-more-panel.open { display: flex; }
.sb-more-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 20px;
  font-size: 15px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  cursor: pointer;
  background: none;
  border-left: none; border-right: none; border-top: none;
  border-bottom: 1px solid var(--border);
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
}
.sb-more-item:last-child { border-bottom: none; }
.sb-more-item.active { color: var(--orange); }
.sb-more-item i, .sb-more-item svg { width: 20px; text-align: center; flex-shrink: 0; }
.sb-more-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 198;
}
.sb-more-backdrop.open { display: block; }

/* ── Mobile (≤ 768px) ────────────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar → fixed bottom nav */
  .app-sidebar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100% !important;
    height: 56px;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 200;
    overflow: visible;
    transition: none;
  }

  /* Ukryj elementy sidebar niepassujące do bottom nav */
  .sb-logo, .sb-fill, .sb-sep { display: none !important; }

  /* Ukryj drugorzędne elementy nav + logout z bottom bara */
  .sb-item[data-nav="knowledge"],
  .sb-item[data-nav="injections"],
  .sb-item[data-nav="agent"],
  .sb-item[data-nav="widget"],
  .sb-logout-btn { display: none !important; }

  /* Pokaż przycisk "Więcej" */
  .sb-more-btn { display: flex; }

  /* Style nav items w bottom bar */
  .sb-item {
    flex: 1 !important;
    height: 56px !important;
    min-height: 56px !important;
    max-height: 56px !important;
    padding: 10px 0 0 !important;
    flex-direction: column !important;
    gap: 2px !important;
    justify-content: flex-start !important;
    align-items: center !important;
    overflow: hidden !important;
  }

  .sb-icon { width: auto !important; font-size: 17px; }

  /* Pokaż etykiety zawsze — nawet gdy sidebar zwinięty */
  .app-sidebar:not(.expanded) .sb-label { display: block; }
  .sb-label { font-size: 9px; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .03em; }

  /* Main — pełna szerokość, padding na dole dla bottom nav */
  .app-main { padding-bottom: 56px; }

  /* Header */
  .page-header {
    padding: 10px 16px;
    height: auto;
    min-height: 48px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .page-title { font-size: 18px; }
  .header-spacer { display: none; }

  /* Page body */
  .page-body { padding: 16px; }

  /* KPI grid — 2 kolumny */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
  .kpi-value { font-size: 26px; }
  .kpi-card { padding: 12px 14px; }

  /* Tabele → karty na mobile */
  .table-scroll { overflow-x: visible; margin: 0; padding: 0; }

  .data-table {
    display: block;
    min-width: 0 !important;
    border: none;
    background: transparent;
    border-radius: 0;
  }
  .data-table thead { display: none; }
  .data-table tbody { display: flex; flex-direction: column; gap: 8px; }

  .data-table tr.tr-link {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
    gap: 4px 10px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }
  .data-table tr.tr-link:hover { background: var(--surface2); }

  .data-table tr.tr-link td {
    display: block;
    padding: 0;
    border: none;
    background: transparent !important;
    vertical-align: unset;
  }

  /* td1: nadawca — wiersz 1, kol 1 */
  .data-table tr.tr-link td:nth-child(1) { grid-column: 1; grid-row: 1; }
  /* td2: kanał — wiersz 1, kol 2 */
  .data-table tr.tr-link td:nth-child(2) { grid-column: 2; grid-row: 1; align-self: center; }
  /* td3: liczba wiadomości — ukryta */
  .data-table tr.tr-link td:nth-child(3) { display: none; }
  /* td4: data — wiersz 3 */
  .data-table tr.tr-link td:nth-child(4) { grid-column: 1 / -1; grid-row: 3; }
  /* td5: ostatnia wiadomość — wiersz 2 */
  .data-table tr.tr-link td:nth-child(5) {
    grid-column: 1 / -1; grid-row: 2;
    white-space: normal; max-width: 100%;
    overflow: hidden; text-overflow: ellipsis;
    display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical;
    font-size: 12px;
  }
  /* td6: przycisk — ukryty */
  .data-table tr.tr-link td:nth-child(6) { display: none; }

  /* Buttons */
  .btn { padding: 8px 14px; }
  .btn-sm { padding: 5px 10px; }

  /* Cards */
  .card { padding: 14px 16px; }

  /* Bańki rozmowy */
  .bubble { max-width: 90%; }

  /* Widok rozmowy — kolumnowy na mobile */
  .conv-layout { flex-direction: column !important; }
  .conv-layout > div:last-child { width: 100% !important; }
}
