:root {
  --bg: #eef4ff;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --line: #d3dff1;
  --text: #102039;
  --muted: #5f6f89;
  --blue: #2b6ef3;
  --blue-strong: #124cbf;
  --orange: #f97316;
  --green: #16a34a;
  --purple: #7c3aed;
  --shadow: 0 10px 28px rgba(16, 40, 94, 0.12);
  --login-wave-1: rgba(14, 42, 102, 0.72);
  --login-wave-2: rgba(18, 58, 138, 0.58);
  --login-wave-3: rgba(22, 84, 192, 0.48);
  --login-wave-4: #2b6ef3;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top left, #f4f8ff 0%, #e9f1ff 45%, #e3ecfb 100%);
}

.app-shell {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.app-shell-hidden {
  display: none;
}

.login-view {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 2rem;
  background: radial-gradient(circle at 16% 18%, rgba(22, 84, 192, 0.08), transparent 24%),
    radial-gradient(circle at 84% 14%, rgba(43, 110, 243, 0.08), transparent 22%),
    linear-gradient(180deg, #ffffff 0%, #f8fbff 38%, #eef5ff 72%, #e7f0ff 100%);
}

.login-view.active {
  display: flex;
}

.login-scene {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.waves {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 15vh;
  margin-bottom: -7px;
  min-height: 90px;
  max-height: 150px;
}

.parallax > use {
  animation: move-forever 25s cubic-bezier(.55, .5, .45, .5) infinite;
}

.parallax > use:nth-child(1) {
  animation-delay: -2s;
  animation-duration: 7s;
}

.parallax > use:nth-child(2) {
  animation-delay: -3s;
  animation-duration: 10s;
}

.parallax > use:nth-child(3) {
  animation-delay: -4s;
  animation-duration: 13s;
}

.parallax > use:nth-child(4) {
  animation-delay: -5s;
  animation-duration: 20s;
}

@keyframes move-forever {
  0% { transform: translate3d(-90px, 0, 0); }
  100% { transform: translate3d(85px, 0, 0); }
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  background: #ffffff;
  border: 1px solid #c9d7ef;
  border-radius: 16px;
  box-shadow: 0 20px 48px rgba(15, 30, 66, 0.18);
  padding: 2rem;
}

.login-card button {
  width: 100%;
}

.login-logo {
  width: min(200px, 100%);
  margin: 0 auto 1.2rem;
  display: block;
}

.error-msg {
  color: #b91c1c;
  background: #fee2e2;
  border: 1px solid #fecaca;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  font-size: 0.9rem;
}

.sidebar {
  background: linear-gradient(180deg, #0f2e6a 0%, #123c85 100%);
  color: #f2f6ff;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-right: 1px solid rgba(255, 255, 255, 0.12);
}

.brand {
  display: grid;
  gap: 8px;
  align-items: start;
  padding: 8px;
}

.brand-logo {
  width: 140px;
  height: auto;
  display: block;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.22));
}

.brand h1 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.brand p {
  margin: 3px 0 0;
  color: #c8d8f9;
  font-size: 0.8rem;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  background: transparent;
  color: #d9e7ff;
  border: 1px solid transparent;
  border-radius: 10px;
  text-align: left;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
  transition: all 130ms ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.09);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(79, 140, 255, 0.35), rgba(79, 140, 255, 0.22));
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.sidebar-foot {
  margin-top: auto;
  color: #d5e2fb;
  font-size: 0.82rem;
  padding: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.main {
  padding: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 14px;
  gap: 12px;
}

.topbar h2 {
  margin: 0;
  font-size: 1.6rem;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.topbar-user {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.user-chip {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid #cad9f3;
  background: #f2f7ff;
  color: #24406f;
  font-size: 0.8rem;
  white-space: nowrap;
}

.view {
  display: none;
  gap: 14px;
}

.view.active {
  display: grid;
  animation: view-fade 250ms ease-out;
}

@keyframes view-fade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.hero-card {
  background: linear-gradient(135deg, #f7faff 0%, #eef4ff 100%);
}

h3 {
  margin: 0 0 8px;
}

p {
  margin: 0;
}

.muted {
  color: var(--muted);
}

form {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 10px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.full {
  grid-column: 1 / -1;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  background: var(--surface-soft);
  border: 1px solid #ccd9f1;
  color: var(--text);
  border-radius: 9px;
  padding: 8px 10px;
}

textarea {
  resize: vertical;
}

button {
  border: 1px solid #c5d5f2;
  border-radius: 9px;
  background: #edf4ff;
  color: #17315c;
  padding: 8px 12px;
  cursor: pointer;
}

button.primary {
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-strong) 100%);
  border-color: #2a62d4;
  color: #ffffff;
}

button.small {
  padding: 4px 8px;
  font-size: 0.78rem;
}

button.icon-btn {
  width: 38px;
  height: 34px;
  min-width: 38px;
  min-height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button.icon-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.row-actions {
  display: inline-flex;
  gap: 6px;
}

button.danger {
  background: #fee2e2;
  border-color: #fecaca;
  color: #991b1b;
}

button:hover {
  filter: brightness(1.03);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: none;
}

.inline {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th, td {
  border-bottom: 1px solid #d8e1f2;
  text-align: left;
  padding: 8px 6px;
  font-size: 0.9rem;
  vertical-align: top;
}

td[contenteditable="true"] {
  min-width: 110px;
  outline: none;
  cursor: text;
  background: #f9fcff;
  white-space: pre-line;
  line-height: 1.35;
}

td.manual-override {
  position: relative;
  border-right: 1px solid #d1e0f8;
  padding-right: 22px;
}

td.manual-override::after {
  content: "M";
  position: absolute;
  top: 3px;
  right: 4px;
  min-width: 14px;
  height: 14px;
  line-height: 14px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: #1d4cb0;
  border: 1px solid #9ab8ea;
  border-radius: 999px;
  background: #e7f0ff;
  pointer-events: none;
}

#productTable td {
  white-space: pre-line;
}

#view-products .table-wrap-products {
  max-height: calc(100vh - 300px);
  overflow-y: auto;
}

#productTable thead th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: #f2f7ff;
}

#productTable th:nth-child(11),
#productTable td:nth-child(11) {
  min-width: 280px;
}

.price-link-cell a {
  font-weight: 600;
  text-decoration: underline;
}

td[contenteditable="true"]:focus {
  box-shadow: inset 0 0 0 2px #60a5fa;
  background: #eff6ff;
}

td.saving {
  opacity: 0.7;
  background: #e0f2fe;
}

th {
  background: #f2f7ff;
  color: #3a4e74;
}

a {
  color: #1d4cb0;
}

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

.running-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.running-clock {
  width: 12px;
  height: 12px;
  border: 1.8px solid currentColor;
  border-radius: 50%;
  position: relative;
  display: inline-block;
}

.running-clock::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 2px;
  width: 1.4px;
  height: 4px;
  border-radius: 1px;
  background: currentColor;
  transform-origin: bottom center;
  animation: clock-minute 1.1s linear infinite;
}

.running-clock::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 5px;
  width: 3px;
  height: 1.4px;
  border-radius: 1px;
  background: currentColor;
  transform-origin: left center;
  animation: clock-hour 6s linear infinite;
}

@keyframes clock-minute {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes clock-hour {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.status-running {
  background: rgba(43, 110, 243, 0.14);
  color: #1f4da8;
}

.status-completed {
  background: rgba(22, 163, 74, 0.15);
  color: #166534;
}

.status-completed_with_errors {
  background: rgba(249, 115, 22, 0.16);
  color: #9a3412;
}

.status-failed {
  background: rgba(239, 68, 68, 0.15);
  color: #b91c1c;
}

.metrics,
.report-kpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  background: #f7faff;
  border: 1px solid #d6e1f2;
  border-radius: 11px;
  padding: 12px;
  box-shadow: 0 6px 16px rgba(16, 40, 94, 0.08);
}

.metric strong {
  display: block;
  font-size: 1.45rem;
  color: #12305f;
}

.metric .metric-label {
  color: #6a7f9e;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.metric .metric-note {
  color: #607189;
  font-size: 0.8rem;
  margin-top: 2px;
}

.metric span {
  color: var(--muted);
  font-size: 0.82rem;
}

.metric.up strong { color: var(--orange); }
.metric.down strong { color: #0284c7; }
.metric.stable strong { color: #64748b; }
.metric.new strong { color: var(--green); }
.metric.removed strong { color: var(--purple); }

.metric.primary {
  background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%);
  border-color: #2b5fd2;
}

.metric.primary strong,
.metric.primary .metric-label,
.metric.primary .metric-note {
  color: #f8fbff;
}

.report-grid-two {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
}

.chart-card-canvas {
  min-height: 320px;
  height: 320px;
}

canvas {
  width: 100%;
  display: block;
  border-radius: 10px;
  border: 1px solid #cdd9ee;
}

.chart-card-canvas canvas,
.trend-canvas-wrap canvas {
  width: 100% !important;
  height: 100% !important;
  border: none;
  background: transparent;
}

.gauge-wrap {
  display: grid;
  place-items: center;
  grid-template-rows: 1fr auto;
}

.freshness-meta {
  margin-top: 8px;
  color: #5f728e;
  font-size: 0.85rem;
  text-align: center;
}

.risk-pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.risk-pill.high {
  background: #fee2e2;
  color: #b91c1c;
}

.risk-pill.medium {
  background: #fef3c7;
  color: #a16207;
}

.risk-pill.low {
  background: #dcfce7;
  color: #166534;
}

.gap-negative {
  color: #b91c1c;
  font-weight: 700;
}

.gap-positive {
  color: #166534;
  font-weight: 700;
}

.delta-up td { background: rgba(249, 115, 22, 0.08); }
.delta-down td { background: rgba(14, 165, 233, 0.08); }
.delta-new td { background: rgba(22, 163, 74, 0.08); }
.delta-removed td { background: rgba(124, 58, 237, 0.08); }

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

.tab-item {
  border-radius: 9px;
  background: #eef4ff;
  border: 1px solid #cad9f3;
}

.tab-item.active {
  background: linear-gradient(135deg, #2b6ef3 0%, #1e55bf 100%);
  color: #fff;
  border-color: #2b62d1;
}

.admin-tab {
  display: none;
  gap: 14px;
}

.admin-tab.active {
  display: grid;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: end;
}

.product-actions-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.menu-dropdown {
  position: relative;
}

.menu-dropdown > summary {
  list-style: none;
  border: 1px solid #c5d5f2;
  border-radius: 9px;
  background: #edf4ff;
  color: #17315c;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
}

.menu-dropdown > summary::-webkit-details-marker {
  display: none;
}

.menu-dropdown-list {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 180px;
  z-index: 10;
  background: #ffffff;
  border: 1px solid #d3def0;
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.16);
  padding: 6px;
}

.menu-dropdown[open] .menu-dropdown-list {
  display: grid;
  gap: 6px;
}

.menu-dropdown-list button {
  width: 100%;
  text-align: left;
}

.menu-group-label {
  padding: 4px 6px 2px;
  font-size: 0.74rem;
  color: #6b7d9c;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#sourceOauthAdvanced {
  border: 1px solid #d7e2f3;
  border-radius: 10px;
  padding: 8px 10px;
  background: #f8fbff;
}

.oauth-advanced-hidden {
  display: none !important;
}

#sourceOauthAdvanced > summary {
  cursor: pointer;
  font-weight: 600;
  color: #2d4773;
}

#sourceOauthAdvanced .grid {
  margin-top: 8px;
}

.product-filter-summary {
  margin: 8px 0 10px;
  padding: 8px 10px;
  border: 1px solid #d7e2f3;
  border-radius: 9px;
  background: #f8fbff;
  color: #41557d;
  font-size: 0.88rem;
}

.report-competitors {
  min-height: 150px;
  max-height: 220px;
  overflow: auto;
  border: 1px solid #d7e2f3;
  border-radius: 10px;
  background: #f8fbff;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.report-competitor-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.86rem;
  color: #284066;
}

.report-competitor-item input[type="checkbox"] {
  accent-color: #1d4ed8;
}

.trend-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 4px 0 10px;
}

.trend-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: #2e456d;
  background: #f5f9ff;
  border: 1px solid #d6e2f6;
  border-radius: 999px;
  padding: 4px 10px;
}

.trend-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.trend-canvas-wrap {
  min-height: 360px;
  height: 360px;
}

.log-toolbar {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(280px, 1fr) auto;
  align-items: end;
  margin-bottom: 10px;
}

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

.log-toolbar-actions .inline {
  display: inline-grid;
  white-space: nowrap;
}

.log-output {
  margin: 10px 0 0;
  padding: 12px;
  min-height: 340px;
  max-height: 62vh;
  overflow: auto;
  border: 1px solid #d7e2f3;
  border-radius: 10px;
  background: #0b1220;
  color: #d6e2ff;
  font-size: 0.82rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Cascadia Mono", "Consolas", "Menlo", monospace;
}

dialog.modal {
  border: none;
  border-radius: 14px;
  padding: 0;
  width: min(680px, calc(100vw - 24px));
  background: transparent;
}

#productFiltersModal {
  width: min(980px, calc(100vw - 24px));
}

dialog.modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.modal-body {
  margin: 0;
  display: grid;
  gap: 10px;
  padding: 14px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #0f766e;
  color: #fff;
  padding: 10px 12px;
  border-radius: 9px;
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.3);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: all 150ms ease;
}

.toast.error {
  background: #b91c1c;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1220px) {
  .metrics,
  .report-kpis {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .report-grid-two {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px;
  }
  .nav {
    display: flex;
    margin-left: auto;
  }
  .sidebar-foot {
    display: none;
  }
  .grid.three {
    grid-template-columns: 1fr 1fr;
  }
  .report-kpis {
    grid-template-columns: 1fr 1fr;
  }
  .log-toolbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .grid.two,
  .grid.three {
    grid-template-columns: 1fr;
  }
  .metrics,
  .report-kpis {
    grid-template-columns: 1fr 1fr;
  }
}
