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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  font-size: 14px;
  background: #f0f2f5;
  color: #1a1a2e;
  min-height: 100vh;
}

/* ── AUTH ── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
}

.auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 48px;
  width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo h1 {
  font-size: 22px;
  font-weight: 700;
  color: #1a1a2e;
  letter-spacing: -0.5px;
}

.auth-logo p {
  font-size: 13px;
  color: #888;
  margin-top: 4px;
}

.auth-card label,
.setup-card label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  margin-top: 20px;
}

.auth-card input,
.setup-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #e0e0e0;
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s;
  outline: none;
}

.auth-card input:focus,
.setup-card input:focus { border-color: #0f3460; }

.btn-primary {
  width: 100%;
  padding: 13px;
  background: #0f3460;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 28px;
  transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover { background: #16213e; }
.btn-primary:active { transform: scale(0.98); }

.auth-error {
  color: #e53e3e;
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  display: none;
}

/* ── SETUP SCREEN ── */
#setup-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 60%, #0f3460 100%);
}

.setup-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 48px;
  width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.setup-card h2 {
  font-size: 20px;
  font-weight: 700;
  color: #1a1a2e;
  margin-bottom: 8px;
}

.setup-card p {
  color: #666;
  font-size: 13px;
  margin-bottom: 24px;
}

/* ── APP ── */
#app-screen { display: none; }

.app-header {
  background: #1a1a2e;
  color: #fff;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.app-header h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.app-header .header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-badge {
  font-size: 13px;
  color: #a0aec0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-sm {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid rgba(255,255,255,0.2);
  background: transparent;
  color: #fff;
  transition: background 0.2s;
}

.btn-sm:hover { background: rgba(255,255,255,0.1); }

.btn-danger-sm {
  border-color: rgba(229,62,62,0.5);
  color: #fc8181;
}

.btn-danger-sm:hover { background: rgba(229,62,62,0.15); }

.app-body {
  max-width: 960px;
  margin: 24px auto;
  padding: 0 16px 48px;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
}

/* ── CARDS ── */
.card {
  background: #fff;
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  margin-bottom: 16px;
}

.card-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #718096;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

/* ── FORM ELEMENTS ── */
.form-row {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

.form-group { display: flex; flex-direction: column; gap: 4px; }

.form-group label {
  font-size: 11px;
  font-weight: 600;
  color: #718096;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 9px 12px;
  border: 1.5px solid #e2e8f0;
  border-radius: 7px;
  font-size: 13.5px;
  font-family: inherit;
  color: #1a1a2e;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #fff;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: #0f3460;
  box-shadow: 0 0 0 3px rgba(15,52,96,0.1);
}

.form-group input.has-value { border-color: #48bb78; }
.form-group input.not-found { border-color: #fc8181; }

/* ── COMPOSITION INPUT ── */
.composition-wrap {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.composition-wrap input { flex: 1; }

.btn-calc {
  padding: 9px 18px;
  background: #0f3460;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.btn-calc:hover { background: #16213e; }

/* ── FABRIC AUTOCOMPLETE ── */
.autocomplete-wrap { position: relative; }

.autocomplete-list {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 50;
  max-height: 220px;
  overflow-y: auto;
  display: none;
}

.autocomplete-list.open { display: block; }

.autocomplete-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.autocomplete-item:hover { background: #f7fafc; }

.autocomplete-item .ac-name { font-weight: 500; color: #1a1a2e; }
.autocomplete-item .ac-meta { font-size: 11px; color: #a0aec0; white-space: nowrap; }
.autocomplete-item .ac-promo {
  font-size: 10px;
  background: #fef3c7;
  color: #92400e;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 600;
}

/* ── SOFTNESS TOGGLE ── */
.softness-toggle {
  display: flex;
  gap: 0;
  border: 1.5px solid #e2e8f0;
  border-radius: 7px;
  overflow: hidden;
  width: fit-content;
}

.softness-toggle input { display: none; }

.softness-toggle label {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: #718096;
  background: #fff;
  transition: all 0.15s;
  text-transform: none;
  letter-spacing: 0;
  border: none;
  border-right: 1px solid #e2e8f0;
  min-width: 42px;
  text-align: center;
}

.softness-toggle label:last-child { border-right: none; }

.softness-toggle input:checked + label {
  background: #0f3460;
  color: #fff;
  border-right-color: #0f3460;
}

/* ── FABRIC INFO BADGE ── */
.fabric-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.badge {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
}

.badge-group { background: #ebf8ff; color: #2b6cb0; }
.badge-promo { background: #fef3c7; color: #92400e; }
.badge-type { background: #f0fff4; color: #276749; }
.badge-error { background: #fff5f5; color: #c53030; }

/* ── MODULES TABLE ── */
.modules-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.modules-table th {
  text-align: left;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #718096;
  border-bottom: 2px solid #eee;
}

.modules-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #f7fafc;
  vertical-align: top;
}

.modules-table tr:last-child td { border-bottom: none; }
.modules-table tr:hover td { background: #f7fafc; }

.modules-table .td-code {
  font-weight: 700;
  font-family: 'Courier New', monospace;
  color: #0f3460;
  white-space: nowrap;
}

.modules-table .td-name {
  color: #4a5568;
  max-width: 240px;
}

.modules-table .td-price {
  text-align: right;
  font-weight: 600;
  color: #1a1a2e;
  white-space: nowrap;
}

.modules-table .td-soft {
  text-align: right;
  color: #718096;
  font-size: 12px;
  white-space: nowrap;
}

.td-notfound {
  color: #fc8181;
  font-style: italic;
  font-size: 12px;
}

.td-mechanism {
  font-size: 11px;
  color: #a0aec0;
  margin-top: 2px;
}

/* ── RESULT PANEL ── */
.result-panel {
  position: sticky;
  top: 76px;
}

.result-card {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.result-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #718096;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.result-line {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  font-size: 13px;
}

.result-line .rl-label { color: #718096; }
.result-line .rl-value { font-weight: 600; color: #1a1a2e; }

.result-divider {
  border: none;
  border-top: 1px solid #eee;
  margin: 14px 0;
}

.result-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 4px;
}

.result-total .rt-label {
  font-size: 16px;
  font-weight: 700;
  color: #1a1a2e;
}

.result-total .rt-value {
  font-size: 24px;
  font-weight: 800;
  color: #0f3460;
}

.result-note {
  font-size: 11px;
  color: #a0aec0;
  margin-top: 14px;
  text-align: center;
}

.discount-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #eee;
}

.discount-input-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
}

.discount-input-wrap input {
  width: 72px;
  padding: 6px 8px;
  border: 1.5px solid #e2e8f0;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  text-align: right;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

.discount-input-wrap input:focus { border-color: #276749; }

.discount-sign {
  font-size: 14px;
  font-weight: 600;
  color: #718096;
}

.btn-reset {
  width: 100%;
  padding: 10px;
  background: #fff;
  color: #718096;
  border: 1.5px solid #e2e8f0;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 16px;
  transition: all 0.2s;
}

.btn-reset:hover { background: #fff5f5; border-color: #fc8181; color: #c53030; }

/* ── USERS PANEL ── */
.users-list { list-style: none; }

.users-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #f7fafc;
  font-size: 13px;
}

.users-list li:last-child { border-bottom: none; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: #a0aec0;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.2s;
}

.btn-icon:hover { color: #c53030; }

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: #a0aec0;
  font-size: 13px;
}

.empty-state .es-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

/* ── PROMO ALERT ── */
.promo-alert {
  background: #fef3c7;
  border: 1px solid #f6e05e;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  color: #744210;
  margin-top: 8px;
  display: none;
}

.promo-alert.show { display: block; }

/* ── SECTION DIVIDERS ── */
.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #a0aec0;
  margin: 16px 0 10px;
  padding-left: 2px;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e0; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a0aec0; }

/* ── DROP ZONE ── */
#drop-zone {
  border: 2px dashed #cbd5e0;
  border-radius: 10px;
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: #f7fafc;
}

#drop-zone.dragover {
  border-color: #0f3460;
  background: #ebf8ff;
}

.drop-icon { font-size: 36px; margin-bottom: 8px; }

.drop-text {
  font-size: 13px;
  color: #718096;
  margin-bottom: 14px;
  line-height: 1.5;
}

.btn-upload {
  padding: 8px 20px;
  background: #0f3460;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-upload:hover { background: #16213e; }

#upload-status {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
}

#upload-status.success {
  background: #f0fff4;
  color: #276749;
  border: 1px solid #9ae6b4;
}

#upload-status.error {
  background: #fff5f5;
  color: #c53030;
  border: 1px solid #feb2b2;
}

/* ── SPEC BUTTON ── */
.btn-spec {
  padding: 9px 16px;
  background: #276749;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.btn-spec:hover { background: #22543d; }

/* ── AI CALCULATE BUTTON ── */
.btn-agent-calc {
  padding: 9px 16px;
  background: linear-gradient(135deg, #5b21b6, #7c3aed);
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.2s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(91,33,182,0.35);
}
.btn-agent-calc:hover { opacity: 0.9; }
.btn-agent-calc:active { transform: scale(0.97); }

/* ── AGENT VERIFY ── */
.btn-agent {
  padding: 9px 16px;
  background: #553c9a;
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}
.btn-agent:hover { background: #44337a; }

.btn-agent-sm {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid rgba(149,103,255,0.4);
  background: transparent;
  color: #b794f4;
  transition: background 0.2s;
}
.btn-agent-sm:hover { background: rgba(149,103,255,0.15); }

.btn-fabrics {
  border-color: rgba(104,211,145,0.4);
  color: #68d391;
}
.btn-fabrics:hover { background: rgba(104,211,145,0.12); }

.btn-rules {
  border-color: rgba(246,173,85,0.4);
  color: #f6ad55;
}
.btn-rules:hover { background: rgba(246,173,85,0.12); }

@keyframes spin { to { transform: rotate(360deg); } }
.agent-spinner {
  width: 18px; height: 18px; flex-shrink: 0;
  border: 2px solid #e2e8f0;
  border-top-color: #0f3460;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── INVOICE DROP ZONE ── */
#invoice-drop-zone {
  border: 2px dashed #cbd5e0;
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: #f7fafc;
}
#invoice-drop-zone.dragover {
  border-color: #276749;
  background: #f0fff4;
}
#inv-dz-loaded { display: flex; }

/* ── SEND BUTTON ── */
.btn-send {
  width: 100%;
  padding: 11px;
  background: linear-gradient(135deg, #276749, #2f855a);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(39,103,73,0.35);
}
.btn-send:hover { opacity: 0.9; }
.btn-send:active { transform: scale(0.98); }
.btn-send:disabled { opacity: 0.6; cursor: default; }

#send-status {
  font-size: 12px;
  margin-top: 6px;
  text-align: center;
  min-height: 16px;
}
.send-status-ok { color: #276749; }
.send-status-err { color: #c53030; }

/* ── RESPONSIVE ── */
@media (max-width: 700px) {
  .app-body {
    grid-template-columns: 1fr;
  }
  .result-panel { position: static; }
}
