/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --green: #34c759;
  --orange: #ff9f0a;
  --red: #ff3b30;
  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #aeaeb2;
  --border: #e5e5ea;
  --border-light: #f2f2f7;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --font: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --transition: 0.2s ease;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: var(--font);
  cursor: pointer;
  border: none;
  background: none;
  font-size: inherit;
}

input, select, textarea {
  font-family: var(--font);
  font-size: inherit;
}

/* ===== Login Page ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-logo {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 0.93rem;
  margin-bottom: 32px;
}

.login-card .form-group {
  margin-bottom: 20px;
  text-align: left;
}

.login-card label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.login-card input[type="password"] {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  transition: border-color var(--transition);
  outline: none;
  background: var(--bg);
}

.login-card input[type="password"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,113,227,0.15);
}

.login-error {
  background: #fff2f2;
  color: var(--red);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: none;
}

.login-error.visible { display: block; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.93rem;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  padding: 12px;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

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

.btn-secondary:hover { background: var(--border-light); }

.btn-sm {
  padding: 6px 14px;
  font-size: 0.85rem;
}

.btn-success {
  background: var(--green);
  color: #fff;
}

.btn-danger {
  background: var(--red);
  color: #fff;
}

/* ===== App Shell ===== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-logo {
  padding: 20px 24px;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  color: var(--text-secondary);
  font-size: 0.93rem;
  font-weight: 450;
  transition: all var(--transition);
  text-decoration: none;
  border-left: 3px solid transparent;
}

.sidebar-link:hover {
  background: var(--bg);
  color: var(--text-primary);
  text-decoration: none;
}

.sidebar-link.active {
  color: var(--accent);
  background: rgba(0,113,227,0.06);
  border-left-color: var(--accent);
}

.sidebar-link .icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.sidebar-bottom {
  padding: 12px 0;
  border-top: 1px solid var(--border-light);
}

/* Main content */
.main-wrap {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.green { background: var(--green); }
.status-dot.orange { background: var(--orange); }
.status-dot.red { background: var(--red); }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--bg);
  color: var(--text-secondary);
}

.mobile-menu-btn {
  display: none;
  padding: 8px;
  font-size: 1.3rem;
  color: var(--text-secondary);
}

/* Page content */
.page-content {
  flex: 1;
  padding: 32px;
  max-width: 1200px;
  width: 100%;
}

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  padding: 24px;
  transition: box-shadow var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
}

/* ===== Grid layouts ===== */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ===== Stat cards ===== */
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  padding: 20px;
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-sub {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.badge-green { background: rgba(52,199,89,0.12); color: #248a3d; }
.badge-orange { background: rgba(255,159,10,0.12); color: #c77c00; }
.badge-red { background: rgba(255,59,48,0.12); color: #d70015; }
.badge-blue { background: rgba(0,113,227,0.1); color: var(--accent); }
.badge-gray { background: var(--bg); color: var(--text-secondary); }

/* ===== Form elements ===== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input, .form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.93rem;
  transition: border-color var(--transition);
  outline: none;
  background: var(--surface);
}

.form-input:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,113,227,0.12);
}

.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.form-row .form-group { flex: 1; margin-bottom: 0; }

/* ===== Product cards ===== */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.product-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
}

.product-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.product-thumb {
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  font-weight: 700;
  color: #fff;
}

.product-body {
  padding: 16px;
}

.product-title {
  font-size: 0.93rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

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

.product-price {
  font-weight: 600;
  color: var(--text-primary);
}

.product-rating {
  color: var(--orange);
  font-size: 0.85rem;
}

.product-stats {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ===== Opportunity detail ===== */
.opp-hero {
  display: flex;
  gap: 24px;
  margin-bottom: 24px;
}

.opp-hero-thumb {
  width: 120px;
  height: 120px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.opp-hero-info { flex: 1; }

.opp-hero-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.opp-hero-detail {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.opp-hero-badges {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.metric-card {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}

.metric-label {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.metric-value {
  font-size: 1.2rem;
  font-weight: 700;
}

/* ===== Section headers ===== */
.section {
  margin-bottom: 24px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 1.05rem;
  font-weight: 600;
}

/* ===== Supplier cards ===== */
.supplier-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: all var(--transition);
}

.supplier-card:hover {
  box-shadow: var(--shadow-sm);
  border-color: var(--accent);
}

.supplier-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.supplier-info { flex: 1; }

.supplier-name {
  font-weight: 600;
  font-size: 0.93rem;
  margin-bottom: 2px;
}

.supplier-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.supplier-price {
  font-weight: 600;
  font-size: 0.93rem;
  text-align: right;
}

.supplier-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== Conversation panel ===== */
.conversation-panel {
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-top: 16px;
}

.conversation-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.conversation-messages {
  padding: 16px 20px;
  min-height: 200px;
  max-height: 400px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
}

.msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-supplier {
  align-self: flex-start;
  background: var(--bg);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.msg-system {
  align-self: center;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 0.8rem;
  text-align: center;
}

.conversation-compose {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border-light);
}

.conversation-compose input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  outline: none;
  font-size: 0.9rem;
}

.conversation-compose input:focus {
  border-color: var(--accent);
}

.conversation-compose button {
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  border-radius: 20px;
  font-weight: 500;
  font-size: 0.85rem;
}

/* ===== Settings ===== */
.settings-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  padding: 24px;
  margin-bottom: 16px;
}

.settings-card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-group {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.toggle-label {
  font-size: 0.9rem;
  color: var(--text-primary);
}

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.empty-state-text {
  font-size: 0.9rem;
  margin-bottom: 20px;
}

/* ===== Loading spinner ===== */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-lg {
  width: 36px;
  height: 36px;
  border-width: 3px;
}

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

.loading-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
}

/* ===== Toast ===== */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--text-primary);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  max-width: 360px;
}

.toast-success { background: #1b7d3a; }
.toast-error { background: #c9302c; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(12px); }
}

/* ===== Stars ===== */
.stars {
  display: inline-flex;
  gap: 1px;
}

.star { color: var(--orange); font-size: 0.85rem; }
.star.empty { color: var(--border); }

/* ===== Quick actions ===== */
.quick-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ===== Provider row ===== */
.provider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}

.provider-row:last-child { border-bottom: none; }

.provider-name {
  font-weight: 500;
  font-size: 0.9rem;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .main-wrap {
    margin-left: 0;
  }

  .mobile-menu-btn {
    display: block;
  }

  .page-content {
    padding: 20px 16px;
  }

  .topbar {
    padding: 0 16px;
  }

  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }

  .opp-hero {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .opp-hero-badges { justify-content: center; }

  .form-row {
    flex-direction: column;
  }

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

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

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 99;
}

.sidebar-overlay.visible {
  display: block;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ===== Compliance / Cost breakdown ===== */
.breakdown-table {
  width: 100%;
  border-collapse: collapse;
}

.breakdown-table td {
  padding: 8px 0;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border-light);
}

.breakdown-table td:last-child {
  text-align: right;
  font-weight: 500;
}

.breakdown-table tr:last-child td {
  border-bottom: none;
  font-weight: 700;
}

/* ===== Provider Help Guide ===== */
.provider-help-guide {
  margin-top: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: var(--transition);
}

.provider-help-guide summary {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
  list-style: none;
  display: flex;
  align-items: center;
  user-select: none;
  transition: background var(--transition);
}

.provider-help-guide summary::-webkit-details-marker { display: none; }

.provider-help-guide summary::after {
  content: '';
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(-45deg);
  transition: transform 0.2s ease;
}

.provider-help-guide[open] summary::after {
  transform: rotate(45deg);
}

.provider-help-guide summary:hover {
  background: rgba(0, 113, 227, 0.04);
}

.help-guide-body {
  padding: 4px 14px 14px;
  animation: helpSlideIn 0.2s ease;
}

@keyframes helpSlideIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.help-steps {
  padding-left: 20px;
  margin: 0;
}

.help-steps li {
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.help-steps li a {
  color: var(--accent);
  font-weight: 500;
}

.help-steps li code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.78rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.help-note {
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(255, 159, 10, 0.08);
  border-left: 3px solid var(--orange);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
}
