:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-alt: #eef3ef;
  --border: #dde5e0;
  --text: #1c2b22;
  --text-muted: #5b6b60;
  --accent: #2f8f5b;
  --accent-contrast: #ffffff;
  --danger: #c0562f;
  --new: #2f7fbf;
  --shadow: 0 1px 3px rgba(20, 40, 30, 0.08), 0 1px 2px rgba(20, 40, 30, 0.06);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131a15;
    --surface: #1c2620;
    --surface-alt: #232f28;
    --border: #33413a;
    --text: #e7f0ea;
    --text-muted: #9fb2a8;
    --accent: #4bbf82;
    --accent-contrast: #0c150f;
    --danger: #e08a5c;
    --new: #6fb3e8;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="light"] {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-alt: #eef3ef;
  --border: #dde5e0;
  --text: #1c2b22;
  --text-muted: #5b6b60;
  --accent: #2f8f5b;
  --accent-contrast: #ffffff;
  --danger: #c0562f;
  --new: #2f7fbf;
}

:root[data-theme="dark"] {
  --bg: #131a15;
  --surface: #1c2620;
  --surface-alt: #232f28;
  --border: #33413a;
  --text: #e7f0ea;
  --text-muted: #9fb2a8;
  --accent: #4bbf82;
  --accent-contrast: #0c150f;
  --danger: #e08a5c;
  --new: #6fb3e8;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-right: auto;
}

.brand-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.brand h1 {
  font-size: 1.25rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  align-items: center;
  width: 100%;
}

.status-line {
  width: 100%;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem;
}

.date-nav input[type="date"] {
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  padding: 0.25rem 0.4rem;
  font-family: inherit;
}

.icon-btn, .text-btn, .toggle-btn {
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.9rem;
  font-family: inherit;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn {
  padding: 0.35rem 0.6rem;
  font-weight: 600;
}

.icon-btn:hover, .text-btn:hover {
  background: var(--border);
}

.toggle-btn.active {
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}

.toggle-btn:not(.active):hover {
  background: var(--border);
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  padding: 0.55rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.tab .count {
  font-weight: 400;
  opacity: 0.8;
  font-size: 0.85em;
}

.toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

#searchBox {
  flex: 1 1 240px;
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

#sortSelect {
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.9rem;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  display: flex;
  gap: 0.75rem;
  box-shadow: var(--shadow);
}

.card.inactive {
  opacity: 0.55;
}

.card-icon {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.card-icon img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-name {
  margin: 0 0 0.15rem;
  font-size: 1rem;
  font-weight: 700;
  overflow-wrap: break-word;
}

.card-body p {
  margin: 0.1rem 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.card-price {
  color: var(--text) !important;
  font-weight: 600;
}

.card-badges {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  align-items: flex-end;
}

.badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  color: #fff;
}

.badge-new {
  background: var(--new);
}

.badge-leaving {
  background: var(--danger);
}

.badge-now {
  background: var(--accent);
}

footer {
  max-width: 1200px;
  margin: 1rem auto 2.5rem;
  padding: 0 1.25rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

@media (max-width: 640px) {
  .controls {
    flex-direction: column;
    align-items: stretch;
  }
  .control-group {
    justify-content: center;
  }
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
}

@media (max-width: 480px) {
  main {
    padding: 0.75rem;
  }
  .toolbar {
    margin-bottom: 0.75rem;
  }
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }
  .card {
    flex-direction: column;
    padding: 0.55rem;
    gap: 0.3rem;
  }
  .card-icon {
    width: 36px;
    height: 36px;
  }
  .card-name {
    font-size: 0.82rem;
  }
  .card-body p {
    font-size: 0.68rem;
    margin: 0.05rem 0;
  }
  .card-badges {
    top: 0.4rem;
    right: 0.4rem;
  }
  .badge {
    font-size: 0.55rem;
    padding: 0.1rem 0.35rem;
  }
}
