@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ============================================================
   CSS Variables / Design Tokens
   ============================================================ */
:root {
  /* Colors - Light Theme (default) */
  --bg-app:       #f9fafb;
  --bg-sidebar:   #ffffff;
  --bg-surface:   #ffffff;
  --bg-elevated:  #f3f4f6;
  --bg-hover:     #e5e7eb;

  /* Design based on the image */
  --accent:       #0b9b9b;
  --accent-hover: #087a7a;
  --accent-light: #e0f2f1;
  --success:      #10b981;
  --warning:      #f5cb62;
  --warning-text: #554100;
  --danger:       #ef4444;
  --info:         #5a6e9a;
  --info-text:    #ffffff;

  --text-primary:   #1f2937;
  --text-secondary: #4b5563;
  --text-muted:     #6b7280;

  --border:       #e5e7eb;
  --border-focus: rgba(11, 155, 155, 0.4);

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  24px;

  --shadow-sm:  0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:  0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg:  0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);

  --sidebar-width: 250px;
  --topbar-height: 64px;

  --transition: 0.2s ease;
}

[data-theme="dark"] {
  /* Colors - Dark Theme */
  --bg-app:       #0f1117;
  --bg-sidebar:   #151823;
  --bg-surface:   #1a1f2e;
  --bg-elevated:  #212638;
  --bg-hover:     #252b3b;

  --accent:       #13c9bb;
  --accent-hover: #10e0c9;
  --accent-light: rgba(19, 201, 187, 0.15);

  --success:      #10b981;
  --warning:      #f6d267;
  --warning-text: #1e293b;
  --danger:       #ef4444;
  --info:         #3b82f6;
  --info-text:    #ffffff;

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;

  --border:       rgba(255,255,255,0.07);
  --border-focus: rgba(19, 201, 187, 0.6);

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg:  0 12px 40px rgba(0,0,0,0.5);
}

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

html { height: 100%; font-size: 15px; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  height: 100%;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }
.link-neutral { color: inherit; text-decoration: none; transition: color var(--transition); }
.link-neutral:hover { color: var(--accent); }

/* ============================================================
   Layout Shell
   ============================================================ */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand .logo-text {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.sidebar-brand .logo-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 2px;
}

.sidebar-section {
  padding: 12px 12px 0;
  flex: 1;
}
.sidebar-section-title {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 8px 8px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 2px;
  text-decoration: none;
}
.nav-item:hover, .nav-item.active {
  background: var(--accent-light);
  color: var(--accent-hover);
}
.nav-item.active {
  font-weight: 600;
}
.nav-item svg, .nav-item .icon { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}
.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}
.user-card:hover { background: var(--bg-hover); }
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; flex-shrink: 0;
}
.user-info .name   { font-size: 0.8rem; font-weight: 600; }
.user-info .role   { font-size: 0.7rem; color: var(--text-muted); }

/* ============================================================
   Main Content Area
   ============================================================ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}
.topbar-title { font-weight: 700; font-size: 1.1rem; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ============================================================
   Cards / Surfaces
   ============================================================ */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title {
  font-weight: 600;
  font-size: 0.95rem;
}

/* ============================================================
   KPI / Stat Cards
   ============================================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}
.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.kpi-card.accent::before { background: linear-gradient(90deg, var(--accent), var(--accent-hover)); }
.kpi-card.success::before { background: var(--success); }
.kpi-card.warning::before { background: var(--warning); }
.kpi-card.danger::before  { background: var(--danger); }
.kpi-card.info::before    { background: var(--info); }

.kpi-label  { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-value  { font-size: 2rem;    font-weight: 800; margin-top: 8px; line-height: 1; }
.kpi-sub    { font-size: 0.75rem; color: var(--text-secondary); margin-top: 4px; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  font-family: inherit;
  line-height: 1;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99,102,241,0.4); }
.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }
.btn-success  { background: var(--success); color: white; }
.btn-success:hover:not(:disabled)  { background: #059669; }
.btn-danger   { background: var(--danger);  color: white; }
.btn-danger:hover:not(:disabled)   { background: #dc2626; }
.btn-ghost    { background: transparent; color: var(--text-secondary); padding: 6px 10px; }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-icon { padding: 7px; border-radius: var(--radius-sm); }

/* ============================================================
   Forms
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-control {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.form-control::placeholder { color: var(--text-muted); }
select.form-control option { background: var(--bg-elevated); }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

.form-error {
  font-size: 0.8rem;
  color: var(--danger);
  margin-top: 4px;
}

/* ============================================================
   Alerts (inline)
   ============================================================ */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-error   { background: rgba(239,68,68,0.12);  border: 1px solid rgba(239,68,68,0.3);  color: #fca5a5; }
.alert-success { background: rgba(16,185,129,0.12); border: 1px solid rgba(16,185,129,0.3); color: #6ee7b7; }
.alert-warning { background: rgba(245,158,11,0.12); border: 1px solid rgba(245,158,11,0.3); color: #fcd34d; }
.alert-info    { background: rgba(59,130,246,0.12); border: 1px solid rgba(59,130,246,0.3); color: #93c5fd; }
.alert:empty   { display: none; }

/* ============================================================
   Table
   ============================================================ */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 11px 14px;
  text-align: left;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}
th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--bg-elevated);
}
tbody tr { transition: background var(--transition); cursor: pointer; }
tbody tr:hover { background: var(--bg-hover); }
tbody tr:last-child td { border-bottom: none; }

/* ============================================================
   Badges / Pills
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.badge-open    { background: var(--info);  color: var(--info-text); }
.badge-won     { background: var(--success);  color: #ffffff; }
.badge-lost    { background: var(--danger);   color: #ffffff; }
.badge-overdue { background: var(--warning);  color: var(--warning-text); }
.badge-info    { background: var(--accent);  color: #ffffff; }
.badge-done    { background: var(--success); color: #ffffff; }
.badge-pending { background: var(--bg-hover); color: var(--text-secondary); }

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: min(560px, 96vw);
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px);
  transition: transform 0.2s;
}
.modal-overlay.open .modal {
  transform: translateY(0);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-close {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--bg-hover);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--danger); color: white; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Filter Bar
   ============================================================ */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.search-input {
  flex: 1;
  min-width: 200px;
}

/* ============================================================
   Empty State
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state h3 { color: var(--text-secondary); font-size: 1rem; margin-bottom: 6px; }
.empty-state p  { font-size: 0.875rem; }

/* ============================================================
   Loading Spinner
   ============================================================ */
.spinner-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Timeline (activities)
   ============================================================ */
.timeline { position: relative; padding-left: 28px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 11px; top: 0; bottom: 0;
  width: 2px;
  background: var(--border);
}
.timeline-item {
  position: relative;
  padding: 12px 0 12px 16px;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.timeline-item:last-child { border-bottom: none; }
.timeline-item.hoverable:hover {
  background: var(--bg-hover);
  margin: 0 -8px;
  padding-left: 24px;
  padding-right: 8px;
}
.timeline-dot {
  position: absolute;
  left: -21px;
  top: 16px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-surface);
}
.timeline-dot.done { background: var(--success); }
.timeline-dot.overdue { background: var(--danger); }
.timeline-meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* ============================================================
   Login Page
   ============================================================ */
.login-page {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-app);
  background-image: radial-gradient(ellipse at 20% 50%, var(--accent-light) 0%, transparent 60%),
                    radial-gradient(ellipse at 80% 20%, var(--accent-light) 0%, transparent 50%);
}
.login-box {
  width: min(440px, 94vw);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  font-size: 1.6rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 4px;
}
.login-subtitle { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 32px; }

/* ============================================================
   Opportunity Value
   ============================================================ */
.value-display {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--success);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }
  .sidebar { display: none; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/* ============================================================
   Scrollbar Styling
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   Toast Notification
   ============================================================ */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: white;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.3s ease;
  max-width: 340px;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--accent); }
@keyframes slideIn {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ============================================================
   Misc Utilities
   ============================================================ */
.text-muted    { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success  { color: var(--success); }
.text-danger   { color: var(--danger); }
.text-warning  { color: var(--warning); }
.text-accent   { color: var(--accent); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.d-flex { display: flex; align-items: center; }
.justify-between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.hidden { display: none !important; }

/* ============================================================
   Sidebar User Flyout Menu
   ============================================================ */
.user-flyout {
  position: absolute;
  bottom: 80px; 
  left: 10px;
  width: calc(100% - 20px);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  padding: 6px;
  z-index: 9999;
  transform: translateY(0);
  transition: opacity 0.2s, transform 0.2s;
}

.user-flyout.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
}

.user-flyout a {
  padding: 10px 12px;
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-flyout a:hover {
  background: var(--bg-hover);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}

.user-card:hover {
  background: var(--bg-hover);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
}

.user-info .name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.user-info .role {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ============================================================
   Tag Selection Chips
   ============================================================ */
.tag-chip {
  padding: 6px 14px;
  border-radius: 99px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}
.tag-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}
.tag-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 2px 8px rgba(11, 155, 155, 0.3);
}
