:root {
  --bg-dark: #0f172a;
  --bg-panel: #1e293b;
  --bg-card: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --border-color: #334155;
  
  --stage-qual: #8b5cf6;
  --stage-prop: #3b82f6;
  --stage-neg: #f59e0b;
  --stage-won: #10b981;
  --stage-lost: #ef4444;

  --font-family: 'Inter', sans-serif;
  --sidebar-width: 260px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { 
  font-family: var(--font-family); 
  background-color: var(--bg-dark); 
  color: var(--text-main); 
  display: flex; 
  height: 100vh; 
  overflow: hidden; 
}

/* Layout */
#app-container { display: flex; width: 100%; height: 100%; }
#sidebar { 
  width: var(--sidebar-width); 
  background-color: var(--bg-panel); 
  border-right: 1px solid var(--border-color); 
  display: flex; 
  flex-direction: column; 
  padding: 1.5rem; 
  z-index: 10; 
}
.logo { font-size: 1.5rem; font-weight: 700; margin-bottom: 2rem; display: flex; align-items: center; gap: 0.75rem; }
.logo i { color: var(--accent-primary); font-size: 1.75rem; }

#sidebar nav { flex-grow: 1; display: flex; flex-direction: column; gap: 0.5rem; }
.nav-item { 
  background: transparent; border: none; color: var(--text-muted); 
  padding: 0.75rem 1rem; text-align: left; font-size: 1rem; 
  border-radius: 0.5rem; cursor: pointer; transition: all 0.2s; 
  display: flex; align-items: center; gap: 0.75rem; font-weight: 500; font-family: var(--font-family); 
}
.nav-item:hover { background-color: rgba(99, 102, 241, 0.1); color: var(--text-main); }
.nav-item.active { background-color: var(--accent-primary); color: white; }

.sidebar-bottom { display: flex; flex-direction: column; gap: 0.5rem; margin-top: auto; border-top: 1px solid var(--border-color); padding-top: 1rem; }
.action-btn { background: transparent; border: 1px solid var(--border-color); color: var(--text-muted); padding: 0.5rem; border-radius: 0.5rem; cursor: pointer; font-size: 0.9rem; font-family: var(--font-family); transition: all 0.2s; }
.action-btn:hover { background-color: rgba(255, 255, 255, 0.05); color: var(--text-main); }
.action-btn.danger:hover { background-color: rgba(239, 68, 68, 0.1); color: #ef4444; border-color: #ef4444; }

#main-content { 
  flex: 1; overflow-y: auto; padding: 2rem; 
  background: linear-gradient(135deg, var(--bg-dark), #151e32); 
}

/* Utilities */
.view { display: none; height: 100%; flex-direction: column; animation: fadeIn 0.3s ease; }
.view.active { display: flex; }
.hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* Headers */
.view-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }
.view-title { font-size: 1.8rem; font-weight: 700; letter-spacing: -0.02em; }
.header-actions { display: flex; gap: 1rem; }
.btn-primary { background-color: var(--accent-primary); color: white; border: none; padding: 0.6rem 1.2rem; border-radius: 0.5rem; cursor: pointer; font-weight: 500; font-family: var(--font-family); display: flex; align-items: center; gap: 0.5rem; transition: background 0.2s, transform 0.1s; }
.btn-primary:hover { background-color: var(--accent-primary-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary { background-color: var(--bg-card); color: var(--text-main); border: 1px solid var(--border-color); padding: 0.6rem 1.2rem; border-radius: 0.5rem; cursor: pointer; font-weight: 500; font-family: var(--font-family); transition: background 0.2s; }
.btn-secondary:hover { background-color: rgba(255, 255, 255, 0.1); }
.btn-danger { background-color: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid #ef4444; padding: 0.6rem 1.2rem; border-radius: 0.5rem; cursor: pointer; font-weight: 500; font-family: var(--font-family); transition: all 0.2s; }
.btn-danger:hover { background-color: #ef4444; color: white; }

/* Dashboard */
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }
.kpi-card { background-color: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 1rem; padding: 1.5rem; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); transition: transform 0.2s; }
.kpi-card:hover { transform: translateY(-3px); }
.kpi-title { font-size: 0.9rem; color: var(--text-muted); font-weight: 500; margin-bottom: 0.5rem; text-transform: uppercase; letter-spacing: 0.05em; }
.kpi-value { font-size: 2rem; font-weight: 700; color: var(--text-main); }
.dashboard-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.chart-container { background-color: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 1rem; padding: 1.5rem; min-height: 350px; display: flex; flex-direction: column; align-items: center; justify-content: center;}
.chart-title { width: 100%; text-align: left; font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; color: var(--text-main); }

/* Directory Tables */
.toolbar { display: flex; gap: 1rem; margin-bottom: 1.5rem; }
.search-bar { background: var(--bg-dark); border: 1px solid var(--border-color); color: var(--text-main); padding: 0.6rem 1rem; border-radius: 0.5rem; width: 300px; font-family: var(--font-family); outline: none; }
.search-bar:focus { border-color: var(--accent-primary); }
.table-container { background-color: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 1rem; overflow-x: auto; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); }
.data-table { width: 100%; border-collapse: collapse; text-align: left; }
.data-table th { padding: 1rem 1.5rem; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border-color); text-transform: uppercase; letter-spacing: 0.05em; }
.data-table td { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border-color); font-size: 0.95rem; }
.data-table tbody tr { transition: background-color 0.2s; cursor: pointer; }
.data-table tbody tr:hover { background-color: rgba(255, 255, 255, 0.03); }

/* Pipeline Kanban */
.pipeline-board { display: flex; gap: 1.25rem; overflow-x: auto; height: 100%; padding-bottom: 1rem; }
.pipeline-col { background-color: rgba(30, 41, 59, 0.5); border-radius: 0.75rem; width: 320px; min-width: 320px; display: flex; flex-direction: column; border: 1px dashed var(--border-color); }
.pipeline-col-header { padding: 1rem; border-bottom: 1px solid var(--border-color); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.col-count { background: var(--bg-card); padding: 0.2rem 0.6rem; border-radius: 1rem; font-size: 0.8rem; }
.pipeline-cards { padding: 1rem; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1rem; min-height: 50px; }
.deal-card { background-color: var(--bg-card); padding: 1.25rem; border-radius: 0.5rem; cursor: grab; box-shadow: 0 2px 4px rgba(0,0,0,0.2); border-left: 4px solid var(--accent-primary); transition: transform 0.1s; }
.deal-card:active { cursor: grabbing; transform: scale(0.98); }
.deal-card.dragging { opacity: 0.5; }
.deal-title { font-weight: 600; margin-bottom: 0.25rem; }
.deal-account { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.75rem; }
.deal-meta { display: flex; justify-content: space-between; font-size: 0.9rem; font-weight: 500; }
.col-qual { border-left-color: var(--stage-qual); }
.col-prop { border-left-color: var(--stage-prop); }
.col-neg { border-left-color: var(--stage-neg); }
.col-won { border-left-color: var(--stage-won); }
.col-lost { border-left-color: var(--stage-lost); }

/* Slide-out Panel */
#detail-panel-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 40; backdrop-filter: blur(2px); }
#detail-panel { position: fixed; right: 0; top: 0; height: 100vh; width: 500px; background-color: var(--bg-panel); border-left: 1px solid var(--border-color); z-index: 50; box-shadow: -4px 0 15px rgba(0,0,0,0.3); transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); display: flex; flex-direction: column; }
#detail-panel.open { transform: translateX(0); }
#detail-panel-header { padding: 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
#btn-close-panel { background: none; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; transition: color 0.2s; }
#btn-close-panel:hover { color: white; }
#detail-panel-body { padding: 1.5rem; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 1.5rem; }
.info-group { display: flex; flex-direction: column; gap: 0.25rem; }
.info-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; font-weight: 600; }
.info-value { font-size: 1rem; color: var(--text-main); }
.activity-timeline { display: flex; flex-direction: column; gap: 1rem; border-left: 2px solid var(--border-color); padding-left: 1.5rem; position: relative; margin-top: 1rem; }
.activity-item { position: relative; }
.activity-item::before { content: ''; position: absolute; left: -1.85rem; top: 0.25rem; width: 10px; height: 10px; border-radius: 50%; background: var(--accent-primary); border: 2px solid var(--bg-panel); }
.activity-date { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.25rem; }
.activity-text { font-size: 0.9rem; background: var(--bg-card); padding: 0.75rem; border-radius: 0.5rem; line-height: 1.4; }

/* Modals */
#modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 100; backdrop-filter: blur(3px); }
#modal-container { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 110; background: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 1rem; width: 550px; max-width: 90vw; max-height: 90vh; overflow-y: auto; box-shadow: 0 10px 25px rgba(0,0,0,0.5); }
.modal-header { padding: 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-size: 1.25rem; font-weight: 600; }
.modal-body { padding: 1.5rem; }
.modal-footer { padding: 1.5rem; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 1rem; }

/* Forms & Inputs */
.form-group { margin-bottom: 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; }
.form-label { font-size: 0.85rem; font-weight: 500; color: var(--text-muted); }
.form-control { background: var(--bg-dark); border: 1px solid var(--border-color); padding: 0.75rem; border-radius: 0.5rem; color: var(--text-main); font-family: var(--font-family); font-size: 0.95rem; outline: none; transition: border-color 0.2s; }
.form-control:focus { border-color: var(--accent-primary); }
select.form-control { appearance: none; background-image: url('data:image/svg+xml;utf8,<svg fill="%2394a3b8" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/><path d="M0 0h24v24H0z" fill="none"/></svg>'); background-repeat: no-repeat; background-position: right 0.5rem center; padding-right: 2rem; }

/* Tabs */
.tabs { display: flex; gap: 1rem; border-bottom: 1px solid var(--border-color); margin-bottom: 1.5rem; }
.tab-btn { background: none; border: none; padding: 0.75rem 1rem; color: var(--text-muted); font-family: var(--font-family); font-size: 1rem; font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.2s; }
.tab-btn:hover { color: var(--text-main); }
.tab-btn.active { color: var(--accent-primary); border-bottom-color: var(--accent-primary); }

/* Quotes Specific */
.line-item-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 1rem; align-items: center; margin-bottom: 1rem; }
.quote-totals { margin-top: 2rem; border-top: 1px solid var(--border-color); padding-top: 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; align-items: flex-end; }
.quote-total-row { display: flex; justify-content: space-between; width: 250px; font-size: 0.95rem; }
.quote-total-row.grand-total { font-size: 1.25rem; font-weight: 700; color: var(--accent-primary); border-top: 1px solid var(--border-color); padding-top: 0.5rem; margin-top: 0.5rem; }

/* Print Styles for Quotes */
@media print {
  body { background: white; color: black; }
  #sidebar, .header-actions, .toolbar, .tabs, .nav-item { display: none !important; }
  #main-content { padding: 0; background: white; }
  .view { display: flex !important; }
  .table-container { box-shadow: none; border: none; }
  .data-table th, .data-table td { color: black; border-bottom: 1px solid #ccc; }
  .btn-primary, .btn-secondary { display: none; }
}

/* Responsive */
@media (max-width: 768px) {
  #sidebar { position: fixed; transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }
  #detail-panel { width: 100%; }
  .dashboard-charts { grid-template-columns: 1fr; }
  .line-item-row { grid-template-columns: 1fr; gap: 0.5rem; }
}
