:root {
  color-scheme: light;
  font-family: "Aptos", "Segoe UI Variable", "Segoe UI", sans-serif;
  --bg-base: #eef4fb;
  --bg-wash: #f8fbff;
  --bg-accent-a: rgba(59, 130, 246, 0.12);
  --bg-accent-b: rgba(20, 184, 166, 0.1);
  --surface: rgba(255, 255, 255, 0.84);
  --surface-strong: #ffffff;
  --surface-muted: #f4f8fc;
  --surface-tint: #edf4fb;
  --border: rgba(104, 130, 161, 0.18);
  --border-strong: rgba(81, 108, 140, 0.24);
  --text: #122033;
  --text-muted: #64748b;
  --accent: #0f766e;
  --accent-hover: #0b5f6a;
  --accent-soft: #e6f6f4;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
  background: linear-gradient(180deg, var(--bg-base) 0%, var(--bg-wash) 100%);
  color: var(--text);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, var(--bg-accent-a), transparent 34%),
    radial-gradient(circle at top left, var(--bg-accent-b), transparent 28%),
    linear-gradient(180deg, var(--bg-base) 0%, var(--bg-wash) 100%);
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--accent) 0%, #155e75 100%);
  color: white;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}

.primary-button:disabled {
  opacity: 0.7;
  cursor: wait;
}

.secondary-button,
.danger-button,
.segment-link,
.segment-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  padding: 8px 12px;
  text-decoration: none;
  font-weight: 700;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}

.secondary-button {
  border: 1px solid rgba(15, 118, 110, 0.2);
  background: var(--surface-muted);
  color: var(--accent-hover);
}

.secondary-button:hover {
  background: #eaf3fb;
}

.danger-button {
  border: 1px solid rgba(180, 35, 24, 0.24);
  background: #fbe9e7;
  color: #8a1c13;
}

.danger-button:hover {
  background: #f8ddd8;
}

.segmented-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.segment-link,
.segment-button {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text-muted);
}

.segment-button {
  cursor: pointer;
  font: inherit;
}

.segment-link-active,
.segment-button-active {
  background: linear-gradient(135deg, var(--accent) 0%, #155e75 100%);
  border-color: transparent;
  color: white;
}

.dashboard-grid {
  display: grid;
  gap: 20px;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  backdrop-filter: blur(8px);
  padding: 20px;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin-top: 0;
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.section-head h2 {
  margin-bottom: 0;
}

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

.stat-card {
  border-radius: 14px;
  padding: 16px;
  background: var(--surface-muted);
  border: 1px solid rgba(15, 118, 110, 0.12);
}

.stat-label {
  margin: 0 0 8px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.stat-value {
  margin: 0 0 6px;
  font-size: 1.5rem;
  font-weight: 700;
}

.stat-value-compact {
  font-size: 1.05rem;
  line-height: 1.35;
}

.stat-meta {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

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

.data-table caption {
  caption-side: top;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(100, 116, 139, 0.14);
  vertical-align: top;
}

.data-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

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

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-bottom: 14px;
  text-align: left;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.summary-item {
  display: grid;
  gap: 6px;
  border-radius: 14px;
  background: var(--surface-muted);
  border: 1px solid rgba(15, 118, 110, 0.12);
  padding: 14px;
}

.summary-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-size: 0.82rem;
  font-weight: 700;
}

.lookup-badge-button {
  border: 0;
  cursor: pointer;
  text-align: left;
}

.lookup-status-summary {
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.35;
}

.lookup-status-meta {
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.lookup-detail-menu {
  display: grid;
  gap: 8px;
  justify-items: start;
}

.lookup-detail-menu[open] {
  z-index: 3;
}

.lookup-detail-menu summary {
  list-style: none;
}

.lookup-detail-menu summary::-webkit-details-marker {
  display: none;
}

.lookup-detail-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-hover);
  font-size: 0.83rem;
  font-weight: 700;
  cursor: pointer;
}

.lookup-detail-trigger:hover {
  color: var(--accent);
}

.lookup-detail-popover {
  position: static;
  width: min(100%, 420px);
  max-width: min(420px, calc(100vw - 96px));
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(10px);
  overflow-wrap: anywhere;
}

.lookup-detail-section {
  display: grid;
  gap: 5px;
}

.lookup-detail-section h3 {
  margin: 0;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.lookup-detail-section p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.badge-danger {
  background: #fbe9e7;
  color: #8a1c13;
}

.badge-warning {
  background: #fff7d6;
  color: #7a4e00;
}

.badge-checking {
  background: #e9f2fb;
  color: #174a7a;
  animation: badge-checking-pulse 1.2s ease-in-out infinite;
}

.badge-checking::before {
  content: "";
  width: 0.72rem;
  height: 0.72rem;
  margin-right: 0.38rem;
  border-radius: 999px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: badge-checking-spin 0.8s linear infinite;
}

@keyframes badge-checking-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

@keyframes badge-checking-spin {
  100% {
    transform: rotate(360deg);
  }
}

.help-tooltip-trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: help;
}

.help-tooltip-trigger::before,
.help-tooltip-trigger::after {
  position: absolute;
  left: 50%;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.08s linear, transform 0.08s ease-out;
  z-index: 50;
}

.help-tooltip-trigger::before {
  content: "";
  bottom: calc(100% + 2px);
  transform: translateX(-50%) translateY(4px);
  border-width: 6px;
  border-style: solid;
  border-color: rgba(15, 23, 42, 0.94) transparent transparent transparent;
}

.help-tooltip-trigger::after {
  content: attr(data-tooltip);
  bottom: calc(100% + 12px);
  transform: translateX(-50%) translateY(4px);
  width: max-content;
  max-width: min(320px, 72vw);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(15, 23, 42, 0.94);
  color: #f8fafc;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.35;
  white-space: pre-line;
  text-align: left;
}

.help-tooltip-trigger:hover::before,
.help-tooltip-trigger:hover::after,
.help-tooltip-trigger:focus-visible::before,
.help-tooltip-trigger:focus-visible::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.stack-cell {
  display: grid;
  gap: 4px;
}

.muted-text {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.inline-error {
  color: #8a1c13;
  font-size: 0.85rem;
  font-weight: 600;
}

.empty-state {
  margin: 0;
  color: var(--text-muted);
}

.muted-paragraph {
  margin-top: 0;
  color: var(--text-muted);
}

.money-amount {
  display: inline-block;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.money-positive {
  color: #18794e;
}

.money-negative {
  color: #b42318;
}

.money-zero {
  color: var(--text-muted);
}

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

.toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  align-items: end;
}

.toolbar-actions {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.form-field {
  display: grid;
  gap: 8px;
  font-weight: 600;
}

.form-field-attention .field-label {
  color: #8a1c13;
}

.field-legend {
  margin: 0 0 12px;
}

.field-label {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.required-mark {
  color: #8a1c13;
  font-weight: 700;
}

.optional-mark {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.checkbox-field {
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 600;
}

.row-inline-checkbox {
  font-weight: 600;
  gap: 8px;
}

.inline-manual-price-fields {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
}

.text-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 11px 12px;
  background: var(--surface-strong);
  color: var(--text);
  font: inherit;
}

.text-input-attention {
  border-color: rgba(138, 28, 19, 0.36);
  background: #fff7f5;
  box-shadow: 0 0 0 3px rgba(138, 28, 19, 0.08);
}

.text-input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.14);
  outline-offset: 1px;
  border-color: rgba(37, 99, 235, 0.34);
}

.text-input-attention:focus {
  outline: 2px solid rgba(138, 28, 19, 0.14);
  border-color: rgba(138, 28, 19, 0.42);
}

.text-input[readonly] {
  background: #eef2f7;
  color: var(--text-muted);
}

.text-input:disabled {
  background: #eef2f7;
  color: var(--text-muted);
  cursor: not-allowed;
}

.text-area-input {
  min-height: 108px;
  resize: vertical;
}

.notes-input {
  min-height: 72px;
}

.success-banner {
  margin: 0 0 20px;
  border-radius: 12px;
  padding: 12px 14px;
  background: #e8f5ec;
  color: #155b2d;
}

.info-banner {
  margin: 0;
  border-radius: 12px;
  padding: 12px 14px;
  background: #e9f2fb;
  color: #174a7a;
}

.error-banner {
  margin: 0 0 20px;
  border-radius: 12px;
  padding: 12px 14px;
  background: #fbe9e7;
  color: #8a1c13;
}

.loading-state {
  margin: 0;
  color: var(--text-muted);
  font-weight: 600;
}

.auth-shell {
  width: min(100%, 460px);
  margin: 64px auto;
}

.auth-brand {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}

.auth-brand .brand-lockup {
  gap: 14px;
}

.auth-brand-icon {
  width: 56px;
  max-width: 56px;
}

.auth-brand-wordmark {
  font-size: 1.5rem;
  letter-spacing: 0.1em;
}

.auth-panel .section-head {
  margin-bottom: 10px;
}

.auth-form-grid {
  grid-template-columns: 1fr;
  margin-bottom: 20px;
  padding: 0;
  border: 0;
}

.history-growth {
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}

.history-growth strong {
  font-size: 1rem;
}

.history-growth-positive strong {
  color: #18794e;
}

.history-growth-negative strong {
  color: #b42318;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.row-action-menu {
  position: relative;
  display: inline-block;
}

.row-action-menu[open] {
  z-index: 60;
}

.row-action-menu summary {
  list-style: none;
}

.row-action-menu summary::-webkit-details-marker {
  display: none;
}

.row-action-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid rgba(15, 118, 110, 0.2);
  background: var(--surface-muted);
  color: var(--accent-hover);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.05em;
  cursor: pointer;
  user-select: none;
}

.row-action-trigger:hover {
  background: #eaf3fb;
}

.row-action-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 61;
  min-width: 170px;
  display: grid;
  gap: 4px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(10px);
}

.row-action-link {
  display: block;
  border-radius: 10px;
  padding: 9px 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.row-action-link:hover {
  background: var(--surface-muted);
  color: var(--accent-hover);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(8px);
}

.modal-card {
  width: min(100%, 520px);
  display: grid;
  gap: 18px;
  padding: 22px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(244, 248, 252, 0.98) 100%);
  box-shadow: 0 28px 60px rgba(15, 23, 42, 0.24);
}

.modal-head h2 {
  margin: 0;
}

.modal-body {
  display: grid;
  gap: 10px;
}

.modal-body p {
  margin: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.refresh-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}

.refresh-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(244, 248, 252, 0.96) 100%);
}

.refresh-card h3 {
  margin: 0;
  font-size: 1.1rem;
}

.refresh-card-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 12px;
}

.refresh-run-details {
  display: grid;
  gap: 12px;
}

.refresh-card-actions {
  display: grid;
  gap: 12px;
}

.refresh-card-actions .info-banner {
  margin: 0;
}

.refresh-card-actions .secondary-button {
  justify-self: start;
}

.refresh-card-details {
  display: grid;
  gap: 12px;
}

.response-preview {
  margin: 0;
  padding: 12px;
  border-radius: 12px;
  background: #1f2933;
  color: #f8fafc;
  overflow-x: auto;
  font: 0.82rem/1.5 Consolas, "Courier New", monospace;
}

.history-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(244, 248, 252, 0.96) 100%);
}

.history-card-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: start;
  margin-bottom: 14px;
}

.history-kpis {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

.history-kpis div {
  display: grid;
  gap: 4px;
}

.chart-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 10px;
}

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

.chart-hint {
  margin-bottom: 0;
}

.chart-shell {
  position: relative;
  margin-bottom: 16px;
  border-radius: 14px;
  background:
    radial-gradient(circle at top right, rgba(59, 130, 246, 0.08), transparent 34%),
    linear-gradient(180deg, #fbfdff 0%, #eff5fb 100%);
  padding: 10px;
  border: 1px solid rgba(37, 99, 235, 0.1);
  user-select: none;
  -webkit-user-select: none;
}

.history-chart {
  width: 100%;
  height: auto;
  aspect-ratio: 680 / 260;
  display: block;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}

.chart-axis {
  stroke: rgba(100, 116, 139, 0.34);
  stroke-width: 1;
}

.chart-grid-line {
  stroke: rgba(100, 116, 139, 0.14);
  stroke-width: 1;
  stroke-dasharray: 4 6;
}

.chart-tick-label {
  fill: var(--text-muted);
  font-size: 12px;
  font-family: inherit;
  user-select: none;
  -webkit-user-select: none;
}

.chart-line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line-positive {
  stroke: #18794e;
}

.chart-line-negative {
  stroke: #b42318;
}

.chart-line-neutral {
  stroke: #52606d;
}

.chart-dot {
  stroke: rgba(248, 250, 252, 0.92);
  cursor: pointer;
  transition: opacity 120ms ease, stroke-width 120ms ease;
}

.chart-dot-active {
  stroke-width: 2.2;
  filter: drop-shadow(0 0 2px rgba(15, 23, 42, 0.3));
}

.chart-dot:hover {
  opacity: 0.88;
  stroke-width: 2.5;
}

.chart-dot-positive {
  fill: #18794e;
}

.chart-dot-negative {
  fill: #b42318;
}

.chart-dot-neutral {
  fill: #52606d;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  display: grid;
  gap: 4px;
  min-width: 140px;
  max-width: 240px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(24, 35, 45, 0.94);
  color: #f8fafc;
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.24);
  transform: translate(-50%, calc(-100% - 12px));
  pointer-events: none;
  font-size: 0.86rem;
}

.chart-tooltip strong {
  font-size: 0.9rem;
}

.chart-tooltip span,
.chart-tooltip small {
  display: block;
  line-height: 1.35;
}

.chart-tooltip small {
  color: rgba(226, 232, 240, 0.9);
}

.chart-selection-overlay {
  position: absolute;
  top: 10px;
  bottom: 10px;
  border-radius: 10px;
  background: rgba(37, 99, 235, 0.14);
  border: 1px solid rgba(37, 99, 235, 0.34);
  pointer-events: none;
}

@media (max-width: 720px) {
  .history-card-head,
  .section-head,
  .refresh-card-head,
  .chart-toolbar,
  .table-toolbar {
    flex-direction: column;
    align-items: start;
  }

  .inline-manual-price-fields {
    grid-template-columns: 1fr;
  }
}
