:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --panel-strong: #f0f4f2;
  --sidebar-bg: #eef2f0;
  --tabs-bg: #e5ece8;
  --table-head-bg: #f8faf9;
  --row-hover: #eef5f1;
  --notification-bg: #fffaf0;
  --danger-bg: #fff0f0;
  --focus: rgba(37, 111, 90, 0.22);
  --text: #17211d;
  --muted: #66726d;
  --line: #dbe2de;
  --accent: #256f5a;
  --accent-strong: #154d3e;
  --blue: #2c5f9e;
  --red: #a63f3f;
  --green: #27764c;
  --amber: #9b6b17;
  --shadow: 0 8px 24px rgba(23, 33, 29, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1513;
  --panel: #141f1b;
  --panel-strong: #101a17;
  --sidebar-bg: #101a17;
  --tabs-bg: #0d1714;
  --table-head-bg: #16231f;
  --row-hover: #1b2d27;
  --notification-bg: #2a2313;
  --danger-bg: #2b1818;
  --focus: rgba(83, 186, 154, 0.28);
  --text: #e8f0ed;
  --muted: #9eb0aa;
  --line: #263832;
  --accent: #4fb891;
  --accent-strong: #75d4b0;
  --blue: #8ab8f0;
  --red: #ff9b9b;
  --green: #7dd8a6;
  --amber: #eac16c;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 72px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}


.theme-toggle-icon {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font-size: 18px;
  box-shadow: var(--shadow);
}

.theme-toggle-icon:hover {
  background: var(--row-hover);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  padding: 18px 12px 18px 18px;
  border-right: 1px solid var(--line);
  background: var(--sidebar-bg);
  overflow: auto;
}

.sidebar-title {
  padding: 0 8px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
}

.day-list {
  display: grid;
  gap: 8px;
}

.day-item {
  width: 100%;
  min-height: 74px;
  padding: 12px;
  display: grid;
  gap: 6px;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
}

.day-item:hover,
.day-item.active {
  background: var(--panel);
  border-color: var(--line);
  box-shadow: var(--shadow);
}

.day-date {
  font-weight: 700;
  line-height: 1.25;
}

.day-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.content {
  min-width: 0;
  padding: 20px;
  overflow: auto;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  min-height: 76px;
  padding: 14px;
  display: grid;
  align-content: space-between;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

.metric strong {
  font-size: 20px;
  line-height: 1.2;
}

.toolbar {
  margin-bottom: 14px;
  display: grid;
  align-items: flex-start;
  gap: 12px;
}

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  background: var(--tabs-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tab {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.tab.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.filters {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: flex-end;
  gap: 10px;
}

.filters .search-input {
  width: 100%;
  min-width: 0;
}

input,
select {
  min-height: 38px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
}

input:focus,
select:focus {
  outline: 2px solid var(--focus);
  border-color: var(--accent);
}

.filter-field {
  grid-column: span 2;
  min-width: 0;
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.filter-field.compact {
  grid-column: span 2;
}

.filter-field.search-field {
  grid-column: span 4;
}

.filter-field input,
.filter-field select {
  width: 100%;
}

.toggle {
  grid-column: span 2;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.filters > .button {
  grid-column: span 2;
  width: 100%;
}

.split-view {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
}

.table-wrap,
.details,
.notifications {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.table-wrap {
  overflow: auto;
}

.table-wrap.full {
  width: 100%;
}

.data-table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--table-head-bg);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.data-table tbody tr {
  transition: background 120ms ease;
}

.data-table tbody tr:hover,
.data-table tbody tr.selected {
  background: var(--row-hover);
}

.title-cell {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 260px;
  max-width: 440px;
  line-height: 1.35;
}

.pill,
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--row-hover);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.hot {
  background: var(--notification-bg);
  color: var(--amber);
}

.button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.button:hover {
  background: var(--accent-strong);
}

.button:disabled {
  cursor: default;
  opacity: 0.65;
}

.button.ghost {
  background: var(--panel);
  color: var(--accent);
}

.button.ghost:hover {
  background: var(--row-hover);
}

.button.ghost.danger {
  color: var(--red);
}

.button.ghost.danger:hover {
  background: var(--danger-bg);
}

.details {
  padding: 18px;
  position: sticky;
  top: 20px;
}

.details-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.details h2 {
  margin: 0 0 12px;
  font-size: 18px;
  line-height: 1.35;
}

.details-price {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.details-price strong {
  font-size: 24px;
}

.details-list {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 9px 12px;
  margin: 16px 0 0;
}

.details-list dt {
  color: var(--muted);
  font-size: 13px;
}

.details-list dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.chart {
  min-height: 186px;
  padding: 10px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.chart svg {
  display: block;
  width: 100%;
  height: 150px;
}

.axis {
  stroke: var(--line);
  stroke-width: 1;
}

.price-path {
  fill: none;
  stroke: var(--blue);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.price-point {
  fill: var(--panel);
  stroke: var(--blue);
  stroke-width: 2;
}

.chart-range {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.empty-chart {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.delta {
  font-weight: 800;
  white-space: nowrap;
}

.delta.up {
  color: var(--red);
}

.delta.down {
  color: var(--green);
}

.delta.neutral,
.muted {
  color: var(--muted);
}

.notifications {
  display: grid;
  gap: 0;
  overflow: hidden;
}

.notification-bar,
.notification {
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.notification-bar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.notification-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.notification {
  background: var(--notification-bg);
}

.notification.read {
  background: var(--panel);
}

.notification-main {
  min-width: 0;
  display: grid;
  gap: 4px;
  cursor: pointer;
}

.notification-main strong,
.notification-main span {
  overflow-wrap: anywhere;
}

.notification-main span {
  color: var(--muted);
  font-size: 13px;
}

.notice,
.empty-state {
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.notice.error {
  margin-bottom: 14px;
  border-color: #e5b9b9;
  background: var(--danger-bg);
  color: var(--red);
}

.empty-state.compact {
  margin: 14px;
  box-shadow: none;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .summary-grid {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

  .split-view {
    grid-template-columns: 1fr;
  }

  .details {
    position: static;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
    gap: 12px;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }


  .topbar-actions .button {
    flex: 1 1 140px;
  }

  .theme-toggle-icon {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    max-height: none;
    padding: 12px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: hidden;
  }

  .sidebar-title {
    padding: 0 0 8px;
  }

  .day-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scroll-snap-type: x mandatory;
  }

  .day-item {
    flex: 0 0 min(78vw, 260px);
    min-height: 66px;
    scroll-snap-align: start;
  }

  .content {
    padding: 14px;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric {
    min-height: 68px;
    padding: 12px;
  }

  .metric strong {
    font-size: 18px;
    overflow-wrap: anywhere;
  }

  .toolbar {
    align-items: stretch;
  }

  .filters {
    grid-template-columns: 1fr;
    gap: 9px;
  }

  input,
  select,
  .button {
    min-height: 44px;
  }

  input,
  select {
    font-size: 16px;
  }

  .tabs {
    display: grid;
    grid-template-columns: minmax(64px, 0.62fr) minmax(92px, 0.88fr) minmax(176px, 1.75fr);
    width: 100%;
    overflow-x: auto;
  }

  .tab {
    min-height: 42px;
    padding: 0 8px;
    line-height: 1.15;
    white-space: nowrap;
  }

  .filters .search-input,
  .filter-field,
  .filter-field.compact,
  .filters > .button,
  .toggle,
  .filters input[type="text"],
  .filters input:not([type]) {
    grid-column: 1 / -1;
    width: 100%;
  }

  .toggle {
    min-height: 44px;
    padding: 0 2px;
  }

  .table-wrap {
    overflow: visible;
  }

  .data-table {
    display: block;
    min-width: 0;
  }

  .data-table thead {
    display: none;
  }

  .data-table tbody {
    display: grid;
    gap: 10px;
    padding: 10px;
  }

  .data-table tr {
    display: grid;
    gap: 8px;
    padding: 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .data-table tbody tr:hover,
  .data-table tbody tr.selected {
    background: var(--row-hover);
    border-color: var(--accent);
  }

  .data-table td {
    display: grid;
    grid-template-columns: minmax(82px, 34%) minmax(0, 1fr);
    gap: 8px;
    padding: 0;
    border-bottom: 0;
    font-size: 13px;
    line-height: 1.35;
  }

  .data-table td::before {
    color: var(--muted);
    content: "";
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
  }

  .data-table td:first-child {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .offers-table td:nth-child(1)::before,
  .changes-table td:nth-child(1)::before {
    content: "Oferta";
  }

  .offers-table td:nth-child(2)::before {
    content: "Cena";
  }

  .offers-table td:nth-child(3)::before,
  .changes-table td:nth-child(5)::before {
    content: "Zmiana";
  }

  .offers-table td:nth-child(4)::before,
  .changes-table td:nth-child(2)::before {
    content: "Źródło";
  }

  .offers-table td:nth-child(5)::before {
    content: "Metraż";
  }

  .offers-table td:nth-child(6)::before {
    content: "Piętro";
  }

  .offers-table td:nth-child(7)::before {
    content: "Lokalizacja";
  }

  .offers-table td:nth-child(8)::before {
    content: "Sprzedający";
  }

  .changes-table td:nth-child(3)::before {
    content: "Poprzednio";
  }

  .changes-table td:nth-child(4)::before {
    content: "Teraz";
  }

  .changes-table td:nth-child(6)::before {
    content: "Data";
  }

  .title-cell {
    min-width: 0;
    max-width: none;
    overflow-wrap: anywhere;
  }

  .details {
    padding: 14px;
  }

  .details-header,
  .details-price {
    align-items: flex-start;
  }

  .details-header span,
  .details h2 {
    overflow-wrap: anywhere;
  }

  .details-list {
    grid-template-columns: 1fr;
  }

  .notification,
  .notification-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .notification-bar-actions {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .notification-actions {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 420px) {
  .topbar,
  .content {
    padding-left: 10px;
    padding-right: 10px;
  }

  .metric {
    padding: 10px;
  }

  .metric strong {
    font-size: 17px;
  }

  .tab {
    padding: 0 6px;
    font-size: 13px;
  }

  .details-price {
    flex-direction: column;
  }

  .notification-bar,
  .notification {
    padding: 12px;
  }
}

@media (max-width: 340px) {
  .tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow-x: visible;
  }

  .tab {
    min-height: 46px;
    padding: 0 4px;
    font-size: 12px;
    overflow-wrap: anywhere;
    white-space: normal;
  }
}
