:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1a1f36;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --border: #e5e7eb;
  --assistant: #f8fafc;
  --user: #eff6ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
}

.login-card {
  max-width: 400px;
  margin: 12vh auto;
  padding: 2rem;
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}

.login-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 1.5rem;
  font-size: 0.95rem;
}

.login-card input#password {
  font-variant-numeric: tabular-nums;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  font-size: 1rem;
  font-family: inherit;
}

input:focus, textarea:focus {
  outline: 2px solid #bfdbfe;
  border-color: var(--primary);
}

button {
  border: none;
  background: var(--primary);
  color: white;
  border-radius: 10px;
  padding: 0.75rem 1.2rem;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
}

button:hover { background: var(--primary-hover); }

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

#login-form button {
  width: 100%;
  margin-top: 1rem;
}

.error {
  color: #dc2626;
  font-size: 0.9rem;
  margin: 0.5rem 0 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.topbar-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.catalog-status {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: normal;
}

button.secondary {
  background: #059669;
}

button.secondary:hover {
  background: #047857;
}

.product-panel {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
}

.product-panel h2 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.hint {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.product-form {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
}

.product-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
}

.product-form button {
  grid-column: 1 / -1;
  justify-self: start;
}

.product-msg {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  color: #047857;
}

.product-msg.error {
  color: #dc2626;
}

.badge {
  margin-left: 0.75rem;
  font-size: 0.75rem;
  background: #ecfdf5;
  color: #047857;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
}

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 500;
}

.ghost:hover {
  background: #f9fafb;
  color: var(--text);
}

#app-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.main-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.project-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.project-select-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.project-select-label select {
  width: auto;
  min-width: 160px;
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
}

.project-panel {
  width: 380px;
  max-width: 42vw;
  background: var(--card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.project-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1rem 0.5rem;
  gap: 0.5rem;
}

.project-panel-header h2 {
  margin: 0;
  font-size: 1rem;
}

.project-subtotal {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}

.project-empty {
  padding: 0 1rem 1rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.project-items-wrap {
  flex: 1;
  overflow: auto;
  padding: 0 0.5rem 1rem;
}

.project-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.project-table th,
.project-table td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.4rem;
  text-align: left;
  vertical-align: top;
}

.project-table .source-tag {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
}

button.item-delete-btn {
  background: transparent;
  color: #dc2626;
  border: none;
  padding: 0.2rem 0.4rem;
  font-size: 0.75rem;
  font-weight: 500;
}

button.item-delete-btn:hover {
  background: #fef2f2;
  color: #b91c1c;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  width: 100%;
  margin: 0;
  max-width: none;
}

.msg {
  display: flex;
  margin-bottom: 1rem;
}

.msg.user { justify-content: flex-end; }

.bubble {
  max-width: 85%;
  padding: 1rem 1.1rem;
  border-radius: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user .bubble {
  background: var(--user);
  border: 1px solid #dbeafe;
}

.msg.assistant .bubble {
  background: var(--assistant);
  border: 1px solid var(--border);
}

.bubble h2 {
  font-size: 1rem;
  margin: 1rem 0 0.5rem;
  color: var(--primary);
}

.bubble h2:first-child { margin-top: 0; }

.bubble table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 0.5rem 0;
}

.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.5rem;
  text-align: left;
}

.composer {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.5rem 1.5rem;
  background: var(--card);
  border-top: 1px solid var(--border);
  width: 100%;
  margin: 0;
  max-width: none;
}

.composer textarea {
  flex: 1;
  resize: vertical;
  min-height: 72px;
}

.composer button {
  align-self: flex-end;
  min-width: 110px;
}

@media (max-width: 640px) {
  .composer { flex-direction: column; }
  .composer button { width: 100%; }
}

.quote-actions {
  margin-top: 0.75rem;
  max-width: 85%;
}

button.confirm-order-btn,
button.add-project-btn {
  background: #059669;
}

button.confirm-order-btn:hover,
button.add-project-btn:hover {
  background: #047857;
}

button.confirm-order-btn:disabled,
button.add-project-btn:disabled {
  background: #6b7280;
}

@media (max-width: 960px) {
  .app-layout {
    flex-direction: column;
  }

  .project-panel {
    width: 100%;
    max-width: none;
    max-height: 40vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

.quote-hint {
  margin: 0.75rem 0 0;
  max-width: 85%;
  font-size: 0.85rem;
  color: #b45309;
}
