@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
  color-scheme: light dark;
  --pw-store-icon: 40px;
  --pw-card-height-factor: 1;
  --pw-card-mobile-height-factor: 1;
  --pw-card-media-height: 160px;
}

.app-root {
  --bg: #282828;
  --surface: #3c3836;
  --surface-2: #504945;
  --text: #ebdbb2;
  --muted: #a89984;
  --accent: #fe8019;
  --danger: #fb4934;
  --success: #b8bb26;
  --warning: #fabd2f;
  --shadow: rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --font-title: "Space Mono", "JetBrains Mono", "Fira Code", monospace;
  --font-body: "JetBrains Mono", "Fira Code", "IBM Plex Mono", "SFMono-Regular", Menlo, monospace;
  --font-mono: "JetBrains Mono", "Fira Code", "IBM Plex Mono", "SFMono-Regular", Menlo, monospace;
  --font-size: 16px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: var(--font-size);
}

.app-root.theme-gruvbox-dark {
  --bg: #282828;
  --surface: #3c3836;
  --surface-2: #504945;
  --text: #ebdbb2;
  --muted: #a89984;
  --accent: #fe8019;
  --danger: #fb4934;
  --success: #b8bb26;
  --warning: #fabd2f;
  --shadow: rgba(0, 0, 0, 0.45);
}

.app-root.theme-gruvbox-light {
  --bg: #fbf1c7;
  --surface: #f2e5bc;
  --surface-2: #ebdbb2;
  --text: #3c3836;
  --muted: #7c6f64;
  --accent: #d65d0e;
  --danger: #cc241d;
  --success: #98971a;
  --warning: #d79921;
  --shadow: rgba(60, 56, 54, 0.25);
}

.app-root.theme-monokai-dark {
  --bg: #1f1f1b;
  --surface: #272822;
  --surface-2: #3b3c35;
  --text: #f8f8f2;
  --muted: #9b9a84;
  --accent: #f92672;
  --danger: #fd5ff1;
  --success: #a6e22e;
  --warning: #fd971f;
  --shadow: rgba(0, 0, 0, 0.55);
}

.app-root.theme-monokai-light {
  --bg: #f8f8f2;
  --surface: #e8e8e3;
  --surface-2: #dcdcd2;
  --text: #272822;
  --muted: #75715e;
  --accent: #f92672;
  --danger: #c0005f;
  --success: #2d8f2d;
  --warning: #fd971f;
  --shadow: rgba(39, 40, 34, 0.2);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: linear-gradient(90deg, var(--surface), var(--surface-2));
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 10px 24px var(--shadow);
}

.vintage-shadow {
  box-shadow: 0 14px 28px var(--shadow);
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease;
}

.icon-btn:hover {
  background: var(--accent);
  color: #1b1b1b;
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(1px);
}

.pill {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.75rem;
  background: var(--surface-2);
  color: var(--muted);
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 16px 32px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: calc(470px * var(--pw-card-height-factor, 1));
  padding: 24px;
  position: relative;
  padding-bottom: 90px;
}

.card-thumbnail {
  width: 100%;
  height: var(--pw-card-media-height, 160px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: var(--surface-2);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.card-media-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
}

.card-media-contain {
  object-fit: contain;
}

.card-media-cover {
  object-fit: cover;
}

.card-price-history {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-price-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
}

.history-panel {
  position: relative;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 12px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.chart-period-label {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: right;
}

.price-panel {
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
  min-width: 120px;
}

.price-main {
  font-size: clamp(24px, 2.2vw, 32px);
  font-weight: 700;
  text-align: right;
}

.price-msrp {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: right;
  text-decoration: line-through;
}

.price-discount {
  font-size: 0.85rem;
  text-align: right;
}

.stock-line {
  margin-top: 6px;
  text-transform: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.history-summary {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
}

@media (max-width: 900px) {
  .history-price-grid {
    grid-template-columns: 1fr;
  }
}

.history-trend {
  display: flex;
  gap: 6px;
  align-items: center;
}

.trend-pill {
  font-size: 0.85rem;
  font-weight: 600;
}

.trend-delta {
  font-size: 0.75rem;
  font-family: var(--font-mono);
}

.card-update {
  font-size: 0.72rem;
  color: rgba(235, 219, 178, 0.7);
}

.card-media {
  width: 100%;
  height: var(--pw-card-media-height, 160px);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--surface-2);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-media-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.card-identity {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.store-icon {
  width: var(--pw-store-icon);
  height: var(--pw-store-icon);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 2px;
}

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

.card-identity-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-chip {
  border-radius: 999px;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.filter-chip:hover {
  border-color: var(--accent);
}

.card-hover {
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-toolbar {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-toolbar .primary-action {
  width: 36px;
  height: 36px;
  pointer-events: auto;
}

.secondary-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.group:hover .secondary-actions,
.group:focus-within .secondary-actions {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.card-hover:hover,
.card-hover:focus-within {
  transform: translateY(-2px);
  box-shadow: 0 18px 32px var(--shadow);
}

.card-delta {
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

.status-pill[data-placeholder] {
  text-transform: none;
}

.status-pill.pill {
  text-transform: none;
}

.card-accent {
  border: 1px solid rgba(254, 128, 25, 0.5);
  box-shadow: 0 10px 30px rgba(254, 128, 25, 0.2);
}

.density-dense .card {
  padding: 12px;
}

.density-comfort .card {
  padding: 20px;
}

.section-title {
  font-family: var(--font-title);
  letter-spacing: 0.5px;
}

.label {
  font-size: 0.8rem;
  color: var(--muted);
}

.detail-dialog {
  max-height: 90vh;
  border-radius: 24px;
}

.detail-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.detail-title {
  font-weight: 600;
  display: inline-block;
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-content-area {
  padding: 24px;
  overflow-y: auto;
}

.detail-columns {
  min-height: 0;
}

.detail-card {
  background: var(--surface-1);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  min-height: 0;
}

.detail-summary-image {
  width: 100%;
  height: 220px;
}

.detail-summary-image img {
  width: 100%;
  height: 100%;
}

.detail-tabs {
  display: flex;
  gap: 8px;
}

.detail-tab-button {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 6px 14px;
  background: transparent;
  color: inherit;
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.detail-tab-button:hover {
  border-color: rgba(255, 255, 255, 0.16);
  transform: translateY(-1px);
}

.detail-tab-button.active {
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
}

.detail-tab-panel {
  margin-top: 4px;
}

.detail-text {
  white-space: pre-wrap;
  line-height: 1.4;
}

.detail-empty {
  font-style: italic;
  opacity: 0.75;
}

.detail-history-periods {
  margin-bottom: 4px;
}

.detail-period-button {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 4px 12px;
  background: transparent;
  font-size: 0.7rem;
  cursor: pointer;
  transition: box-shadow 0.2s ease;
}

.detail-period-button.selected {
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.25);
  border-color: rgba(255, 255, 255, 0.45);
}

.detail-history-summary .section-title {
  font-size: 0.85rem;
}

.detail-price-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-price-value {
  font-size: clamp(28px, 2.8vw, 34px);
  font-weight: 700;
}

.detail-price-updated {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
}

.detail-specs span {
  font-weight: 600;
}

.detail-card.edit-card .actions-section {
  justify-content: flex-start;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-actions .icon-btn {
  width: 32px;
  height: 32px;
}

.add-product-btn {
  width: 50px;
  height: 50px;
  box-shadow: 0 16px 32px var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.add-product-btn:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 20px 36px var(--shadow);
}

.header-actions .icon-btn .fa-solid {
  font-size: 0.95rem;
}

.input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--text);
}

.input:focus {
  outline: 2px solid rgba(254, 128, 25, 0.4);
}

.sidebar {
  width: 280px;
  min-width: 240px;
}

.detail-panel {
  width: 320px;
  min-width: 280px;
}

.image-toggle {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 2px;
  background: transparent;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border 0.15s ease;
}

.image-toggle:hover {
  border-color: rgba(254, 128, 25, 0.8);
  transform: translateY(-1px);
}

.image-toggle.selected {
  background: rgba(254, 128, 25, 0.15);
  border-color: rgba(254, 128, 25, 0.9);
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
}

.log-status-panel {
  border-color: rgba(255, 255, 255, 0.1);
}

.log-entry {
  transition: background 0.2s ease;
}

.log-entry-error {
  border-color: rgba(251, 73, 52, 0.7);
  background: rgba(251, 73, 52, 0.07);
  color: var(--danger);
}

.detail-popup {
  border-radius: calc(var(--radius) * 1.2);
  border-width: 1px;
  max-height: calc(100vh - 60px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

.view-mode-btn.active-view {
  background: var(--accent);
  color: #1b1b1b;
}

.logs-panel {
  display: flex;
  flex-direction: column;
  max-height: min(80vh, 560px);
  gap: 0.75rem;
}

.logs-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow-y: auto;
  max-height: calc(80vh - 200px);
}

.logs-toolbar {
  margin-top: auto;
  justify-content: flex-end;
}

.scrape-log-bar {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  width: min(80%, 900px);
  max-height: 140px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 24px 40px rgba(0, 0, 0, 0.45);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 60;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.scrape-log-line {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  color: var(--text);
  white-space: nowrap;
}

.scrape-log-time {
  color: var(--muted);
  font-size: 0.75rem;
}

.scrape-log-icon {
  font-size: 0.85rem;
}

.scrape-log-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scrape-log-enter-active,
.scrape-log-leave-active {
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.scrape-log-enter-from,
.scrape-log-leave-to {
  opacity: 0;
  transform: translateY(12px);
}

.price-section .price-value {
  font-size: 2.1rem;
  font-weight: 700;
}

.source-section .link {
  color: var(--accent);
  text-decoration: underline;
}

.actions-section .icon-btn {
  background: var(--surface-2);
}

.app-root.layout-compact .sidebar,
.app-root.layout-compact .detail-panel {
  display: none;
}

.app-root.layout-compact .product-grid {
  grid-template-columns: 1fr;
}

.app-root.layout-wide .sidebar {
  width: 320px;
}

.app-root.layout-wide .detail-panel {
  width: 360px;
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 32px;
}

@media (max-width: 1024px) {
  .sidebar {
    display: none;
  }
  .detail-panel {
    display: none;
  }
}

@media (max-width: 640px) {
  .app-header .toolbar-text {
    display: none;
  }
  .icon-btn {
    width: 36px;
    height: 36px;
  }
  .product-grid {
    grid-template-columns: 1fr;
  }
  .card {
    min-height: calc(470px * var(--pw-card-mobile-height-factor, 1));
  }
}
.view-toggle-group {
  display: flex;
  gap: 4px;
}

.price-dominant {
  margin-top: -4px;
}

.price-dominant .price-value {
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 700;
  line-height: 1.1;
}

.price-dominant .price-value {
  font-size: clamp(20px, 2.4vw, 26px);
  font-weight: 700;
}

.mini-sparkline {
  margin-top: 8px;
  border-radius: 12px;
  padding: 6px;
  background: var(--surface-2);
  overflow: hidden;
}

.sparkline-polyline {
  stroke: var(--text);
  stroke-width: 1.3;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.mini-line-chart__point--last {
  r: 3;
}

.history-placeholder {
  font-size: 0.75rem;
  opacity: 0.6;
  text-align: center;
  padding-top: 10px;
}
.mini-line-chart-panel {
  height: 160px;
  overflow: hidden;
  position: relative;
  margin-top: 12px;
  width: 100%;
}

.mini-line-chart-wrapper {
  height: 100%;
}

.mini-line-chart-wrapper svg {
  display: block;
}

.price-history-popup {
  width: 280px;
  border-radius: 14px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35);
  background: var(--surface);
  color: var(--text);
  min-height: 120px;
  max-width: 320px;
}

.price-history-popup .sparkline {
  stroke: currentColor;
  stroke-width: 1.5;
}

.price-history-popup strong {
  font-weight: 700;
}

.price-history-chart {
  border-radius: 14px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
  background: var(--surface);
}

.price-history-chart .sparkline {
  stroke: var(--accent);
  stroke-width: 1.6;
}
