@import url("../shared/design.css");

body {
  height: 100vh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

.bom-app.app-shell {
  width: min(1180px, calc(100vw - 32px));
  height: calc(100vh - 32px);
  max-height: 760px;
  display: grid;
  grid-template-columns: minmax(340px, 400px) minmax(0, 1fr);
  grid-template-rows: 1fr;
  gap: 12px;
  min-height: 0;
}

/* ── Left panel ── */

.input-card,
.results-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-lead { display: none; }

/* Dropzone — always compact horizontal layout */
.dropzone {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding: 10px 14px;
  border: 2px dashed var(--card-border);
  border-radius: var(--radius-lg);
  background: #f8fafc;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-dragover {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px var(--accent-muted);
  transform: translateY(-1px);
}

.dropzone-icon {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  background: var(--accent-muted);
}

.dropzone-copy {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}

.dropzone-copy h2 {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropzone-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.browse-button {
  flex: 0 0 auto;
  padding: 6px 10px;
  font-size: 0.82rem;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  left: 0;
  top: 0;
  opacity: 0;
  pointer-events: none;
}

/* ── Product list ── */

.product-list-section {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--card-border);
}


.product-list {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-auto-rows: max-content;
  gap: 6px;
  padding-right: 4px;
}

.product-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  background: #fff;
  transition: background 0.1s ease;
}

.product-item--disabled {
  opacity: 0.45;
}

.product-checkbox {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  cursor: pointer;
  accent-color: var(--accent);
}

.product-info {
  flex: 1;
  min-width: 0;
}

.product-name {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-meta {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-qty-control {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
}

.product-qty-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.product-qty-input {
  padding: 4px 6px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  border: 1.5px solid var(--card-border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
  /* override global input width */
  width: 64px !important;
}

.product-qty-input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 2px var(--accent-muted);
}

/* ── Calculate button ── */

.calculate-section {
  flex: 0 0 auto;
  padding-top: 10px;
}

.calc-hint {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  opacity: 0;
  transition: opacity 0.15s;
}

#calculateButton:disabled ~ .calc-hint {
  opacity: 1;
}

.calculate-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  font-size: 0.9rem;
}

.calculate-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── Export button ── */

.export-button {
  padding: 9px 14px;
  white-space: nowrap;
  flex: 0 0 auto;
}


/* ── Results list ── */

.results-list {
  flex: 1;
  min-height: 0;
  overflow-y: scroll;
  scrollbar-gutter: stable;
  padding-right: 4px;
  display: grid;
  grid-auto-rows: max-content;
  gap: 16px;
}

.results-section-empty {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 10px 2px;
}

.collapsible-waste-badge-group {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.collapsible-waste-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.collapsible-waste-badges {
  display: inline-flex;
  position: relative;
  background: #f1f5f9;
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.collapsible-waste-badge-slider {
  position: absolute;
  top: 3px;
  left: 3px;
  height: calc(100% - 6px);
  border-radius: 999px;
  pointer-events: none;
  background: #fee2e2;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s ease, width 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.collapsible-waste-badge-slider--optimized {
  background: #dcfce7;
  box-shadow: 0 1px 3px rgba(22, 101, 52, 0.1);
}

.collapsible-waste-badge {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  background: transparent;
  color: #991b1b;
  position: relative;
  z-index: 1;
  transition: color 0.15s ease;
}

.collapsible-waste-badge--optimized {
  color: #166534;
}

.collapsible-waste-badge--ok {
  color: #166534;
}

.collapsible-waste-badge--inactive {
  color: #94a3b8;
}

.collapsible-waste-badge--clickable {
  cursor: pointer;
  position: relative;
}

/* Expand touch target to full header height without changing visual size */
.collapsible-waste-badge--clickable::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -40px;
  bottom: -40px;
}

.collapsible-waste-badge--clickable.collapsible-waste-badge--inactive:hover {
  color: #475569;
}

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

.collapsible-waste-badge--loading {
  color: var(--muted);
  animation: badge-pulse 1.4s ease-in-out infinite;
  pointer-events: none;
}

.optimizing-state {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

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

.optimizing-state svg {
  flex: 0 0 auto;
  animation: spin 1s linear infinite;
  color: var(--accent);
}

.results-collapsible-body .coating-table {
  margin: -10px -12px;
  width: calc(100% + 24px);
}

/* ── Material details ── */

.material-details + .material-details {
  margin-top: 8px;
}

.material-details {
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  background: #fff;
  overflow: hidden;
}

.material-details--alert {
  border-color: #fca5a5;
  background: #fff5f5;
}

.material-details summary {
  list-style: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  cursor: pointer;
}

.material-details summary .toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-right: 8px;
  color: var(--muted);
  flex: 0 0 auto;
  transition: transform 0.12s ease;
}

.material-details[open] summary .toggle-icon {
  transform: rotate(180deg);
}

.material-details summary .summary-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.material-details summary::-webkit-details-marker {
  display: none;
}

.material-details summary:hover {
  background: #f8fafc;
}

.material-details--alert summary:hover {
  background: #fff1f1;
}

.material-title {
  font-size: 0.94rem;
  font-weight: 600;
}

.material-subtitle { display: none !important; }

.summary-badges {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 4px;
  flex: 0 0 auto;
}

.summary-badges--text {
  font-size: 0.78rem;
  font-weight: 600;
}

.summary-number {
  color: var(--text);
  font-weight: 700;
}

/* Waste badge on summary row */
.waste-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.waste-badge--ok {
  background: #dcfce7;
  color: #166534;
}

.waste-badge--alert {
  background: #fee2e2;
  color: #991b1b;
}

.waste-badge--alert .summary-number {
  color: #991b1b;
}

.badge { display: none; }
.badge--soft { display: none; }
.badge--danger { display: none; }

.material-body {
  display: grid;
  gap: 12px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--card-border);
}

.material-details--alert .material-body {
  border-top-color: #fca5a5;
}

.material-stats { display: none !important; }

/* ── Pattern block ── */

.source-block,
.pattern-block {
  display: grid;
  gap: 8px;
}

.block-title {
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.chip-row,
.pattern-chiprow,
.pattern-sublist {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip,
.pattern-chip,
.pattern-sublist li {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--bg);
  font-size: 0.8rem;
}

.pattern-qty {
  font-weight: 700;
  color: var(--text);
  background: var(--accent-muted);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.78rem;
}

.pattern-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-auto-rows: max-content;
  gap: 12px;
}

.pattern-item {
  padding: 9px 12px;
  background: #fff;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  display: grid;
  gap: 7px;
}

.pattern-item--alert {
  border-color: #fca5a5;
  background: #fff8f8;
}

.pattern-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.pattern-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent);
}

.pattern-name small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  margin-left: 4px;
}

.pattern-foot {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  padding-top: 6px;
  border-top: 1px dashed var(--card-border);
  color: var(--muted);
  font-size: 0.78rem;
}

.waste-tag {
  color: var(--muted);
  font-weight: 500;
}

.waste-tag--alert {
  color: #dc2626;
  font-weight: 700;
}

/* ── Powder coating table ── */

.coating-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.coating-table thead th {
  padding: 7px 14px;
  text-align: left;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--card-border);
  background: #f8fafc;
}

.coating-table thead th:last-child {
  text-align: right;
}

.coating-table tbody td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--card-border);
  color: var(--text);
  font-weight: 500;
}

.coating-table tbody td:last-child {
  text-align: right;
  font-weight: 700;
  color: var(--accent);
}

.coating-table tbody tr:last-child td {
  border-bottom: none;
}

.coating-table tbody tr:hover td {
  background: #f8fafc;
}


.summary-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.summary-stat-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  background: #fff;
}

.summary-stat-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.summary-stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.summary-stat-unit {
  font-size: 0.75rem;
  color: var(--muted);
}


/* ── Responsive ── */

@media (max-width: 980px) {
  body {
    height: auto;
    overflow: auto;
    align-items: flex-start;
  }

  .bom-app.app-shell {
    width: min(980px, calc(100vw - 24px));
    height: auto;
    max-height: none;
    margin: 12px auto;
    grid-template-columns: 1fr;
  }

  .input-card,
  .results-card {
    overflow: visible;
  }

  .results-list {
    max-height: 460px;
  }

  .summary-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .panel-header,
  .material-details summary,
  .pattern-head,
  .pattern-foot {
    flex-direction: column;
    align-items: flex-start;
  }

  .summary-badges {
    justify-content: flex-start;
  }

  .summary-stats {
    grid-template-columns: 1fr;
  }

  .dropzone {
    min-height: 180px;
  }

  /* Waste badge group wraps to its own row under the section title */
  .results-collapsible-header {
    flex-wrap: wrap;
  }

  .collapsible-waste-badge-group {
    margin-left: 0;
    /* indent aligns badge with title text: toggle icon (14px) + gap (8px) */
    padding-left: 22px;
    flex-basis: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .collapsible-waste-badge-group::-webkit-scrollbar {
    display: none;
  }

  .collapsible-waste-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
  }

  /* Reduce the oversized touch-target pseudo so it doesn't bleed into row above */
  .collapsible-waste-badge--clickable::before {
    top: -8px;
    bottom: -8px;
  }
}
