/* ==========================================================================
   SalesFlow CRM - application styles
   Built on top of Bootstrap 5.3; only the app shell and a few components
   are defined here so the CDN bundle does the heavy lifting.
   ========================================================================== */

:root {
  --sf-sidebar-w: 256px;
  --sf-topbar-h: 62px;
  --sf-sidebar-bg: #1b2138;
  --sf-sidebar-bg-2: #232a45;
  --sf-primary: #4e73df;
  --sf-radius: 12px;
  --sf-shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
}

body {
  background: #f5f6fa;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: .925rem;
  color: #2b2f3a;
}

/* ---------------------------------------------------------------- shell -- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sf-sidebar-w);
  background: var(--sf-sidebar-bg);
  color: #cfd4e6;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1045;
  transition: transform .2s ease;
}

.sidebar-brand {
  height: var(--sf-topbar-h);
  display: flex;
  align-items: center;
  gap: .625rem;
  padding: 0 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.sidebar-brand a { display: flex; align-items: center; gap: .625rem; color: #fff; text-decoration: none; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  background: linear-gradient(135deg, #4e73df, #6f42c1);
  color: #fff; font-size: 1.05rem;
}
.brand-text { font-weight: 600; font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem .625rem 1.5rem; }
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .15); border-radius: 3px; }

.nav-section {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  color: #6f7799; padding: 1rem .75rem .375rem; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: .7rem;
  padding: .55rem .75rem; margin-bottom: 2px;
  border-radius: 8px; color: #b9c0d8; text-decoration: none;
  font-size: .89rem; transition: background .12s, color .12s;
}
.nav-item i { font-size: 1.02rem; width: 20px; text-align: center; flex: none; }
.nav-item:hover { background: var(--sf-sidebar-bg-2); color: #fff; }
.nav-item.active { background: var(--sf-primary); color: #fff; font-weight: 500; }
.nav-badge {
  margin-left: auto; background: #e74a3b; color: #fff;
  border-radius: 999px; font-size: .68rem; font-weight: 600;
  min-width: 20px; padding: .1rem .35rem; text-align: center;
}
.nav-item.active .nav-badge { background: rgba(255, 255, 255, .25); }

.sidebar-foot { padding: .75rem 1rem; border-top: 1px solid rgba(255, 255, 255, .07); }

.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(10, 14, 30, .5); z-index: 1044;
}
.sidebar-backdrop.show { display: block; }

.app-main {
  flex: 1; min-width: 0;
  margin-left: var(--sf-sidebar-w);
  display: flex; flex-direction: column;
}

/* --------------------------------------------------------------- topbar -- */
.topbar {
  height: var(--sf-topbar-h);
  background: #fff;
  border-bottom: 1px solid #e6e8f0;
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1rem;
  position: sticky; top: 0; z-index: 1030;
}
.topbar-search { position: relative; flex: 1; max-width: 460px; }
.topbar-search i { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: #98a2b3; }
.topbar-search .form-control { padding-left: 2.25rem; background: #f5f6fa; border-color: transparent; }
.topbar-search .form-control:focus { background: #fff; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .4rem; }

.btn-icon {
  width: 38px; height: 38px; padding: 0;
  display: inline-grid; place-items: center;
  border-radius: 9px; border: 0; background: transparent; color: #4a5068;
  font-size: 1.1rem;
}
.btn-icon:hover { background: #f0f2f8; color: #1b2138; }
.btn-icon.d-flex { width: auto; padding: 0 .5rem; gap: .45rem; }

.avatar {
  width: 32px; height: 32px; flex: none;
  border-radius: 50%; display: inline-grid; place-items: center;
  color: #fff; font-size: .74rem; font-weight: 700; letter-spacing: .02em;
}
.avatar-sm { width: 26px; height: 26px; font-size: .64rem; }
.avatar-lg { width: 64px; height: 64px; font-size: 1.4rem; }

.notif-dot {
  position: absolute; top: 4px; right: 4px;
  background: #e74a3b; color: #fff;
  font-size: .62rem; font-weight: 700;
  min-width: 17px; height: 17px; padding: 0 .2rem;
  border-radius: 999px; display: grid; place-items: center;
}
.notif-menu { width: min(370px, 94vw); padding: 0; }
.notif-list { max-height: 380px; overflow-y: auto; }
.notif-row {
  display: flex; gap: .65rem; padding: .7rem .9rem;
  border-bottom: 1px solid #f0f1f6; text-decoration: none; color: inherit;
}
.notif-row:hover { background: #f7f8fc; }
.notif-row.unread { background: #eef3ff; }
.notif-row .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: .4rem; flex: none; }

/* -------------------------------------------------------------- content -- */
.app-content { flex: 1; padding: 1.25rem; max-width: 1600px; width: 100%; }
.app-footer {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: .85rem 1.25rem; font-size: .8rem; color: #6b7280;
  border-top: 1px solid #e6e8f0; background: #fff;
}

.page-head {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: .75rem; margin-bottom: 1.1rem;
}
.page-head h1 { font-size: 1.32rem; font-weight: 650; margin: 0; }
.page-head .subtitle { font-size: .83rem; color: #6b7280; margin: .15rem 0 0; }
.page-head-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: .45rem; }

.card { border: 1px solid #e6e8f0; border-radius: var(--sf-radius); box-shadow: var(--sf-shadow); }
.card-header {
  background: #fff; border-bottom: 1px solid #eef0f6;
  font-weight: 600; font-size: .92rem;
  padding: .8rem 1rem; border-radius: var(--sf-radius) var(--sf-radius) 0 0;
  display: flex; align-items: center; gap: .5rem;
}
.card-header .btn { margin-left: auto; }

/* ----------------------------------------------------------- stat tiles -- */
.stat-grid {
  display: grid; gap: .85rem; margin-bottom: 1.1rem;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.stat-card {
  background: #fff; border: 1px solid #e6e8f0; border-radius: var(--sf-radius);
  padding: .95rem 1rem; box-shadow: var(--sf-shadow);
  display: flex; align-items: center; gap: .85rem; text-decoration: none; color: inherit;
}
.stat-card:hover { border-color: #ccd4ef; }
.stat-icon {
  width: 42px; height: 42px; flex: none; border-radius: 11px;
  display: grid; place-items: center; font-size: 1.2rem;
}
.stat-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: #7b8194; font-weight: 600; }
.stat-value { font-size: 1.42rem; font-weight: 700; line-height: 1.15; }
.stat-meta { font-size: .74rem; color: #8b91a4; }

/* --------------------------------------------------------------- tables -- */
.table-wrap { overflow-x: auto; }
.table { font-size: .875rem; margin: 0; }
.table > :not(caption) > * > * { padding: .62rem .75rem; vertical-align: middle; }
.table thead th {
  background: #f8f9fc; color: #5a6178;
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  font-weight: 600; white-space: nowrap; border-bottom: 1px solid #e6e8f0;
}
.table thead th a { color: inherit; text-decoration: none; }
.table thead th a:hover { color: var(--sf-primary); }
.table tbody tr:hover { background: #fafbff; }
.table .row-title { font-weight: 600; color: #1f2438; text-decoration: none; }
.table .row-title:hover { color: var(--sf-primary); }
.table-empty { padding: 2.5rem 1rem; text-align: center; color: #8b91a4; }

.status-pill {
  display: inline-block; padding: .18rem .55rem;
  border-radius: 999px; font-size: .73rem; font-weight: 600; white-space: nowrap;
}

.filter-bar {
  background: #fff; border: 1px solid #e6e8f0; border-radius: var(--sf-radius);
  padding: .8rem; margin-bottom: .9rem; box-shadow: var(--sf-shadow);
}
.filter-bar .form-control, .filter-bar .form-select { font-size: .85rem; }

.bulk-bar {
  display: none; align-items: center; gap: .5rem; flex-wrap: wrap;
  background: #eef3ff; border: 1px solid #c7d6ff;
  border-radius: var(--sf-radius); padding: .6rem .8rem; margin-bottom: .75rem;
}
.bulk-bar.show { display: flex; }

/* ------------------------------------------------------------- timeline -- */
.timeline { position: relative; padding-left: 1.9rem; }
.timeline::before {
  content: ''; position: absolute; left: .62rem; top: .35rem; bottom: .35rem;
  width: 2px; background: #e6e8f0;
}
.timeline-item { position: relative; padding-bottom: 1.05rem; }
.timeline-dot {
  position: absolute; left: -1.9rem; top: .1rem;
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: .75rem;
  color: #fff; box-shadow: 0 0 0 3px #f5f6fa;
}
.timeline-title { font-size: .87rem; font-weight: 600; }
.timeline-body { font-size: .85rem; color: #4a5068; white-space: pre-line; margin-top: .15rem; }
.timeline-time { font-size: .74rem; color: #8b91a4; }

/* ---------------------------------------------------------- quick notes -- */
.notes-grid {
  display: grid; gap: .85rem;
  grid-template-columns: repeat(auto-fill, minmax(245px, 1fr));
}
.note-card {
  border-radius: var(--sf-radius); padding: .85rem .9rem;
  border: 1px solid rgba(0, 0, 0, .06); box-shadow: var(--sf-shadow);
  display: flex; flex-direction: column; min-height: 132px;
}
.note-card.done { opacity: .55; }
.note-card.done .note-content { text-decoration: line-through; }
.note-title { font-weight: 650; font-size: .9rem; margin-bottom: .25rem; }
.note-content { font-size: .85rem; white-space: pre-wrap; word-break: break-word; flex: 1; }
.note-foot {
  display: flex; align-items: center; gap: .35rem;
  margin-top: .6rem; font-size: .73rem; color: #6b7280;
}
.note-foot .btn { --bs-btn-padding-y: .1rem; --bs-btn-padding-x: .35rem; --bs-btn-font-size: .75rem; }

/* ------------------------------------------------------------- calendar -- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: #e6e8f0; border: 1px solid #e6e8f0; border-radius: var(--sf-radius); overflow: hidden; }
.cal-head { background: #f8f9fc; padding: .5rem; text-align: center; font-size: .74rem; font-weight: 600; color: #5a6178; text-transform: uppercase; letter-spacing: .04em; }
.cal-cell { background: #fff; min-height: 104px; padding: .35rem .4rem; }
.cal-cell.muted { background: #fbfbfd; }
.cal-cell.today { background: #eef3ff; }
.cal-date { font-size: .76rem; font-weight: 600; color: #6b7280; margin-bottom: .2rem; }
.cal-cell.today .cal-date { color: var(--sf-primary); }
.cal-event {
  display: block; font-size: .72rem; padding: .12rem .35rem; margin-bottom: 2px;
  border-radius: 5px; color: #fff; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-event:hover { filter: brightness(.92); color: #fff; }

/* ----------------------------------------------------------- task board -- */
.board { display: grid; grid-template-columns: repeat(3, minmax(270px, 1fr)); gap: .85rem; }
.board-col { background: #eef0f6; border-radius: var(--sf-radius); padding: .7rem; min-height: 220px; }
.board-col h6 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: #5a6178; display: flex; align-items: center; gap: .4rem; }
.board-card {
  background: #fff; border-radius: 9px; padding: .65rem .75rem; margin-bottom: .55rem;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .08); border-left: 3px solid #adb5bd;
}
.board-card.p-high { border-left-color: #e74a3b; }
.board-card.p-medium { border-left-color: #f6c23e; }
.board-card.p-low { border-left-color: #1cc88a; }
.board-card a { color: #1f2438; font-weight: 600; font-size: .86rem; text-decoration: none; }

/* -------------------------------------------------------------- toasts --- */
.toast-stack { position: fixed; right: 1rem; bottom: 1rem; z-index: 1090; display: flex; flex-direction: column; gap: .5rem; }
.sf-toast {
  background: #fff; border-left: 4px solid var(--sf-primary);
  border-radius: 9px; box-shadow: 0 8px 24px rgba(16, 24, 40, .15);
  padding: .7rem .9rem; min-width: 260px; max-width: 380px;
  font-size: .86rem; display: flex; gap: .55rem; align-items: flex-start;
  animation: sfIn .18s ease;
}
.sf-toast.success { border-left-color: #1cc88a; }
.sf-toast.error { border-left-color: #e74a3b; }
.sf-toast.warning { border-left-color: #f6c23e; }
@keyframes sfIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------ auth page -- */
.bare-page { background: linear-gradient(135deg, #1b2138, #2d3a6b); min-height: 100vh; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; }
.auth-card { background: #fff; border-radius: 16px; box-shadow: 0 18px 50px rgba(0, 0, 0, .25); padding: 2rem; width: min(430px, 100%); }
.auth-brand { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.4rem; }
.auth-brand h1 { font-size: 1.22rem; font-weight: 650; margin: 0; }
.auth-brand p { margin: 0; font-size: .8rem; color: #6b7280; }
.auth-foot { margin: 1.1rem 0 0; font-size: .78rem; color: #6b7280; text-align: center; }

/* ------------------------------------------------------------ error page -- */
.error-page { text-align: center; padding: 3.5rem 1rem; }
.error-code { font-size: 4.5rem; font-weight: 800; color: var(--sf-primary); line-height: 1; }
.bare-page .error-page { color: #fff; }
.bare-page .error-page .text-muted { color: rgba(255, 255, 255, .7) !important; }

/* --------------------------------------------------------------- misc --- */
.detail-list { margin: 0; font-size: .87rem; }
.detail-list dt { color: #7b8194; font-weight: 500; font-size: .78rem; }
.detail-list dd { margin-bottom: .6rem; font-weight: 500; word-break: break-word; }

.progress-thin { height: 6px; border-radius: 999px; }
.text-truncate-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.chart-box { position: relative; height: 290px; }
.chart-box.sm { height: 230px; }
.cursor-pointer { cursor: pointer; }
.sortable-th { cursor: pointer; user-select: none; }

/* --------------------------------------------------------- responsive --- */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .app-main { margin-left: 0; }
  .app-content { padding: 1rem .75rem; }
  .board { grid-template-columns: 1fr; }
}

@media (max-width: 575.98px) {
  .page-head h1 { font-size: 1.12rem; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .stat-value { font-size: 1.2rem; }
  .cal-cell { min-height: 76px; }
  .app-footer { flex-direction: column; gap: .2rem; }
}

@media print {
  .sidebar, .topbar, .app-footer, .page-head-actions, .filter-bar, .no-print { display: none !important; }
  .app-main { margin-left: 0; }
  .card { box-shadow: none; border-color: #ccc; }
  body { background: #fff; }
}
