:root {
  color-scheme: light;
  --brand: #6c0019;
  --brand-contrast: #ffffff;
  --surface-1: #ffffff;
  --page-plane: #f6f6f6;
  --text-primary: #171717;
  --text-secondary: #55555a;
  --text-muted: #8f8f8f;
  --gridline: #e7e7e7;
  --border: rgba(23, 23, 23, 0.08);

  --series-shopify: #2a78d6;
  --series-keycrm: #eb6834;
  --series-meta: #1baf7a;
  --series-google-ads: #eda100;
  --series-ga4: #e87ba4;

  --status-good: #0ca30c;
  --status-critical: #d03b3b;
  --status-warning: #c98500;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand: #e2597a;
    --brand-contrast: #1a0509;
    --surface-1: #1c1c1c;
    --page-plane: #121212;
    --text-primary: #f5f5f5;
    --text-secondary: #c9c9c9;
    --text-muted: #8f8f8f;
    --gridline: #2c2c2c;
    --border: rgba(245, 245, 245, 0.1);

    --series-shopify: #3987e5;
    --series-keycrm: #d95926;
    --series-meta: #199e70;
    --series-google-ads: #c98500;
    --series-ga4: #d55181;

    --status-warning: #e0a736;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: #e2597a;
  --brand-contrast: #1a0509;
  --surface-1: #1c1c1c;
  --page-plane: #121212;
  --text-primary: #f5f5f5;
  --text-secondary: #c9c9c9;
  --text-muted: #8f8f8f;
  --gridline: #2c2c2c;
  --border: rgba(245, 245, 245, 0.1);

  --series-shopify: #3987e5;
  --series-keycrm: #d95926;
  --series-meta: #199e70;
  --series-google-ads: #c98500;
  --series-ga4: #d55181;

  --status-warning: #e0a736;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-card h1 {
  font-size: 1.1rem;
  margin: 0 0 16px;
}

.login-card label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 8px;
}

.login-card input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page-plane);
  color: var(--text-primary);
  font-size: 0.95rem;
}

.login-card button {
  margin-top: 16px;
  padding: 10px;
  border: none;
  border-radius: 999px;
  background: var(--brand);
  color: var(--brand-contrast);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
}

.login-error {
  color: var(--status-critical);
  font-size: 0.85rem;
  margin: 0;
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-logo {
  display: block;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.brand-logo {
  display: block;
  height: 28px;
  width: auto;
  color: var(--brand);
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

.login-logo .brand-logo {
  height: 34px;
}

.sidebar-nav {
  flex: 1;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-link {
  display: block;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
}

.sidebar-link:hover {
  background: var(--page-plane);
  color: var(--text-primary);
}

.sidebar-link.active {
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  color: var(--brand);
  font-weight: 600;
}

.sidebar-group {
  margin-top: 2px;
}

.sidebar-group-row {
  display: flex;
  align-items: center;
}

.sidebar-group-row .sidebar-link {
  flex: 1;
  min-width: 0;
}

.sidebar-toggle {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 8px;
}

.sidebar-toggle:hover {
  background: var(--page-plane);
  color: var(--text-primary);
}

.sidebar-toggle svg {
  width: 13px;
  height: 13px;
  transition: transform 0.15s;
}

.sidebar-toggle.is-open svg {
  transform: rotate(90deg);
}

.sidebar-sublist {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 1px 0 4px 20px;
  padding-left: 13px;
  border-left: 1px solid var(--gridline);
}

.sidebar-sublink {
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: none;
}

.sidebar-sublink:hover {
  background: var(--page-plane);
  color: var(--text-primary);
}

.sidebar-sublink.active {
  color: var(--brand);
  font-weight: 600;
  background: color-mix(in srgb, var(--brand) 8%, transparent);
}

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}

.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 18px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.page-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}

.range-label {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.logout-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
}

.page {
  max-width: 1080px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

@media (max-width: 800px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidebar-sublist {
    margin-left: 0;
    padding-left: 12px;
    flex-basis: 100%;
  }
}

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

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  padding: 16px;
}

a.stat-tile {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s;
}

a.stat-tile:hover {
  border-color: var(--brand);
}

.stat-label {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

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

.chart-card,
.sync-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  padding: 20px;
}

.chart-card h2,
.sync-card h2 {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin: 0 0 16px;
  font-weight: 600;
}

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

.card-header-row h2 {
  margin: 0;
}

.refresh-form {
  flex-shrink: 0;
}

.period-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.period-pill {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.period-pill:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.period-pill-active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-contrast);
}

.period-pill-active:hover {
  color: var(--brand-contrast);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
}

.pagination-link {
  color: var(--brand);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
}

.pagination-link:hover {
  text-decoration: underline;
}

.pagination-link-disabled {
  color: var(--text-muted);
  pointer-events: none;
}

.pagination-status {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.btn-refresh {
  padding: 6px 14px;
  border: none;
  border-radius: 999px;
  background: var(--brand);
  color: var(--brand-contrast);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.btn-refresh:hover {
  opacity: 0.88;
}

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: 96px 1fr 80px;
  align-items: center;
  gap: 12px;
}

.bar-name {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.bar-track {
  height: 14px;
  background: var(--gridline);
  border-radius: 7px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 7px;
  min-width: 2px;
}

.source-shopify { background: var(--series-shopify); }
.source-keycrm { background: var(--series-keycrm); }
.source-meta { background: var(--series-meta); }
.source-google_ads { background: var(--series-google-ads); }
.source-ga4 { background: var(--series-ga4); }

.bar-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.sync-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.sync-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  padding: 6px 8px;
  border-bottom: 1px solid var(--gridline);
}

.sync-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}

.sync-error {
  color: var(--text-muted);
  font-variant-numeric: normal;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
}

.status-ok {
  background: color-mix(in srgb, var(--status-good) 18%, transparent);
  color: var(--status-good);
}

.status-error {
  background: color-mix(in srgb, var(--status-critical) 18%, transparent);
  color: var(--status-critical);
}

.status-running {
  background: color-mix(in srgb, var(--text-muted) 18%, transparent);
  color: var(--text-muted);
}

.status-warning {
  background: color-mix(in srgb, var(--status-warning) 18%, transparent);
  color: var(--status-warning);
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.product-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.product-cell-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.product-cell-link:hover .product-title-text span:first-child {
  color: var(--brand);
  text-decoration: underline;
}

.link-title {
  color: inherit;
  text-decoration: none;
}

.link-title:hover {
  color: var(--brand);
  text-decoration: underline;
}

.product-thumb {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--page-plane);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.product-thumb-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--gridline);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  flex-shrink: 0;
}

.product-title-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.product-title-text .product-sku {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.link-brand {
  color: var(--brand);
  font-weight: 500;
  text-decoration: none;
}

.link-brand:hover {
  text-decoration: underline;
}

.info-dot {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--gridline);
  color: var(--text-secondary);
  font-size: 0.68rem;
  font-style: italic;
  font-weight: 700;
  font-family: Georgia, serif;
  cursor: help;
  margin-left: 6px;
  vertical-align: middle;
}

.info-tooltip {
  position: absolute;
  bottom: 130%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--surface-1);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 400;
  font-style: normal;
  font-family: "Onest", system-ui, sans-serif;
  width: 240px;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 20;
}

.info-dot:hover .info-tooltip,
.info-dot:focus .info-tooltip {
  opacity: 1;
}

.edit-form {
  display: flex;
  gap: 6px;
  align-items: center;
}

.edit-input {
  width: 90px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page-plane);
  color: var(--text-primary);
  font-size: 0.8rem;
}

.btn-save {
  padding: 5px 12px;
  border: none;
  border-radius: 999px;
  background: var(--brand);
  color: var(--brand-contrast);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.btn-shopify {
  padding: 5px 12px;
  border: none;
  border-radius: 999px;
  background: var(--brand);
  color: var(--brand-contrast);
  font-size: 0.75rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  display: inline-block;
}

.btn-shopify:hover {
  opacity: 0.88;
}

.actions-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.edit-banner {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
}

.edit-banner-error {
  background: color-mix(in srgb, var(--status-critical) 12%, transparent);
  color: var(--status-critical);
  border: 1px solid color-mix(in srgb, var(--status-critical) 35%, transparent);
}

.edit-banner-ok {
  background: color-mix(in srgb, var(--status-good) 12%, transparent);
  color: var(--status-good);
  border: 1px solid color-mix(in srgb, var(--status-good) 35%, transparent);
}

.btn-save:disabled {
  opacity: 0.5;
  cursor: default;
}

.page-notes {
  border: 1px dashed var(--border);
  border-radius: 16px;
  background: var(--surface-1);
  overflow: hidden;
}

.page-notes-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: left;
}

.page-notes-toggle:hover {
  color: var(--text-primary);
}

.page-notes-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  background: color-mix(in srgb, var(--status-warning) 18%, transparent);
  color: var(--status-warning);
}

.page-notes-chevron {
  margin-left: auto;
  color: var(--text-muted);
  transition: transform 0.15s;
}

.page-notes-toggle-open .page-notes-chevron {
  transform: rotate(90deg);
}

.page-notes-body {
  padding: 0 16px 16px;
}

.page-notes-input-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.page-notes-textarea {
  flex: 1;
  resize: vertical;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
}

.page-notes-shots {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.page-notes-shots:not(:empty) {
  margin-top: 8px;
}

.page-notes-shot {
  position: relative;
}

.page-notes-shot img {
  height: 64px;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
}

.page-notes-shot-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: var(--text-primary);
  color: var(--surface-1);
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
}

.page-notes-hint {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.page-notes-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.page-notes-list:not(:empty) {
  margin-top: 12px;
}

.page-notes-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--page-plane);
}

.page-notes-item-closed {
  opacity: 0.6;
}

.page-notes-item-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.page-notes-item-main {
  min-width: 0;
}

.page-notes-item-text {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-primary);
  white-space: pre-wrap;
}

.page-notes-item-meta {
  margin: 4px 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.page-notes-status-done {
  color: var(--status-good);
}

.page-notes-status-skip {
  color: var(--text-muted);
}

.page-notes-item-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.page-notes-item-image {
  height: 72px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.page-notes-item-reply {
  margin: 8px 0 0;
  padding-left: 8px;
  border-left: 2px solid color-mix(in srgb, var(--status-good) 50%, transparent);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.page-notes-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.page-notes-link {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--brand);
  padding: 0;
}

.page-notes-link-muted {
  color: var(--text-muted);
  font-weight: 500;
}

.page-notes-link-danger {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 400;
}

.page-notes-link-danger:hover {
  color: var(--status-critical);
}

.theme-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 50;
}

.theme-toggle:hover {
  border-color: var(--text-muted);
}
