/* Mini CRM — light theme, no external dependencies */
:root {
  --bg: #f5f7fb; --card: #fff; --text: #1f2937; --muted: #6b7280; --border: #e5e7eb;
  --primary: #4f46e5; --primary-600: #4338ca; --primary-50: #eef2ff;
  --success: #059669; --danger: #dc2626; --warn: #d97706;
  --swhi: #0284c7; --bouncer: #c026d3; --both: #7c3aed;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --sidebar: 236px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.3rem; } h2 { font-size: 1.05rem; } h3 { font-size: .98rem; margin: 1rem 0 .5rem; }
code { background: #f3f4f6; padding: 1px 5px; border-radius: 4px; font-size: .85em; word-break: break-all; }
pre { white-space: pre-wrap; font: inherit; margin: .5rem 0 0; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); background: #111827; color: #d1d5db; position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 40; transition: transform .2s; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; color: #fff; padding: 1.1rem 1.2rem; font-size: 1.05rem; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #6366f1, #06b6d4); display: grid; place-items: center; color: #fff; font-weight: 800; }
.brand-lg { color: var(--text); padding: 0 0 1rem; font-size: 1.2rem; }
.sidebar nav { flex: 1; padding: .25rem .6rem; overflow-y: auto; }
.sidebar nav a { display: flex; align-items: center; gap: .7rem; color: #d1d5db; padding: .6rem .7rem; border-radius: 8px; margin-bottom: 2px; }
.sidebar nav a:hover { background: #1f2937; text-decoration: none; color: #fff; }
.sidebar nav a.active { background: #312e81; color: #fff; }
.nav-count { margin-left: auto; background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700; padding: 0 .45rem; border-radius: 999px; }
.sidebar-foot { padding: 1rem 1.2rem; border-top: 1px solid #1f2937; }
.sidebar-foot .muted { color: #9ca3af; }
.sidebar-foot .link-btn { color: #a5b4fc; padding: 0; }
.main { flex: 1; margin-left: var(--sidebar); min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 30; background: rgba(255,255,255,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 1rem; padding: .7rem 1.5rem; }
.topbar h1 { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: .5rem; align-items: center; }
.quick-search input { width: 220px; }
.menu-btn { display: none; background: none; border: 0; font-size: 1.4rem; cursor: pointer; padding: 0 .3rem; }
.content { padding: 1.5rem; max-width: 1400px; }
.sidebar-backdrop { display: none; }
.bare-main { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h2 { margin-bottom: .9rem; }

/* Cards & grids */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1.25rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .9rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }
.grid-2, .grid-3 { margin-bottom: 1.25rem; }
.page-actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1.1rem; justify-content: space-between; }
.page-actions > .btn:first-child { margin-right: auto; }
.mt { margin-top: 1.25rem; }

/* Forms */
input, select, textarea { font: inherit; font-weight: 400; color: inherit; border: 1px solid #d1d5db; border-radius: 8px; padding: .5rem .65rem; background: #fff; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-50); border-color: var(--primary); }
input[type=checkbox] { width: auto; }
input[type=color] { width: 44px; height: 38px; padding: 2px; }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; font-weight: 600; color: #374151; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1rem; }
.form-grid.one { grid-template-columns: 1fr; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.hint { font-weight: 400; font-size: .8rem; color: var(--muted); }
.form-actions { display: flex; gap: .6rem; margin-top: 1.1rem; flex-wrap: wrap; align-items: center; }
.form-actions .spacer { flex: 1; }
.form-inline { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.form-inline input:not([type=color]):not([type=hidden]) { width: auto; flex: 1 1 160px; }
.form-inline select { width: auto; }
.form-inline.grow { flex: 1; }
.inline-label { flex-direction: row; align-items: center; gap: .5rem; }
.inline-form { display: inline; margin: 0; }
.align-end { display: flex; align-items: flex-end; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: .75rem; margin: 0; }
legend { font-size: .88rem; font-weight: 600; padding: 0 .3rem; }
.tag-picker { display: flex; flex-wrap: wrap; gap: .4rem .8rem; margin-bottom: .6rem; }
.tag-check { flex-direction: row; align-items: center; gap: .3rem; font-weight: 400; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.filters input[type=search] { flex: 1 1 220px; width: auto; }
.filters select { width: auto; flex: 0 1 auto; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit; font-weight: 600; font-size: .9rem; padding: .5rem .9rem; border-radius: 8px; border: 1px solid #d1d5db; background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: #f9fafb; }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-success { background: #ecfdf5; border-color: #a7f3d0; color: var(--success); }
.btn-success:hover { background: #d1fae5; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.link-btn { background: none; border: 0; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }
.btn-row { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.chip { font: inherit; font-size: .8rem; border: 1px dashed #c7d2fe; background: var(--primary-50); color: var(--primary-600); border-radius: 999px; padding: .15rem .55rem; cursor: pointer; }
.merge-help { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin-top: .8rem; }

/* Segmented control */
.seg { display: inline-flex; background: #eef0f4; border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg a, .seg button { font: inherit; font-size: .85rem; font-weight: 600; color: #4b5563; padding: .35rem .8rem; border-radius: 8px; border: 0; background: none; cursor: pointer; text-decoration: none; }
.seg a.active, .seg button.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.seg-sm a, .seg-sm button { padding: .25rem .65rem; font-size: .8rem; }

/* Badges & tags */
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .12rem .5rem; border-radius: 999px; background: #f3f4f6; color: #374151; vertical-align: middle; white-space: nowrap; }
.biz-swhi { background: #e0f2fe; color: var(--swhi); }
.biz-bouncer { background: #fae8ff; color: var(--bouncer); }
.biz-both { background: #ede9fe; color: var(--both); }
.st-active { background: #d1fae5; color: #047857; }
.st-lead { background: #fef3c7; color: #b45309; }
.st-inactive { background: #f3f4f6; color: #6b7280; }
.it-call { background: #dbeafe; color: #1d4ed8; } .it-email { background: #e0e7ff; color: #4338ca; }
.it-text { background: #dcfce7; color: #15803d; } .it-meeting { background: #ffedd5; color: #c2410c; } .it-other { background: #f3f4f6; color: #4b5563; }
.tag { --tag: #6366f1; display: inline-block; font-size: .74rem; font-weight: 600; padding: .1rem .5rem; border-radius: 6px; color: var(--tag); background: color-mix(in srgb, var(--tag) 14%, white); border: 1px solid color-mix(in srgb, var(--tag) 30%, white); white-space: nowrap; }
.count-pill { background: #f3f4f6; color: #374151; font-size: .78rem; padding: .05rem .5rem; border-radius: 999px; margin-left: .3rem; }
.biz-pill { display: inline-flex; gap: .5rem; align-items: center; border: 1px solid var(--border); border-radius: 10px; padding: .5rem .8rem; color: var(--text); }

/* Flash */
.flash { padding: .7rem .9rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid; font-size: .92rem; }
.flash-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.flash-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.flash-info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; padding: .55rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th a { color: inherit; }
.table td { padding: .65rem .6rem; border-bottom: 1px solid #f1f2f4; vertical-align: top; }
.table tr:hover td { background: #fafbff; }
.pager { display: flex; gap: .3rem; flex-wrap: wrap; margin-top: 1rem; }
.pager a { padding: .3rem .65rem; border: 1px solid var(--border); border-radius: 6px; }
.pager a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .7rem 0; border-bottom: 1px solid #f1f2f4; flex-wrap: wrap; }
.list > li:last-child { border-bottom: 0; }
.list.compact > li { padding: .5rem 0; }
.list > li.is-done { opacity: .55; }
.list .right { text-align: right; }
.fu-main { flex: 1 1 320px; min-width: 0; }
.fu-overdue { border-left: 4px solid var(--danger); }
.fu-today { border-left: 4px solid var(--warn); }
.fu-week { border-left: 4px solid var(--swhi); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: .6rem 0 .6rem 1rem; border-left: 2px solid var(--border); margin-left: .3rem; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 1rem; width: 10px; height: 10px; border-radius: 50%; background: #c7d2fe; }
.timeline-actions { margin-top: .2rem; }
.details { display: grid; grid-template-columns: 130px 1fr; gap: .45rem .75rem; margin: 0; font-size: .92rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; word-break: break-word; }
.notes { margin-top: 1rem; padding: .8rem; background: #fafafa; border-radius: 8px; border: 1px solid var(--border); font-size: .9rem; }
.followup-box { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: .9rem; margin-bottom: .8rem; }
.followup-box.is-overdue { background: #fef2f2; border-color: #fecaca; }
.big { font-size: 1.2rem; font-weight: 700; }
.danger-zone { border-color: #fecaca; }

/* Dashboard */
.eyebrow { font-size: .74rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--swhi); }
.goal-card { background: linear-gradient(180deg, #f0f9ff, #fff 55%); border-color: #bae6fd; }
.goal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.goal-head h2 { font-size: 1.25rem; margin-top: .15rem; }
.goal-grid { display: grid; grid-template-columns: 180px minmax(220px, 1fr) minmax(280px, 1.6fr); gap: 1.5rem; align-items: center; }
.goal-ring { --pct: 0; width: 150px; height: 150px; border-radius: 50%; margin: 0 auto; display: grid; place-items: center;
  background: conic-gradient(var(--warn) calc(var(--pct) * 1%), #e5e7eb 0); }
.goal-ring.hit { background: conic-gradient(var(--success) calc(var(--pct) * 1%), #e5e7eb 0); }
.goal-ring > div { width: 118px; height: 118px; border-radius: 50%; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.goal-ring strong { font-size: 2rem; line-height: 1; }
.goal-ring span { font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.goal-stats { display: grid; gap: .9rem; }
.stat-num { font-size: 1.9rem; font-weight: 800; line-height: 1.1; }
.stat-num small { font-size: 1rem; color: var(--muted); font-weight: 600; }
.stat-label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.bar { position: relative; height: 8px; background: #e5e7eb; border-radius: 99px; margin: .4rem 0 .3rem; }
.bar span { display: block; height: 100%; background: var(--swhi); border-radius: 99px; }
.bar i { position: absolute; top: -4px; width: 2px; height: 16px; background: #111827; }
.stats-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; color: var(--text); text-decoration: none !important; display: block; }
a.stat-card:hover { border-color: #c7d2fe; }
.stat-card.danger .stat-num { color: var(--danger); }
.stat-card.warn .stat-num { color: var(--warn); }
.chart { width: 100%; height: 190px; position: relative; }
.chart-lg { height: 260px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .tip { position: absolute; pointer-events: none; background: #111827; color: #fff; font-size: .78rem; padding: .3rem .5rem; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%); opacity: 0; transition: opacity .1s; }
.legend { display: flex; gap: .4rem .8rem; align-items: center; flex-wrap: wrap; color: var(--muted); margin-top: .4rem; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: -.4rem; }
.dash { display: inline-block; width: 16px; border-top: 2px dashed #111827; margin-right: -.4rem; }
.incentive-card { background: linear-gradient(90deg, #fdf4ff, #fff); border-color: #f5d0fe; }
.incentive-card .eyebrow { color: var(--bouncer); }
.incentive { font-size: 1.15rem; font-weight: 700; margin: .3rem 0; }
.rank { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: #f3f4f6; font-weight: 700; font-size: .8rem; }
.rank-1 { background: #fde68a; } .rank-2 { background: #e5e7eb; } .rank-3 { background: #fed7aa; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 1.25rem; }
.template-card .preview { background: #fafafa; border: 1px solid var(--border); border-radius: 8px; padding: .8rem; margin-top: .4rem; font-size: .88rem; max-height: 320px; overflow: auto; }
.template-card h3 { margin: 0; }

/* Utilities */
.muted { color: var(--muted); } .small { font-size: .82rem; } .strong { font-weight: 700; }
.center { text-align: center; } .empty { color: var(--muted); padding: .5rem 0; margin: 0; }
.text-danger { color: var(--danger); } .text-success { color: var(--success); }

/* Responsive */
@media (max-width: 1200px) {
  .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .goal-grid { grid-template-columns: 180px 1fr; }
  .goal-chart { grid-column: 1 / -1; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  .main { margin-left: 0; }
  .menu-btn { display: block; }
  .quick-search { display: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .content { padding: 1rem; }
  .topbar { padding: .6rem 1rem; }
}
@media (max-width: 640px) {
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .goal-grid { grid-template-columns: 1fr; }
  .details { grid-template-columns: 105px 1fr; }
  .template-grid { grid-template-columns: 1fr; }
  .table.responsive thead { display: none; }
  .table.responsive tr { display: block; border-bottom: 1px solid var(--border); padding: .5rem 0; }
  .table.responsive td { display: flex; gap: .75rem; border: 0; padding: .25rem .2rem; }
  .table.responsive td[data-label]::before { content: attr(data-label); flex: 0 0 110px; color: var(--muted); font-size: .78rem; font-weight: 600; }
  .followup-box { grid-template-columns: 1fr; }
}
