/* ============================================================
   DealHub — Main Stylesheet v1.2
   ============================================================ */

:root {
  --sidebar-w:         240px;
  --sidebar-w-collapsed: 60px;
  --topbar-h:          52px;
  --transition:        .22s ease;

  --bg:        #f5f6f8;
  --surface:   #ffffff;
  --surface2:  #f0f1f4;
  --border:    #e3e5eb;
  --border2:   #d0d3dc;

  --text-primary:   #1a1d27;
  --text-secondary: #5a5f72;
  --text-muted:     #9498a8;

  --accent:       #1a3a5c;
  --accent-light: #2557a7;
  --accent-hover: #122840;
  --accent-soft:  #eaf0f8;

  --success-bg: #f0fdf4; --success: #15803d;
  --warning-bg: #fffbeb; --warning: #b45309;
  --danger-bg:  #fef2f2; --danger:  #b91c1c;

  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 1px 4px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,.08), 0 8px 32px rgba(0,0,0,.06);

  --font:      'DM Sans', -apple-system, sans-serif;
  --font-mono: 'DM Mono', monospace;
}

*, *::before, *::after { box-sizing: border-box; }
body { font-family: var(--font); background: var(--bg); color: var(--text-primary); font-size: 14px; line-height: 1.6; margin: 0; }

/* ── Sidebar ──────────────────────────────────────────────── */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--accent);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  transition: width var(--transition);
  overflow: hidden;
}

/* Collapsed state */
body.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .nav-text,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .brand-name { display: none; }
body.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 16px 0; }
body.sidebar-collapsed .sidebar-nav .nav-link { justify-content: center; padding: 10px 0; }
body.sidebar-collapsed .sidebar-footer .nav-link { justify-content: center; padding: 10px 0; }
body.sidebar-collapsed .user-avatar { margin: 0; }
body.sidebar-collapsed .logout-btn { display: none; }
body.sidebar-collapsed .sidebar-collapse-btn { left: calc(var(--sidebar-w-collapsed) - 14px); }
body.sidebar-collapsed .sidebar-collapse-btn #collapseIcon { transform: rotate(180deg); }
body.sidebar-collapsed .main-content { margin-left: var(--sidebar-w-collapsed); }

/* Sidebar brand */
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  flex-shrink: 0;
}
.brand-logo { width: 34px; height: 34px; object-fit: contain; border-radius: 6px; background: white; padding: 2px; flex-shrink: 0; }
.brand-name { font-size: 14px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; }

/* Sidebar nav */
.sidebar-nav { flex: 1; padding: 10px 8px; overflow-y: auto; overflow-x: hidden; }
.nav-label {
  font-size: 10px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase;
  color: rgba(255,255,255,.35); padding: 14px 10px 4px; white-space: nowrap;
}
.sidebar-nav .nav-link {
  display: flex; align-items: center; gap: 10px;
  color: rgba(255,255,255,.72); padding: 7px 10px;
  border-radius: var(--radius-sm); text-decoration: none;
  font-size: 13px; font-weight: 400;
  transition: background .15s, color .15s;
  margin-bottom: 2px; white-space: nowrap;
}
.sidebar-nav .nav-link i { font-size: 15px; flex-shrink: 0; width: 18px; text-align: center; }
.sidebar-nav .nav-link:hover { background: rgba(255,255,255,.12); color: #fff; }
.sidebar-nav .nav-link.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 500; }

/* Sidebar footer */
.sidebar-footer {
  padding: 10px 8px;
  border-top: 1px solid rgba(255,255,255,.1);
  flex-shrink: 0;
}
.sidebar-footer .nav-link { margin-bottom: 0; overflow: hidden; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 7px;
  background: rgba(255,255,255,.2); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px; flex-shrink: 0;
}
.logout-btn { color: rgba(255,255,255,.45); text-decoration: none; font-size: 15px; padding: 2px 4px; }
.logout-btn:hover { color: #fff; }

/* Collapse toggle button (desktop) */
.sidebar-collapse-btn {
  position: fixed;
  top: 18px;
  left: calc(var(--sidebar-w) - 14px);
  z-index: 200;
  width: 26px; height: 26px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 11px; color: var(--text-secondary);
  transition: left var(--transition), box-shadow .15s;
  box-shadow: var(--shadow);
}
.sidebar-collapse-btn:hover { box-shadow: var(--shadow-md); color: var(--accent); }
.sidebar-collapse-btn #collapseIcon { transition: transform var(--transition); }

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

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 14px; font-weight: 600; color: var(--text-primary); flex: 1; }
.sidebar-toggle { display: none; background: none; border: none; font-size: 20px; color: var(--text-secondary); cursor: pointer; }

.content-area { padding: 20px; flex: 1; }

/* ── Cards ────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: transparent; border-radius: var(--radius) var(--radius) 0 0;
}
.card-header-title { font-size: 13.5px; font-weight: 600; color: var(--text-primary); }
.card-body { padding: 16px; }

/* ── Stat tiles (dashboard) ──────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(175px, 1fr)); gap: 12px; }
.stat-tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  text-decoration: none; display: block;
  transition: box-shadow .15s, transform .15s;
}
.stat-tile:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-tile-header { margin-bottom: 8px; }
.stat-tile-value { font-size: 30px; font-weight: 700; font-family: var(--font-mono); line-height: 1; margin-bottom: 5px; }
.stat-tile-label { font-size: 11.5px; font-weight: 500; color: var(--text-muted); letter-spacing: .2px; }

/* ── Compact filter bar ───────────────────────────────────── */
.filter-bar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-group { display: flex; flex-direction: column; gap: 2px; }
.filter-group .form-label { font-size: 11px; margin-bottom: 0; }
.filter-actions { display: flex; gap: 6px; align-items: center; margin-left: auto; }
.filter-info { display: flex; align-items: center; gap: 6px; }
.form-control-sm, .form-select-sm { font-size: 13px !important; padding: 4px 8px !important; }

/* Select2 compact overrides */
.select2-container--bootstrap-5 .select2-selection--multiple {
  min-height: 30px !important; padding: 2px 6px !important; font-size: 13px !important;
}
.select2-container--bootstrap-5 .select2-selection--single {
  height: 30px !important; padding: 3px 8px !important; font-size: 13px !important;
}

/* ── Tables ────────────────────────────────────────────────── */
.table-responsive { border-radius: 0 0 var(--radius) var(--radius); }
.table { margin-bottom: 0; font-size: 13px; }
.table thead th {
  background: var(--surface2); color: var(--text-secondary);
  font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
  border-bottom: 1px solid var(--border); padding: 8px 12px; white-space: nowrap;
}
.table tbody tr { border-bottom: 1px solid var(--border); }
.table tbody tr:last-child { border-bottom: none; }
.table tbody td { padding: 8px 12px; vertical-align: middle; }
.table tbody tr:hover { background: var(--accent-soft); }

/* Sort links in headers */
.sort-link { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.sort-link:hover { color: var(--accent); }
.sort-icon { font-size: 10px; opacity: .6; }

/* ── Badges ───────────────────────────────────────────────── */
.badge-status { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-active    { background: #dcfce7; color: #15803d; }
.badge-passed    { background: #fee2e2; color: #991b1b; }
.badge-hold      { background: #fef9c3; color: #854d0e; }
.badge-portfolio { background: #dbeafe; color: #1e40af; }
.badge-default   { background: var(--surface2); color: var(--text-secondary); }

/* ── Forms ────────────────────────────────────────────────── */
.form-label { font-size: 12px; font-weight: 500; color: var(--text-secondary); margin-bottom: 4px; }
.form-control, .form-select {
  border: 1px solid var(--border2); border-radius: var(--radius-sm);
  font-size: 13.5px; padding: 6px 10px;
  background: var(--surface); color: var(--text-primary);
  transition: border-color .15s, box-shadow .15s;
  /* Bootstrap default width:100% retained — use explicit max-width or
     width on the element or its container to constrain where needed */
}
/* Filter bar inputs: shrink to fit content, with sensible min/max */
.filter-bar .form-control,
.filter-bar .form-select {
  width: auto;
  min-width: 140px;
}
/* Inline search/filter inputs used standalone (not in grid cols) */
.input-inline { width: auto !important; }
.form-control:focus, .form-select:focus {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(37,87,167,.1); outline: none;
}
.input-group-text { background: var(--surface2); border-color: var(--border2); font-size: 13px; }
.form-section-title {
  font-size: 11.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-secondary);
  margin-bottom: 12px;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn { border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; padding: 6px 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-icon { padding: 4px 7px; }

/* ── Kanban ───────────────────────────────────────────────── */
.kanban-wrapper { overflow-x: auto; padding-bottom: 12px; }
.kanban-board { display: flex; gap: 12px; min-width: max-content; align-items: flex-start; }
.kanban-col { width: 210px; background: var(--surface2); border-radius: var(--radius); border: 1px solid var(--border); flex-shrink: 0; }
.kanban-col-header { padding: 9px 11px; font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .4px; display: flex; justify-content: space-between; border-bottom: 1px solid var(--border); }
.kanban-col-count { background: var(--border); border-radius: 10px; padding: 0 6px; font-size: 11px; }
.kanban-col-body { padding: 8px; min-height: 100px; }
.kanban-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px; margin-bottom: 7px; cursor: pointer; transition: box-shadow .15s; text-decoration: none; display: block; color: var(--text-primary); }
.kanban-card:hover { box-shadow: var(--shadow-md); color: var(--accent); }
.kanban-card-name { font-size: 12.5px; font-weight: 500; margin-bottom: 3px; }
.kanban-card-meta { font-size: 11px; color: var(--text-muted); }

/* ── Notes ────────────────────────────────────────────────── */
.note-stream { display: flex; flex-direction: column; gap: 14px; }
.note-item { display: flex; gap: 10px; }
.note-avatar { width: 28px; height: 28px; border-radius: 7px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 11px; flex-shrink: 0; margin-top: 2px; }
.note-body { flex: 1; }
.note-header { display: flex; gap: 8px; align-items: baseline; margin-bottom: 3px; }
.note-author { font-size: 13px; font-weight: 600; }
.note-time { font-size: 11px; color: var(--text-muted); }
.note-content { font-size: 13.5px; line-height: 1.6; }
.note-content p { margin-bottom: 3px; }

/* ── Deal tabs ────────────────────────────────────────────── */
.deal-tabs .nav-tabs { border-bottom: 2px solid var(--border); }
.deal-tabs .nav-link { color: var(--text-secondary); font-size: 13px; font-weight: 500; border: none; border-bottom: 2px solid transparent; margin-bottom: -2px; padding: 7px 13px; }
.deal-tabs .nav-link.active { color: var(--accent); border-bottom-color: var(--accent); background: none; }

/* ── Quill editor ─────────────────────────────────────────── */
.ql-container { font-family: var(--font); font-size: 13.5px; min-height: 100px; border-bottom-left-radius: var(--radius-sm); border-bottom-right-radius: var(--radius-sm); }
.ql-toolbar { border-radius: var(--radius-sm) var(--radius-sm) 0 0; background: var(--surface2); }

/* ── Alert ────────────────────────────────────────────────── */
.alert { border-radius: var(--radius-sm); font-size: 13.5px; }
.alert-success { background: var(--success-bg); border-color: #bbf7d0; color: var(--success); }
.alert-danger  { background: var(--danger-bg);  border-color: #fecaca; color: var(--danger); }
.alert-warning { background: var(--warning-bg); border-color: #fde68a; color: var(--warning); }

/* ── Misc ─────────────────────────────────────────────────── */
.page-header { margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.page-header h1 { font-size: 17px; font-weight: 700; margin: 0; }
.text-muted-sm { color: var(--text-muted); font-size: 11.5px; }
.required-mark::after { content: ' *'; color: var(--danger); }
.section-divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.dl-grid { display: grid; grid-template-columns: 160px 1fr; gap: 5px 14px; }
.dl-grid dt { color: var(--text-secondary); font-size: 12px; font-weight: 500; }
.dl-grid dd { margin: 0; font-size: 13.5px; }
.fw-500 { font-weight: 500; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 992px) {
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w) !important; }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-content { margin-left: 0 !important; }
  .sidebar-toggle { display: block; }
  .sidebar-collapse-btn { display: none; }
  body.sidebar-collapsed .sidebar { width: var(--sidebar-w) !important; }
  body.sidebar-collapsed .nav-text,
  body.sidebar-collapsed .brand-name,
  body.sidebar-collapsed .nav-label { display: block; }
}
@media (max-width: 576px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .content-area { padding: 14px; }
}

/* Tooltip for collapsed sidebar icon-only links */
body.sidebar-collapsed .sidebar-nav .nav-link {
  position: relative;
}

/* ── Rich content display (overview fields) ──────────────── */
.rich-content { font-size: 13.5px; line-height: 1.7; color: var(--text-primary); }
.rich-content p { margin-bottom: 6px; }
.rich-content ul, .rich-content ol { padding-left: 20px; margin-bottom: 6px; }
.rich-content h2, .rich-content h3 { font-size: 14px; font-weight: 600; margin-bottom: 6px; }

/* ── Sidebar unread badge ─────────────────────────────────── */
.sidebar-badge {
  display: inline-flex; align-items: center; justify-content: center;
  background: #ef4444; color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px;
  padding: 0 5px; margin-left: 6px; line-height: 1;
}
