:root {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --bg-page: #090d16;
  --bg-card: #111827;
  --bg-card-subtle: #1a2336;
  --bg-input: #0f172a;
  --border-color: #243147;
  --border-focus: #f97316;

  --text-main: #f8fafc;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  --accent: #f97316;
  --accent-hover: #ea580c;
  --accent-soft: rgba(249, 115, 22, 0.14);
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.14);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

[data-theme="light"] {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #cbd5e1;
  --border-focus: #ea580c;

  --text-main: #0f172a;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --accent: #ea580c;
  --accent-hover: #c2410c;
  --accent-soft: #ffedd5;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #b45309;
  --warning-bg: #fffbeb;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: var(--font-main);
  background: var(--bg-page);
  color: var(--text-primary);
  margin: 0;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, .brand-title, .panel-title {
  font-family: var(--font-heading);
}

.mono {
  font-family: var(--font-mono);
}

.tool-layout {
  width: 100%;
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
  flex: 1 0 auto;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card-main {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.35rem;
  width: 100%;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.panel-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.panel-subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.preset-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.preset-btn {
  background: var(--bg-card-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
}

.preset-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.partidas-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.partida-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  padding: 0.65rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
}

.partida-select-wrap {
  flex: 1 1 0%;
  min-width: 0;
}

.partida-select-wrap select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 0.5rem 40px 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.9rem;
  appearance: none;
  -webkit-appearance: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3b8' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.partida-select-wrap select option {
  background-color: var(--bg-card);
  color: var(--text-primary);
}

.partida-qty-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 135px;
  flex-shrink: 0;
}

.partida-qty-wrap input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  min-height: 42px;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.94rem;
  text-align: right;
}

.partida-unit {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  width: 30px;
}

.btn-remove-row {
  width: 38px;
  height: 42px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
}

.btn-remove-row:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.controls-bottom-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
}

.margin-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 220px;
}

.margin-field label {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.margin-field select {
  width: 100%;
  min-height: 42px;
  padding: 0.5rem 40px 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-input);
  color: var(--text-primary);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2394a3b8' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.margin-field select option {
  background-color: var(--bg-card);
  color: var(--text-primary);
}

.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 42px;
  padding: 0.6rem 1.05rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
}

.btn-primary {
  border: none;
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  border: 1px solid var(--border-color);
  background: var(--bg-card-subtle);
  color: var(--text-primary);
}

.btn-secondary:hover {
  border-color: var(--accent);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.kpi-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.9rem;
}

.kpi-card.is-highlight {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 700;
}

.kpi-sub {
  font-size: 0.77rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  line-height: 1.35;
}

.advice-banner {
  padding: 0.9rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  font-size: 0.92rem;
  line-height: 1.45;
  margin-bottom: 0.85rem;
}

.alert-box {
  display: none;
  align-items: flex-start;
  gap: 0.65rem;
  background: var(--warning-bg);
  border: 1px solid var(--warning);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  margin-bottom: 1rem;
  font-size: 0.86rem;
  line-height: 1.45;
}

.bars-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.bar-row {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}

.bar-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.83rem;
  font-weight: 600;
  margin-bottom: 0.45rem;
}

.bar-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--bg-input);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.25s ease;
}

.bar-fill.is-ok {
  background: var(--success);
}

.bar-fill.is-over {
  background: var(--danger);
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.data-table th,
.data-table td {
  padding: 0.65rem 0.6rem;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.85rem;
}

.faq-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card-subtle);
  padding: 0.25rem 0.9rem;
}

.faq-question {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  list-style: none;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-chevron {
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.faq-item[open] .faq-chevron {
  transform: rotate(180deg);
}

.faq-answer p {
  margin: 0 0 0.85rem;
  font-size: 0.89rem;
  line-height: 1.55;
  color: var(--text-secondary);
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.is-open {
  display: flex;
}

.modal-dialog {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-title {
  margin: 0;
  font-size: 1rem;
}

.btn-modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 1.1rem;
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.modal-footer {
  padding: 0.85rem 1.1rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

@media (max-width: 960px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .card-main {
    padding: 1rem;
  }
  .partida-row {
    flex-wrap: wrap;
  }
  .partida-select-wrap {
    flex: 1 0 100%;
  }
  .partida-qty-wrap {
    flex: 1 1 0%;
    width: auto;
  }
  .kpi-grid,
  .bars-grid {
    grid-template-columns: 1fr;
  }
  .margin-field,
  .btn-primary,
  .btn-secondary {
    width: 100%;
  }
}
