:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #d6dde6;
  --primary: #0b63f6;
  --danger: #c92a2a;
  --success: #0d8a3b;
  --pending: #a16207;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at top left, #e5eefc 0%, var(--bg) 35%, #eef6f3 100%);
  color: var(--text);
}

a {
  color: var(--primary);
}

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

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

.brand {
  font-weight: 700;
  letter-spacing: 0.3px;
}

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

.nav a {
  text-decoration: none;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
}

.nav a.active {
  border-color: #90b4f8;
  background: #dbeafe;
}

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

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}

.card .big {
  font-size: 28px;
  font-weight: 700;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-top: 14px;
}

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

.panel-head h3 {
  margin: 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

button,
select,
input {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.primary {
  background: var(--primary);
  border-color: #0a57da;
  color: #fff;
}

button.success {
  background: var(--success);
  border-color: #0a6c2e;
  color: #fff;
}

button.danger {
  background: var(--danger);
  border-color: #9f1f1f;
  color: #fff;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

.schedule-timers {
  margin-bottom: 8px;
  line-height: 1.5;
}

.status {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
}

.status.pending {
  color: var(--pending);
  border-color: #f5d08c;
  background: #fff8e8;
}

.status.accepted {
  color: var(--success);
  border-color: #9be3b2;
  background: #eafbf0;
}

.status.rejected {
  color: var(--danger);
  border-color: #f4b3b3;
  background: #fef0f0;
}

.status.info {
  color: #1d4ed8;
  border-color: #bfd5ff;
  background: #eef4ff;
}

.status.running {
  color: #1d4ed8;
  border-color: #bfd5ff;
  background: #eef4ff;
}

.status.queued {
  color: #7c3aed;
  border-color: #d8c6ff;
  background: #f5f0ff;
}

.status.scheduled,
.status.idle,
.status.completed {
  color: var(--success);
  border-color: #9be3b2;
  background: #eafbf0;
}

.status.manual_only,
.status.never_run {
  color: var(--pending);
  border-color: #f5d08c;
  background: #fff8e8;
}

.status.failed {
  color: var(--danger);
  border-color: #f4b3b3;
  background: #fef0f0;
}

.status.warn {
  color: var(--pending);
  border-color: #f5d08c;
  background: #fff8e8;
}

.status.error {
  color: var(--danger);
  border-color: #f4b3b3;
  background: #fef0f0;
}

.diagnostics-feed td:last-child {
  max-width: 520px;
  white-space: pre-wrap;
  word-break: break-word;
}

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

th,
td {
  padding: 8px;
  border-bottom: 1px solid #e6edf5;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: var(--muted);
  background: #f8fafd;
  position: sticky;
  top: 0;
}

.table-wrap {
  overflow: auto;
  max-height: 68vh;
}

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

.page-info {
  color: var(--muted);
  font-size: 13px;
}

.planning-table input[type="text"] {
  min-width: 170px;
}

.planning-table input[type="number"] {
  width: 100px;
}

.planning-cards {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 12px;
}

.planning-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  padding: 12px;
}

.planning-card-head h4 {
  margin: 0;
  font-size: 18px;
}

.planning-card-head .hint {
  display: inline-block;
  margin-top: 4px;
}

.planning-next {
  margin-top: 6px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--muted);
}

.planning-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 10px;
}

.planning-form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.planning-form-grid small,
.advanced-cron small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.planning-form-grid input,
.planning-form-grid select,
.advanced-cron input {
  width: 100%;
}

.planning-form-grid input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.advanced-cron {
  margin-top: 10px;
}

.hidden {
  display: none;
}

.planning-card-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

.settings-grid {
  margin-top: 12px;
}

.composition-overview {
  margin-bottom: 14px;
}

.compositions-panel {
  padding: 18px;
}

.composition-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 14px;
}

.composition-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  background:
    radial-gradient(circle at top right, rgba(11, 99, 246, 0.08), transparent 32%),
    linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.06);
}

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

.composition-card-title {
  min-width: 0;
}

.composition-product-link {
  display: inline-block;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.3;
  text-decoration: none;
  color: var(--text);
}

.composition-product-link:hover {
  color: var(--primary);
}

.composition-subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.composition-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

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

.composition-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--border);
  background: #f8fbff;
  color: var(--text);
}

.composition-kind-pill {
  background: #eef4ff;
  border-color: #c6d8ff;
  color: #0f3f9a;
}

.composition-source-pill {
  background: #effaf5;
  border-color: #bee4cf;
  color: #11633e;
}

.composition-score-pill.score-high {
  background: #eafbf0;
  border-color: #a9e4bb;
  color: #0d6b31;
}

.composition-score-pill.score-medium {
  background: #fff8e8;
  border-color: #f2d59c;
  color: #9a6508;
}

.composition-score-pill.score-low {
  background: #fff1f1;
  border-color: #f2c1c1;
  color: #b42318;
}

.composition-score-pill.score-neutral {
  background: #f6f8fb;
  border-color: #d6dde6;
  color: var(--muted);
}

.composition-card-body {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(320px, 0.9fr);
  gap: 18px;
}

.composition-main,
.composition-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.composition-section {
  border: 1px solid #e5edf5;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.78);
  padding: 14px;
}

.composition-section-label {
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.composition-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.composition-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: #edf4ff;
  color: #184998;
  border: 1px solid #caddff;
  font-size: 12px;
  font-weight: 600;
}

.subproduct-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.subproduct-item {
  border: 1px solid #e4ebf3;
  border-radius: 14px;
  background: #fbfdff;
  padding: 12px;
}

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

.subproduct-code {
  display: inline-block;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #34518f;
}

.subproduct-name {
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
}

.subproduct-percent {
  min-width: 52px;
  text-align: right;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.subproduct-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.subproduct-bar {
  margin-top: 10px;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #e6edf6;
}

.subproduct-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0b63f6 0%, #54a3ff 100%);
}

.composition-summary-body p {
  margin: 0 0 10px;
  line-height: 1.6;
}

.composition-summary-body p:last-child {
  margin-bottom: 0;
}

.composition-fact {
  display: grid;
  grid-template-columns: minmax(120px, 150px) minmax(0, 1fr);
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid #edf2f7;
  font-size: 13px;
  line-height: 1.55;
}

.composition-fact:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.composition-fact-label {
  color: var(--muted);
  font-weight: 700;
}

.composition-details summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
  line-height: 1.55;
}

.composition-details[open] summary {
  margin-bottom: 12px;
}

.composition-card-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #e6edf5;
  font-size: 12px;
  color: var(--muted);
}

.composition-empty,
.composition-empty-state {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.composition-empty-state {
  border: 1px dashed var(--border);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  background: #f9fbfe;
}

.composition-edit-btn {
  align-self: center;
}

.composition-edit-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.composition-edit-subproducts {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.composition-edit-row {
  display: grid;
  grid-template-columns: 120px minmax(220px, 1fr) 130px 100px auto;
  gap: 8px;
  align-items: center;
}

.composition-edit-row input {
  width: 100%;
}

.live-feed {
  overflow: auto;
  max-height: 36vh;
}

.live-empty {
  color: var(--muted);
  font-size: 13px;
}

.mono {
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
}

.error {
  color: var(--danger);
  font-weight: 600;
}

.crawler-toast-root {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.crawler-toast {
  min-width: 260px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #bfd5ff;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.16);
}

.crawler-toast-title {
  display: block;
  margin-bottom: 4px;
}

.crawler-toast-body {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

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

.modal-card {
  width: min(900px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.2);
  padding: 16px;
}

.modal-backdrop.hidden {
  display: none;
}

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

.modal-head h3 {
  margin: 0;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.modal-form textarea {
  min-height: 100px;
  resize: vertical;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
}

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

@media (max-width: 760px) {
  .wrap {
    padding: 14px 10px 28px;
  }

  th,
  td {
    font-size: 12px;
  }

  .planning-form-grid {
    grid-template-columns: 1fr;
  }

  .composition-card {
    padding: 14px;
  }

  .composition-card-head,
  .composition-card-footer {
    flex-direction: column;
  }

  .composition-meta {
    justify-content: flex-start;
  }

  .composition-edit-row {
    grid-template-columns: 1fr;
  }

  .composition-card-body {
    grid-template-columns: 1fr;
  }

  .composition-fact {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .modal-grid {
    grid-template-columns: 1fr;
  }

  .crawler-toast-root {
    left: 10px;
    right: 10px;
    top: 10px;
  }

  .crawler-toast {
    min-width: 0;
    max-width: none;
  }
}
