/* TradeReach v2 - Main CSS */
:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-secondary: #718096;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --sidebar-bg: #1e293b;
  --sidebar-text: #e2e8f0;
  --sidebar-hover: #334155;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

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

/* Sidebar */
.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.brand {
  padding: 20px 16px;
  border-bottom: 1px solid var(--sidebar-hover);
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
  flex-shrink: 0;
}

.brand-text strong { font-size: 14px; display: block; }
.brand-text span { font-size: 11px; opacity: 0.6; }

.nav-list { padding: 8px; flex: 1; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px;
  border: none; background: none;
  color: var(--sidebar-text);
  font-size: 13px; cursor: pointer;
  border-radius: var(--radius);
  text-align: left;
  transition: background 0.15s;
}

.nav-item:hover { background: var(--sidebar-hover); }
.nav-item.active { background: var(--primary); color: #fff; }

.nav-icon { font-size: 11px; opacity: 0.7; width: 20px; text-align: center; }

.nav-section { padding: 16px 12px 4px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.4; }

/* Main */
.main {
  margin-left: 220px;
  flex: 1;
  padding: 24px;
  min-height: 100vh;
}

.topbar {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 24px;
  gap: 16px;
}

.title-block h1 { font-size: 22px; font-weight: 700; }
.title-block p { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text);
  transition: all 0.15s;
}

.btn:hover { background: var(--bg); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.success { background: var(--success); color: #fff; border-color: var(--success); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.compact { padding: 4px 8px; font-size: 11px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

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

.card-header h3 { font-size: 15px; }

/* Grid */
.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; }

.metric { text-align: center; padding: 16px; }
.metric-value { font-size: 28px; font-weight: 700; color: var(--primary); }
.metric-label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* Table */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--bg); font-weight: 600; font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }
tr:hover { background: #f8fafc; }

/* Badges */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px;
  font-size: 11px; font-weight: 500;
}
.badge-new { background: #dbeafe; color: #1e40af; }
.badge-drafted { background: #fef3c7; color: #92400e; }
.badge-sent { background: #d1fae5; color: #065f46; }
.badge-replied { background: #e0e7ff; color: #3730a3; }
.badge-blocked { background: #fee2e2; color: #991b1b; }
.badge-review { background: #fef3c7; color: #92400e; }
.badge-approved { background: #d1fae5; color: #065f46; }
.badge-archived { background: #f3f4f6; color: #6b7280; }

/* Forms */
input, select, textarea {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px; font-family: var(--font);
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; color: var(--text-secondary); }

.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }

/* Modal */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 640px; width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
}

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

.modal-header h2 { font-size: 18px; }

.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Progress */
.progress-bar {
  background: var(--bg); border-radius: var(--radius);
  height: 6px; overflow: hidden; margin: 12px 0;
}

.progress-fill {
  background: var(--primary);
  height: 100%; border-radius: var(--radius);
  transition: width 0.3s ease;
}

.progress-event {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; font-size: 12px; color: var(--text-secondary);
}

.progress-event .stage { font-weight: 600; color: var(--text); min-width: 60px; }

/* Toast */
.toast-container {
  position: fixed; top: 16px; right: 16px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
}

.toast {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 13px; box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease;
  max-width: 360px;
}

.toast-success { background: #d1fae5; color: #065f46; border-left: 4px solid var(--success); }
.toast-error { background: #fee2e2; color: #991b1b; border-left: 4px solid var(--danger); }
.toast-info { background: #dbeafe; color: #1e40af; border-left: 4px solid var(--primary); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Hidden utility */
.hidden { display: none !important; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { width: 56px; }
  .sidebar .brand-text, .nav-item { justify-content: center; }
  .nav-item span:not(.nav-icon) { display: none; }
  .nav-section { display: none; }
  .main { margin-left: 56px; padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* Acquisition results */
.discovery-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px;
  margin-top: 16px;
}

.discovery-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow);
}

.discovery-card h4 { font-size: 14px; margin-bottom: 4px; }
.discovery-card .meta { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.discovery-card .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.discovery-card .tag { font-size: 10px; padding: 2px 6px; background: var(--bg); border-radius: 4px; }
.discovery-card .actions { display: flex; gap: 6px; margin-top: 10px; }

/* Config checklist */
.config-status { margin-bottom: 8px; }
.config-status .item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; font-size: 13px; border-bottom: 1px solid var(--border);
}
.config-status .item .icon { margin-right: 6px; }
.config-status .item .ready { color: var(--success); }
.config-status .item .missing { color: var(--text-secondary); }

/* Dashboard activity */
.activity-list { list-style: none; }
.activity-item {
  display: flex; gap: 10px; padding: 8px 0;
  font-size: 13px; border-bottom: 1px solid var(--border);
}
.activity-item .time { color: var(--text-secondary); font-size: 11px; white-space: nowrap; }

/* Job status */
.job-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.job-item .info { flex: 1; }
.job-item .info strong { font-size: 14px; }
.job-item .info p { font-size: 12px; color: var(--text-secondary); }

/* Tab bar */
.tab-bar { display: flex; gap: 0; margin-bottom: 16px; border-bottom: 2px solid var(--border); }
.tab-btn {
  padding: 8px 16px; border: none; background: none;
  font-size: 13px; cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
