:root {
  --primary: #1d4ed8;
  --primary-light: #3b82f6;
  --primary-dark: #1e40af;
  --primary-bg: #eff6ff;
  --secondary: #64748b;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --purple: #7c3aed;
  --teal: #0d9488;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

/* ===== TOP NAV ===== */
.top-nav {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 20px;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: white; z-index: 100;
}
.nav-left { display: flex; align-items: center; gap: 12px; }
.nav-logo { height: 30px; }
.nav-title { font-weight: 700; font-size: 15px; letter-spacing: -0.3px; }
.nav-env {
  background: rgba(59,130,246,0.25); color: #93c5fd;
  padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.nav-right { display: flex; align-items: center; }
.agent-badge {
  background: rgba(255,255,255,0.1); color: #cbd5e1;
  padding: 5px 12px; border-radius: 16px; font-size: 12px; font-weight: 500;
  display: flex; align-items: center; gap: 6px;
}

/* ===== LAYOUT ===== */
.app-layout { display: flex; height: calc(100vh - 56px); }

/* ===== SIDEBAR ===== */
.sidebar {
  width: 220px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 12px; flex-shrink: 0; overflow-y: auto;
}
.sidebar-section { margin-bottom: 20px; }
.sidebar-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text-muted); padding: 8px 14px 4px;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; border-radius: 6px;
  text-decoration: none; color: var(--text-muted); font-size: 13px; font-weight: 500;
  transition: all 0.12s;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-bg); color: var(--primary); }
.nav-item i { width: 18px; text-align: center; font-size: 13px; }

/* ===== MAIN ===== */
.main-content { flex: 1; overflow-y: auto; padding: 24px 28px; }

.view { display: none; }
.view.active { display: block; }
.view-header { margin-bottom: 20px; }
.view-header h1 { font-size: 22px; font-weight: 700; }
.view-header .subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; display: block; }
.view-header-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.view-header-row h1 { font-size: 22px; font-weight: 700; }
.view-header-row .subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; display: block; }

/* ===== STATS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 14px;
  border-left: 3px solid transparent;
}
.stat-card.blue { border-left-color: var(--primary); }
.stat-card.green { border-left-color: var(--success); }
.stat-card.purple { border-left-color: var(--purple); }
.stat-card.orange { border-left-color: var(--warning); }
.stat-card.teal { border-left-color: var(--teal); }
.stat-icon {
  width: 42px; height: 42px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 17px;
}
.stat-icon.blue { background: #dbeafe; color: var(--primary); }
.stat-icon.green { background: #d1fae5; color: var(--success); }
.stat-icon.purple { background: #ede9fe; color: var(--purple); }
.stat-icon.orange { background: #fed7aa; color: var(--warning); }
.stat-icon.teal { background: #ccfbf1; color: var(--teal); }
.stat-value { font-size: 24px; font-weight: 700; display: block; }
.stat-label { font-size: 12px; color: var(--text-muted); }

/* ===== CARDS ===== */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.card-body { padding: 16px 18px; }
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ===== TABLES ===== */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 9px 12px; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--text-muted); border-bottom: 2px solid var(--border); font-weight: 600;
}
.data-table td {
  padding: 10px 12px; font-size: 13px; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:hover { background: var(--bg); }
.data-table tr { cursor: pointer; }
.data-table .id-cell { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; color: var(--primary); }
.data-table .name-cell { font-weight: 600; }
.data-table .desc-cell { color: var(--text-muted); max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== BADGES ===== */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; text-transform: capitalize;
}
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #d1fae5; color: #059669; }
.badge-orange { background: #fed7aa; color: #92400e; }
.badge-red { background: #fee2e2; color: #dc2626; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-purple { background: #ede9fe; color: #6d28d9; }
.badge-teal { background: #ccfbf1; color: #0d9488; }

/* ===== LIFECYCLE BAR ===== */
.lifecycle-bar {
  display: flex; height: 32px; border-radius: 6px; overflow: hidden; margin-bottom: 8px;
}
.lifecycle-segment { display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: white; min-width: 32px; }
.lifecycle-segment.active { background: var(--success); }
.lifecycle-segment.retired { background: var(--secondary); }
.lifecycle-segment.design { background: var(--primary-light); }
.lifecycle-segment.other { background: var(--warning); }
.lifecycle-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 4px; }
.lifecycle-legend-item { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-muted); }
.lifecycle-legend-dot { width: 10px; height: 10px; border-radius: 3px; }

/* ===== CATALOG CARDS ===== */
.catalog-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.catalog-card {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); border-top: 3px solid var(--primary);
  transition: box-shadow 0.15s;
}
.catalog-card:hover { box-shadow: var(--shadow-lg); }
.catalog-card h3 { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.catalog-card .cc-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.catalog-card .cc-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.catalog-card .cc-categories { display: flex; flex-wrap: wrap; gap: 4px; }

/* ===== CATEGORY TREE ===== */
.cat-tree { }
.cat-tree-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s;
}
.cat-tree-item:hover { background: var(--bg); }
.cat-tree-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 15px; }
.cat-tree-info { flex: 1; }
.cat-tree-name { font-weight: 600; font-size: 14px; }
.cat-tree-meta { font-size: 12px; color: var(--text-muted); }
.cat-offering-count {
  background: var(--primary-bg); color: var(--primary); padding: 3px 10px;
  border-radius: 12px; font-size: 12px; font-weight: 600;
}

/* ===== RELATIONSHIP MAP ===== */
.rel-graph {
  background: var(--surface); border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow); min-height: 200px;
}
.rel-node {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 500;
  margin: 4px;
}
.rel-node.catalog { background: #dbeafe; color: #1d4ed8; }
.rel-node.category { background: #d1fae5; color: #059669; }
.rel-node.offering { background: #ede9fe; color: #6d28d9; }
.rel-node.spec { background: #fed7aa; color: #92400e; }
.rel-node.price { background: #ccfbf1; color: #0d9488; }
.rel-section { margin-bottom: 16px; }
.rel-section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 6px; }
.rel-connector { color: var(--text-muted); font-size: 18px; text-align: center; padding: 4px 0; }

/* ===== FILTERS ===== */
.filters { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; align-items: end; }
.filter-group label { display: block; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 3px; }
.filter-group select, .filter-group input {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; background: var(--surface); min-width: 160px;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 14px; border-radius: 6px; font-size: 13px;
  font-weight: 500; border: none; cursor: pointer; transition: all 0.12s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn-icon { padding: 5px 8px; background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; }
.btn-icon:hover { color: var(--primary); }

/* ===== MODAL ===== */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.modal-content {
  position: relative; background: var(--surface); border-radius: 12px;
  width: 90%; max-width: 600px; max-height: 85vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-content.modal-wide { max-width: 800px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-header h2 { font-size: 17px; }
.modal-close { border: none; background: none; cursor: pointer; font-size: 16px; color: var(--text-muted); }
.modal-body { padding: 18px 20px; }
.detail-row { display: flex; padding: 7px 0; border-bottom: 1px solid var(--border); }
.detail-label { width: 140px; font-size: 12px; color: var(--text-muted); font-weight: 600; flex-shrink: 0; text-transform: uppercase; letter-spacing: 0.3px; }
.detail-value { flex: 1; font-size: 13px; word-break: break-word; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.3px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 13px; font-family: inherit; outline: none;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary-light); box-shadow: 0 0 0 2px rgba(59,130,246,0.1);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 2000;
  padding: 12px 18px; border-radius: var(--radius);
  background: #1e293b; color: white; font-size: 13px;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 8px;
  animation: slideUp 0.25s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ===== LOADING ===== */
.loading-spinner { text-align: center; padding: 28px; color: var(--text-muted); font-size: 13px; }

/* ===== PRICE TABLE ===== */
.price-value { font-weight: 700; font-size: 15px; color: var(--primary); }

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
