/* Sellway light theme — tokens lifted from sellway.pl/panel (Metronic-based):
   - Brand orange #E94112 (hover #F85517, soft tint #FFF3E0)
   - Page bg #FAFCFE, white cards with #E8E5DD borders, ~12px radius
   - Warm-gray text scale: #211F1C / #403D38 / #716D66 / #968E7E
*/
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");

:root {
  --bg: #FAFCFE;
  --surface: #ffffff;
  --surface-soft: #F7F8F8;
  --surface-alt: #F2F3F2;
  --ink: #211F1C;
  --ink-soft: #403D38;
  --ink-mid: #716D66;
  --muted: #968E7E;
  --line: #EAEAEA;
  --line-strong: #D8DCE3;
  --accent: #E94112;
  --accent-hover: #F85517;
  --accent-soft: #FFF3E0;
  --accent-strong: #C9370E;
  --good: #27AD10;
  --bad: #F06445;
  --radius: 12px;
  --radius-lg: 15px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 0.1rem 1rem 0.25rem rgba(0,0,0,0.05);
  --font:  "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono:  ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv01";
  /* Safety belt - no element should ever cause horizontal page scroll on mobile.
     Wide content (tables) has its own .table-wrap scroll. */
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px;
}

/* ----- Top bar ----- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 28px; background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img.wordmark { display: block; height: 22px; width: auto; }
.brand .brand-name { font-weight: 600; font-size: 14px; letter-spacing: -0.01em; color: var(--ink); }

.tabs { display: flex; gap: 2px; margin-left: 8px; }
.tab {
  padding: 7px 12px; border-radius: 8px; color: var(--ink-mid);
  font-weight: 500; font-size: 13.5px; letter-spacing: -0.005em;
  transition: background 120ms ease, color 120ms ease;
}
.tab:hover { background: var(--surface-alt); color: var(--ink); }
.tab.is-active { background: var(--accent); color: #fff; }
.tab-signout { display: none; }   /* visible only inside mobile hamburger menu */

.user { margin-left: auto; display: flex; align-items: center; gap: 12px; color: var(--ink-mid); }
.freshness-badge {
  font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 6px;
  letter-spacing: 0.02em; font-variant-numeric: tabular-nums;
  background: var(--surface-alt); color: var(--ink-mid);
  border: 1px solid var(--line);
  cursor: help;
}
.freshness-badge.fresh { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.freshness-badge.stale { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.freshness-badge.broken { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.avatar { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); }
.email { font-size: 13px; color: var(--ink-soft); }
.logout {
  color: var(--muted); font-size: 12.5px; padding: 6px 10px; border-radius: 6px;
}
.logout:hover { color: var(--ink); background: var(--surface-alt); }

/* Hamburger button - only visible on narrow viewports (toggled via media query) */
.hamburger {
  display: none;
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
  padding: 0; cursor: pointer;
  flex-direction: column; gap: 4px; align-items: center; justify-content: center;
  width: 38px; height: 38px;
}
.hamburger span { display: block; width: 18px; height: 2px; background: var(--ink); border-radius: 1px; transition: transform 200ms ease, opacity 200ms ease; }
.hamburger[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hamburger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.hamburger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ----- Range bar ----- */
.range {
  display: flex; align-items: center; gap: 14px; padding: 18px 28px 8px;
  flex-wrap: wrap; max-width: 1480px; margin: 0 auto;
}
.range label {
  color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.04em; display: flex; align-items: center; gap: 8px; font-weight: 500;
}
.range input[type="date"] {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); font-family: var(--font); font-size: 13.5px; color: var(--ink);
}
.range input[type="date"]:hover { border-color: var(--line-strong); }
.btn-primary {
  background: var(--accent); color: white; border: 0; padding: 8px 16px; border-radius: 8px;
  font-weight: 600; font-size: 13.5px; cursor: pointer; font-family: var(--font);
  letter-spacing: -0.005em;
  transition: background 120ms ease, transform 80ms ease;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: translateY(1px); }
.muted { color: var(--muted); font-size: 12px; }
.range-sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.range-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 500; }

main { padding: 8px 28px 64px; max-width: 1480px; margin: 0 auto; }

/* ----- KPIs ----- */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px; margin-bottom: 22px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm);
  position: relative;
}
.kpi .kpi-ic {
  position: absolute; top: 12px; right: 12px;
  width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft);
}
.kpi .kpi-ic .ic { width: 15px; height: 15px; }
.kpi .label {
  color: var(--muted); font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; font-weight: 500; padding-right: 34px;
  /* reserve two lines so the value sits at the same height on every card,
     even when a label wraps (e.g. "Koszt leada hotelowego") */
  min-height: 2.7em; line-height: 1.35;
  display: flex; align-items: flex-start;
}
.kpi .value {
  font-size: 22px; font-weight: 600; margin-top: 6px;
  letter-spacing: -0.02em; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.kpi .sub { color: var(--ink-mid); font-size: 12px; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* Segment tiles: the same KPI card, three across, tucked under the main row */
.kpis-segments { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: -12px; }
@media (max-width: 640px) { .kpis-segments { grid-template-columns: 1fr; } }

/* Small "i" next to a card title; the explanation lives in its title attribute */
.info-tip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin-left: 8px; border-radius: 50%;
  border: 1px solid var(--line-strong); color: var(--muted);
  font-size: 10px; font-weight: 600; cursor: help; vertical-align: middle;
}
.info-tip { position: relative; }
.info-tip:hover, .info-tip:focus-visible { color: var(--accent); border-color: var(--accent); outline: none; }
/* CSS tooltip from data-tip: instant, styled, works with keyboard focus */
.info-tip::after {
  content: attr(data-tip); position: absolute; left: 50%; top: calc(100% + 8px); transform: translateX(-50%);
  width: 340px; max-width: min(340px, 80vw); padding: 10px 12px; border-radius: 10px;
  background: var(--ink); color: #fff; font-size: 12.5px; font-weight: 400; line-height: 1.45;
  text-transform: none; letter-spacing: 0; white-space: normal; text-align: left;
  box-shadow: var(--shadow); opacity: 0; visibility: hidden; transition: opacity .12s ease; z-index: 30; pointer-events: none;
}
.info-tip:hover::after, .info-tip:focus-visible::after { opacity: 1; visibility: visible; }
@media (max-width: 640px) { .info-tip::after { left: auto; right: 0; transform: none; } }

/* ----- Cards ----- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}
.card.no-pad { padding: 0; }
.card h2 {
  margin: 0 0 14px 0; font-size: 15px; font-weight: 600;
  letter-spacing: -0.01em; color: var(--ink);
  display: flex; align-items: center; gap: 9px;
}
/* Inline section icons (Feather-style, themed to the brand accent). */
.ic {
  width: 17px; height: 17px; flex: 0 0 auto;
  color: var(--accent); stroke-width: 2;
}
.ic-badge {
  width: 30px; height: 30px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft);
}
.ic-badge .ic { width: 16px; height: 16px; }
.card h3 {
  margin: 18px 0 8px 0; font-size: 13px; font-weight: 600; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.04em;
}

/* ----- Tables ----- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap > table { min-width: 720px; }
/* "fit" tables aim to sit inside a normal desktop width without sideways
   scroll: drop the min-width and let text columns wrap. */
.table-wrap.fit > table { min-width: 0; }
.table-wrap.fit td.wrap, .table-wrap.fit th.wrap { white-space: normal; }
.table-wrap.fit td, .table-wrap.fit th { padding: 9px 10px; }
.link-btn {
  color: var(--accent); font-weight: 600; font-size: 12.5px;
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 7px;
  display: inline-block; white-space: nowrap;
}
.link-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
th:first-child, td:first-child { text-align: left; font-variant-numeric: normal; }
/* Free-text cells (names, obiekt, branża): wrap and cap, so one long entry
   cannot stretch the column for the whole date range. */
td.wrap, th.wrap { white-space: normal; text-align: left; max-width: 260px; overflow-wrap: anywhere; }
thead th {
  background: var(--surface-soft); color: var(--muted);
  font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--line);
}
tbody tr:hover { background: var(--surface-soft); }
tbody tr:last-child td { border-bottom: 0; }
tr.total td {
  font-weight: 600; background: var(--surface-alt);
  border-top: 1px solid var(--line-strong);
}
td.num { font-family: var(--mono); font-size: 12.5px; color: var(--ink); }
td.dim { color: var(--muted); }

/* ----- Subtabs ----- */
.subtabs {
  display: flex; gap: 4px; margin-bottom: 16px;
  border-bottom: 1px solid var(--line); padding-bottom: 0;
}
.subtab {
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  padding: 8px 14px; font-family: var(--font); font-weight: 500; font-size: 13px;
  color: var(--ink-mid); cursor: pointer; letter-spacing: -0.005em;
  margin-bottom: -1px;
  transition: color 120ms ease, border-color 120ms ease;
}
.subtab:hover { color: var(--ink); }
.subtab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* Segmented control */
.card-header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.seg {
  display: inline-flex; background: var(--surface-alt); border-radius: 8px; padding: 3px;
  border: 1px solid var(--line);
}
.seg-btn {
  background: transparent; border: 0; padding: 6px 12px; border-radius: 6px;
  font-family: var(--font); font-size: 12.5px; font-weight: 500; color: var(--ink-mid);
  cursor: pointer; letter-spacing: -0.005em;
  transition: background 120ms ease, color 120ms ease;
}
.seg-btn:hover:not(.is-active) { color: var(--ink); }
.seg-btn.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); font-weight: 600; }

/* ----- Charts ----- */
.two-col {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 18px; margin-bottom: 18px;
}
.two-col > .card { margin-bottom: 0; }
/* Wrap every canvas in .chart-box with a fixed height to stop Chart.js
   from growing the canvas every resize (canvas grows -> parent grows -> canvas grows -> ...). */
.chart-box { position: relative; width: 100%; }
.chart-box > canvas { width: 100% !important; height: 100% !important; display: block; }

/* Status pill (good/warn/bad) - generic, reusable for pacing etc. */
.pct-pill {
  display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.pct-pill.pace-good { background: #d1fae5; color: #065f46; }
.pct-pill.pace-warn { background: #fef3c7; color: #92400e; }
.pct-pill.pace-bad { background: #fee2e2; color: #991b1b; }
.pct-pill.pace-neutral { background: var(--surface-alt); color: var(--muted); }

.cat-current { margin-bottom: 4px; font-variant-numeric: tabular-nums; }

.empty { padding: 28px; text-align: center; color: var(--muted); font-size: 13px; }

/* Big segmented funnel: each step a colour-segmented bar, widths tapering */
.funnel2 { display: flex; flex-direction: column; gap: 22px; padding: 6px 0; }
.f2-step { width: 100%; }
.f2-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-weight: 700; font-size: 14px; color: var(--ink); margin-bottom: 6px;
}
.f2-head span:last-child { color: var(--ink-mid); font-weight: 600; font-variant-numeric: tabular-nums; }
.f2-bar {
  display: flex; height: 38px; border-radius: 9px; overflow: hidden;
  box-shadow: var(--shadow-sm); transition: width 200ms ease;
}
.f2-seg {
  display: flex; align-items: center; justify-content: center; min-width: 0;
  color: #fff; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
  border-right: 1px solid rgba(255,255,255,.6);
}
.f2-seg:last-child { border-right: 0; }
.f2-legend { display: flex; flex-wrap: wrap; gap: 7px 16px; margin-top: 9px; }
.f2-leg { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-mid); }
.f2-dot { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto; }

/* Category select in the Kategoryzacja queue */
.cat-select {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); font-family: var(--font); font-size: 12.5px;
  color: var(--ink); max-width: 180px;
}
.cat-select:focus { border-color: var(--accent); outline: none; }

/* ===== Mobile / narrow viewport ===== */
@media (max-width: 900px) {
  /* Topbar: brand left, freshness + avatar + hamburger right */
  .topbar {
    flex-wrap: wrap; gap: 10px 8px; padding: 10px 16px;
    position: relative;
  }
  .brand { order: 0; flex: 1 1 auto; min-width: 0; }
  .user { order: 1; gap: 8px; margin-left: auto; }
  .user .email { display: none; }
  .user .logout { display: none; }  /* sign-out moves into hamburger menu */
  .hamburger { display: inline-flex; order: 2; }

  /* Hamburger dropdown contains tabs + sign-out */
  .tabs {
    order: 99; width: 100%; margin-left: 0;
    flex-direction: column; gap: 2px;
    background: var(--surface); border-top: 1px solid var(--line);
    margin: 8px -16px -10px; padding: 8px 16px 12px;
    display: none;
  }
  .tabs.is-open { display: flex; }
  .tab { padding: 12px 14px; font-size: 14px; border-radius: 8px; }
  .tab-signout {
    display: block; margin-top: 8px; padding-top: 14px;
    border-top: 1px solid var(--line); color: var(--bad); font-weight: 600;
  }
  .tab-signout:hover { background: #fee2e2; }

  /* Range bar: stack into clean rows on mobile.
     Row 1: From + To dates (50/50). Row 2: quick chips. Row 3: Apply (full width). */
  .range {
    padding: 12px 16px 8px;
    gap: 8px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "from to"
      "quick quick"
      "apply apply";
    align-items: center;
  }
  .range > label:nth-of-type(1) { grid-area: from; }
  .range > label:nth-of-type(2) { grid-area: to; }
  .range > #applyRange { grid-area: apply; width: 100%; }
  .range > #quickRange { grid-area: quick; }
  .range-sep, .range-label { display: none; }
  .range label {
    font-size: 10.5px;
    flex-direction: column; align-items: stretch; gap: 4px;
    text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 500;
  }
  .range input[type="date"] {
    width: 100%; padding: 9px 10px; font-size: 14px;
  }
  #quickRange {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    width: 100%;
    background: var(--surface-alt);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 3px;
  }
  #quickRange .seg-btn { padding: 8px 4px; font-size: 12px; }

  /* Main padding tighter */
  main { padding: 4px 16px 48px; }

  /* KPI cards: 2 per row on phones */
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi .value { font-size: 18px; }
  .kpi .label { font-size: 10px; }

  /* Two-col layout always 1 col on phone */
  .two-col { grid-template-columns: 1fr; gap: 12px; }

  /* Subtabs: horizontal scroll */
  .subtabs {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap; scrollbar-width: none;
  }
  .subtabs::-webkit-scrollbar { display: none; }
  .subtab { flex: 0 0 auto; }

  /* Card paddings */
  .card { padding: 14px 14px; }
  .card h2 { font-size: 14px; }

  /* Freshness badge in topbar: smaller on phone */
  .freshness-badge { font-size: 10.5px; padding: 3px 8px; }
}

@media (max-width: 480px) {
  /* Even tighter for small phones */
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi .value { font-size: 17px; }
  .freshness-badge { display: none; }     /* save space; tooltip irrelevant on phone */
  main { padding: 4px 12px 40px; }
  .range { padding: 10px 12px 4px; }
}
