:root {
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #0f172a;
  --subtle: #334155;
  --muted: #64748b;
  --border: #cbd5e1;
  --primary: #0ea5a3;
  --primary-hover: #0b8c8a;
  --chip-bg: #f1f5f9;
  --chip-text: #334155;
  --info-bg: #eff6ff;
  --info-text: #1d4ed8;
  --danger-bg: #fef2f2;
  --danger-text: #b91c1c;
  --danger-border: #fecaca;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.widget-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 12px;
}

.mini-card {
  width: min(100%, 700px);
  background: var(--card-bg);
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 10px 28px rgba(2, 6, 23, 0.08);
  position: relative;
  overflow: hidden;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(248, 250, 252, 0.86);
  backdrop-filter: blur(1px);
  pointer-events: all;
}

.loading-overlay[hidden] {
  display: none;
}

.loading-overlay-inner {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 10px 14px;
  background: #ffffff;
  color: #0f172a;
  font-size: 14px;
  font-weight: 600;
}

.loading-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #cbd5e1;
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

.card-header h1 {
  margin: 0;
  font-size: 23px;
  line-height: 1.1;
  font-weight: 700;
  color: #0b1f44;
}

.view-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--chip-text);
  font-size: 12px;
  line-height: 1;
  padding: 6px 10px;
  white-space: nowrap;
}

.input-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span {
  color: var(--subtle);
  font-size: 15px;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 16px;
  color: var(--text);
  background: #fff;
}

.field input:focus,
.field select:focus {
  outline: 2px solid #bfdbfe;
  border-color: #60a5fa;
}

.status-box {
  margin-top: 12px;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  background: var(--info-bg);
  color: var(--info-text);
  font-size: 14px;
  padding: 8px 10px;
}

.status-box.error {
  border-color: var(--danger-border);
  background: var(--danger-bg);
  color: var(--danger-text);
}

.calc-section {
  margin-top: 14px;
  border-top: 1px solid #e2e8f0;
  padding-top: 14px;
}

.calc-section h2 {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 700;
  color: #1e293b;
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}

.calc-item {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  padding: 10px;
}

.calc-item span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.calc-item strong {
  display: block;
  font-size: 30px;
  line-height: 1;
  letter-spacing: -0.01em;
  color: #0f172a;
}

.action-row {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.mode-btn {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #0f172a;
  border-radius: 10px;
  min-height: 40px;
  padding: 0 14px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
}

.mode-btn:hover {
  background: #eef2f7;
}

.mode-btn.mode-btn-primary,
.mode-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.mode-btn.mode-btn-primary:hover,
.mode-btn.active:hover {
  background: var(--primary-hover);
}

.mode-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.panel {
  margin-top: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #f8fafc;
  padding: 12px;
}

.panel h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
}

.metrics,
.offers-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.metrics th,
.metrics td,
.offers-table th,
.offers-table td {
  border-bottom: 1px solid #e2e8f0;
  padding: 7px 6px;
}

.metrics th,
.offers-table th {
  color: #475569;
  font-weight: 600;
}

.metrics th,
.metrics td,
.offers-table td.num,
.offers-table th.num {
  text-align: right;
}

.metrics th:first-child,
.metrics td:first-child,
.offers-table th:first-child,
.offers-table td:first-child {
  text-align: left;
}

.metrics tr:last-child td,
.offers-table tr:last-child td {
  border-bottom: 0;
}

.offers-table tr.best {
  background: #ecfeff;
}

.offers-wrap {
  height: 300px;
  overflow-x: auto;
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #ffffff;
}

.offers-wrap .offers-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
}

.sortable-th {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  width: 100%;
  white-space: nowrap;
}

.sort-controls {
  display: inline-flex;
  flex-direction: column;
  gap: 1px;
  align-items: center;
}

.sort-btn {
  border: 0;
  background: transparent;
  color: #94a3b8;
  font-size: 10px;
  line-height: 1;
  width: 12px;
  height: 10px;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sort-btn.active {
  color: #0b8c8a;
}

.panel-note {
  margin-top: 8px;
  color: #475569;
  font-size: 11px;
}

.empty {
  color: #64748b;
  font-size: 13px;
}

@media (max-width: 640px) {
  .mini-card {
    padding: 14px;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .card-header h1 {
    font-size: 21px;
  }

  .input-grid,
  .calc-grid {
    grid-template-columns: 1fr;
  }

  .calc-item strong {
    font-size: 25px;
  }

  .mode-btn {
    width: 100%;
  }
}
