/* ============================================================
   Dashboard Mastto — style
   Tokeny projektu jako zmienne CSS (:root). Zmiana --accent przebarwia całość.
   ============================================================ */
:root {
  --bg:            #0a0f1e;
  --sidebar-bg:    #0b1120;
  --card-bg:       #111a2e;

  --text:          #e6eaf3;
  --text-strong:   #f3f6fc;
  --text-muted:    #8a94ab;
  --text-faint:    #6f7a94;
  --text-dim:      #5c6683;

  --accent:        #e7b782;
  --accent-ink:    #241606;
  --accent-soft:   rgba(231,183,130,0.13);

  --blue:          #5b8def;
  --green:         #6fcf97;
  --purple:        #c58ce0;

  --border:        rgba(255,255,255,0.06);
  --border-2:      rgba(255,255,255,0.08);
  --hairline:      rgba(255,255,255,0.05);

  --sidebar-w:      264px;
  --sidebar-w-min:  76px;
  --radius-card:    16px;
  --radius-md:      11px;
  --radius-sm:      9px;

  --font: 'Manrope', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  color-scheme: dark;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: #f0cfa4; }

svg { display: block; }
[data-lucide] { width: 18px; height: 18px; stroke-width: 1.75; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
  border-radius: 8px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.14); background-clip: padding-box; }

/* ============================================================ LAYOUT */
.app { display: flex; height: 100vh; width: 100%; overflow: hidden; }
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }

/* Scrim pod menu mobilne (ukryty na desktopie) */
.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(3,6,15,0.6);
  opacity: 0; visibility: hidden;
  transition: opacity 180ms ease, visibility 180ms ease;
}

/* ============================================================ SIDEBAR */
.sidebar {
  flex: none;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: width 180ms ease;
}

.switcher {
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 18px 16px;
  border-bottom: 1px solid var(--border);
}
.switcher__brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.logo {
  width: 38px; height: 38px; flex: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent), #c98f56);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent-ink); font-weight: 800; font-size: 17px;
  box-shadow: 0 4px 14px rgba(231,183,130,0.25);
}
.switcher__text { min-width: 0; }
.switcher__name { font-size: 14.5px; font-weight: 700; color: var(--text-strong); line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.switcher__sub  { font-size: 11.5px; color: var(--text-faint); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border-2);
  background: rgba(255,255,255,0.03);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); color: #dbe2f0; }

.nav {
  flex: 1 1 auto;
  overflow-y: auto; overflow-x: hidden;
  padding: 14px 16px 10px;
  display: flex; flex-direction: column; gap: 3px;
}
.nav__item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 11px 12px;
  border: none; border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer; text-align: left;
  font-family: var(--font); font-size: 13.5px; font-weight: 500;
  transition: background 120ms ease, color 120ms ease;
}
.nav__item:hover { background: rgba(255,255,255,0.04); color: #c7d0e4; }
.nav__icon { display: flex; flex: none; color: var(--text-muted); }
.nav__label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav__bar {
  position: absolute; right: -16px; top: 9px; bottom: 9px;
  width: 3px; border-radius: 3px 0 0 3px;
  background: var(--accent);
  opacity: 0;
}
.nav__item.is-active { background: rgba(255,255,255,0.06); color: var(--text-strong); font-weight: 700; }
.nav__item.is-active .nav__icon { color: var(--accent); }
.nav__item.is-active .nav__bar { opacity: 1; }

.userbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 14px 16px;
  border-top: 1px solid var(--border);
}
.userbar__brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.avatar {
  width: 36px; height: 36px; flex: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #39507d, #26324e);
  display: flex; align-items: center; justify-content: center;
  color: #dbe6fb; font-weight: 700; font-size: 13px;
  border: 1px solid rgba(255,255,255,0.1);
}
.userbar__text { min-width: 0; }
.userbar__name { font-size: 13.5px; font-weight: 600; color: #e9edf6; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.userbar__sub  { font-size: 11.5px; color: var(--text-faint); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Stan zwinięty (desktop) ---- */
.app.is-collapsed .sidebar { width: var(--sidebar-w-min); }
.app.is-collapsed .switcher { justify-content: center; padding: 18px 0; }
.app.is-collapsed .userbar  { justify-content: center; padding: 14px 0; }
.app.is-collapsed .nav__item { justify-content: center; padding: 11px 0; }
.app.is-collapsed .switcher__text,
.app.is-collapsed .switcher__toggle,
.app.is-collapsed .userbar__text,
.app.is-collapsed .userbar .icon-btn,
.app.is-collapsed .nav__label { display: none; }

/* ============================================================ TOPBAR */
.topbar {
  flex: none; height: 60px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
}
.topbar .icon-btn { width: 34px; height: 34px; border-radius: var(--radius-sm); color: #aeb7cc; }
.topbar__divider { width: 1px; height: 24px; background: var(--border-2); }
.topbar__spacer { flex: 1 1 auto; }
.topbar__logout { display: flex; margin: 0; }
#menuBtn { display: none; }

.tabs { display: flex; align-items: center; gap: 4px; }
.tab {
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  font-family: var(--font); font-size: 13px; font-weight: 500;
  background: transparent; color: var(--text-muted);
  transition: background 120ms ease, color 120ms ease;
}
.tab:hover { color: #dbe2f0; }
.tab.is-active { background: rgba(255,255,255,0.07); color: var(--text-strong); font-weight: 700; }

.cta {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 8px 15px; border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  font-family: var(--font); font-size: 13px; font-weight: 700;
  background: var(--accent); color: var(--accent-ink);
  transition: filter 120ms ease;
}
.cta:hover { filter: brightness(1.06); }
.cta [data-lucide] { width: 16px; height: 16px; }

/* ============================================================ CONTENT */
.content { flex: 1 1 auto; overflow-y: auto; padding: 26px 28px 40px; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 20px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-title { margin: 0; font-size: 25px; font-weight: 800; letter-spacing: -0.02em; color: var(--text-strong); }
.page-sub   { margin: 6px 0 0; font-size: 13.5px; color: var(--text-muted); }
.page-head__right { display: flex; align-items: center; gap: 12px; }

.datepill {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-muted); font-size: 13px;
  padding: 8px 13px; border: 1px solid var(--border-2);
  border-radius: 10px; background: rgba(255,255,255,0.02);
}
.datepill__icon { display: flex; color: var(--accent); }

.rangeswitch {
  display: flex; align-items: center; padding: 3px; gap: 2px;
  border: 1px solid var(--border-2); border-radius: 10px;
  background: rgba(255,255,255,0.02);
}
.range {
  padding: 6px 12px; border-radius: 8px; border: none; cursor: pointer;
  font-family: var(--font); font-size: 12px; font-weight: 600;
  background: transparent; color: var(--text-muted);
}
.range.is-active { background: var(--accent); color: var(--accent-ink); }

/* ---- Card ---- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 18px;
}
.card__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card__title { font-size: 15px; font-weight: 700; color: #eef2fa; }
.link { font-size: 12px; font-weight: 600; }

/* ---- KPI ---- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 18px; }
.kpi { padding: 18px 18px 16px; }
.kpi__top { display: flex; align-items: center; justify-content: space-between; }
.kpi__icon {
  width: 38px; height: 38px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
}
.kpi__icon--accent { background: var(--accent-soft); color: var(--accent); }
.kpi__icon--blue   { background: rgba(91,141,239,0.14); color: var(--blue); }
.kpi__icon--purple { background: rgba(197,140,224,0.14); color: var(--purple); }
.kpi__icon--green  { background: rgba(111,207,151,0.14); color: var(--green); }
.kpi__value { margin-top: 15px; font-size: 29px; font-weight: 800; letter-spacing: -0.02em; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.kpi__label { margin-top: 3px; font-size: 12.5px; color: var(--text-muted); }

.delta { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 7px; }
.delta--pos { color: var(--green); background: rgba(111,207,151,0.12); }
.delta--neutral { color: var(--text-muted); background: rgba(255,255,255,0.06); }

/* ---- Grids ---- */
.grid-main   { display: grid; grid-template-columns: 1.85fr 1fr; gap: 16px; margin-bottom: 18px; }
.grid-bottom { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }

/* ---- Chart ---- */
.chartcard { display: flex; flex-direction: column; padding: 20px 22px 16px; }
.chartcard__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.chartcard__stat { margin-top: 5px; display: flex; align-items: baseline; gap: 10px; }
.chartcard__num { font-size: 24px; font-weight: 800; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.chartcard__delta { font-size: 12.5px; color: var(--green); font-weight: 600; }

.legend { display: flex; align-items: center; gap: 16px; font-size: 12px; color: var(--text-muted); }
.legend__item { display: flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; }
.dot--accent { background: var(--accent); }
.dot--blue { background: var(--blue); }

.chart { flex: 1 1 auto; margin-top: 14px; min-height: 230px; position: relative; }
.chart svg { width: 100%; height: 100%; }
.grid-line { stroke: rgba(255,255,255,0.05); }
.chart-line { stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; }
.chart-dot { fill: var(--accent); stroke: var(--card-bg); stroke-width: 3; }
.chart__axis {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--text-dim);
  padding-top: 8px; margin-top: 4px;
  border-top: 1px solid var(--hairline);
}

/* ---- Lists ---- */
.list { display: flex; flex-direction: column; }

.meeting { display: flex; align-items: center; gap: 13px; padding: 12px 4px; border-bottom: 1px solid var(--hairline); }
.meeting__time { flex: none; width: 46px; text-align: center; font-size: 14px; font-weight: 700; color: #f0f3fa; font-variant-numeric: tabular-nums; }
.meeting__bar { width: 3px; height: 34px; border-radius: 3px; flex: none; }
.meeting__bar--accent { background: var(--accent); }
.meeting__body { min-width: 0; flex: 1 1 auto; }
.meeting__name { font-size: 13px; font-weight: 600; color: #e9edf6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meeting__kind { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }

.lead { display: flex; align-items: center; gap: 13px; padding: 11px 4px; border-bottom: 1px solid var(--hairline); }
.lead__avatar { flex: none; width: 36px; height: 36px; border-radius: 10px; background: rgba(255,255,255,0.05); border: 1px solid var(--border-2); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #c7d0e4; }
.lead__body { min-width: 0; flex: 1 1 auto; }
.lead__name { font-size: 13px; font-weight: 600; color: #e9edf6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead__source { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; }
.lead__time { flex: none; width: 70px; text-align: right; font-size: 11.5px; color: var(--text-faint); }

.post { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--hairline); }
.post__body { min-width: 0; flex: 1 1 auto; }
.post__title { font-size: 13px; font-weight: 600; color: #e9edf6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.post__date { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

/* ---- Chips ---- */
.chip { flex: none; font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 20px; white-space: nowrap; }
.chip--new     { color: var(--accent); background: var(--accent-soft); }
.chip--contact { color: var(--blue);   background: rgba(91,141,239,0.14); }
.chip--won     { color: var(--green);  background: rgba(111,207,151,0.14); }
.chip--planned { color: var(--purple); background: rgba(197,140,224,0.14); }
.chip--draft   { color: var(--text-muted); background: rgba(255,255,255,0.06); }

/* ---- Stan pusty (moduł w budowie) ---- */
.empty { text-align: center; padding: 56px 24px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty__icon {
  width: 60px; height: 60px; border-radius: 16px; margin-bottom: 6px;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.empty__icon [data-lucide] { width: 26px; height: 26px; }
.empty__title { font-size: 17px; font-weight: 700; color: var(--text-strong); }
.empty__text { max-width: 460px; font-size: 13.5px; color: var(--text-muted); line-height: 1.6; margin: 0; }

/* ---- Alerty (komunikaty w panelu) ---- */
.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; line-height: 1.5; }
.alert--ok  { background: rgba(111,207,151,0.12); color: var(--green); }
.alert--err { background: rgba(224,108,108,0.14); color: #f0a0a0; }

/* ---- Przyciski / pola formularzy w panelu ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-2); background: rgba(255,255,255,0.04);
  color: var(--text-strong); font-family: var(--font); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: filter 120ms ease, background 120ms ease;
}
.btn:hover { background: rgba(255,255,255,0.08); }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
.btn--primary:hover { filter: brightness(1.06); }
.btn--sm { padding: 7px 11px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field {
  width: 100%; padding: 9px 11px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  color: var(--text); font-family: var(--font); font-size: 13px;
}
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field--sm { padding: 6px 9px; }
.field::-webkit-calendar-picker-indicator { filter: invert(0.7); }

/* ---- Tabela danych (leady, terminy) ---- */
.tablecard { padding: 18px; }
.tablewrap { overflow-x: auto; }
.dtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.dtable th {
  text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border-2);
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); font-weight: 600; white-space: nowrap;
}
.dtable td { padding: 11px 12px; border-bottom: 1px solid var(--hairline); vertical-align: top; color: var(--text); }
.dtable tr:last-child td { border-bottom: none; }
.dtable .muted { color: var(--text-faint); font-size: 12px; }
.dtable .empty-row { text-align: center; padding: 30px; }
.dtable .actions form { display: inline-flex; gap: 6px; margin: 0 4px 6px 0; align-items: center; }
.dtable .actions input[type=url] { width: 190px; }
.regon-ok { color: var(--green); }
.regon-warn { color: var(--accent); }

/* Tagi stanu rezerwacji */
.tag { display: inline-block; margin-top: 4px; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.tag-oczekuje    { background: rgba(231,183,130,0.14); color: var(--accent); }
.tag-potwierdzony{ background: rgba(111,207,151,0.14); color: var(--green); }
.tag-odrzucony, .tag-anulowany { background: rgba(255,255,255,0.06); color: var(--text-muted); }
.tag-zapytanie   { background: rgba(91,141,239,0.14); color: var(--blue); }

/* Klikalny NIP / nazwa firmy (otwiera dane z GUS) */
.firma-link {
  background: none; border: none; padding: 0; cursor: pointer;
  font: inherit; color: var(--accent); text-align: left;
  text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 2px;
}
.firma-link:hover { color: #f0cfa4; }
.firma-link.regon-ok { color: var(--green); }
.firma-link.regon-ok:hover { filter: brightness(1.1); }

/* Formularz zmiany terminu (inline w akcjach) */
.reschedule { flex-wrap: wrap; }
.reschedule .field { width: auto; }

/* ---- Lightbox (dane firmy z GUS) ---- */
.lb { position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; padding: 20px; }
.lb[hidden] { display: none; }
.lb__backdrop { position: absolute; inset: 0; background: rgba(3,6,15,0.68); }
.lb__panel {
  position: relative; z-index: 1;
  width: 100%; max-width: 460px; max-height: 84vh; overflow-y: auto;
  background: var(--card-bg); border: 1px solid var(--border-2);
  border-radius: var(--radius-card); box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.lb__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--card-bg);
}
.lb__title { font-size: 15px; font-weight: 700; color: var(--text-strong); }
.lb__body { padding: 8px 18px 18px; }
.lb__row { display: flex; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--hairline); }
.lb__row:last-child { border-bottom: none; }
.lb__k { flex: 0 0 140px; font-size: 12px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; }
.lb__v { flex: 1 1 auto; min-width: 0; font-size: 13.5px; color: var(--text); word-break: break-word; }
.lb__empty { padding: 24px 0; text-align: center; color: var(--text-muted); font-size: 13.5px; }

/* ---- Responsywność ---- */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-main, .grid-bottom { grid-template-columns: 1fr; }
}

/* Mobile: sidebar jako nakładka nad treścią */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 50;
    transform: translateX(-100%);
    transition: transform 200ms ease;
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
  }
  .app.is-menu-open .sidebar { transform: translateX(0); }
  .app.is-menu-open .scrim { opacity: 1; visibility: visible; }
  /* na mobile przycisk zwijania działa jak otwieranie menu */
  .app.is-collapsed .sidebar { width: var(--sidebar-w); }
  .app.is-collapsed .switcher__text,
  .app.is-collapsed .userbar__text,
  .app.is-collapsed .nav__label,
  .app.is-collapsed .switcher__toggle,
  .app.is-collapsed .userbar .icon-btn { display: flex; }
  .app.is-collapsed .nav__item { justify-content: flex-start; padding: 11px 12px; }
  .content { padding: 20px 16px 36px; }
  .topbar { padding: 0 14px; gap: 10px; }
  .cta span { display: none; }
  .cta { padding: 8px 11px; }
}
