:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e2e6ee;
  --text: #1e2733;
  --muted: #68738a;
  --primary: #f59e0b;
  --primary-dark: #d97706;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar { width: 230px; background: #131a26; color: #cdd5e0; display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: #fff; padding: 6px 10px 18px; }
.brand-icon { font-size: 20px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-btn { background: none; border: 0; color: #cdd5e0; text-align: left; padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.nav-btn:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-btn.active { background: var(--primary); color: #131a26; font-weight: 600; }
.sidebar-footer { margin-top: auto; padding: 10px; font-size: 12px; }
.sidebar-footer a { color: #9aa5b5; text-decoration: none; }

/* Main */
.main { flex: 1; padding: 20px 28px; max-width: 1200px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.search-wrap { flex: 1; max-width: 520px; }
#globalSearch { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background: var(--panel); }
#globalSearch:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* Buttons */
.btn { border: 0; border-radius: 8px; padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--primary); color: #1e1200; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); padding: 6px 10px; }
.btn-danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; padding: 6px 12px; font-weight: 500; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* Cards / panels */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-actions { display: flex; align-items: center; gap: 8px; }

/* Dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.dash-grid > .panel { min-width: 0; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }
.stage-bar { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 13px; }
.stage-bar .name { width: 110px; text-align: right; color: var(--muted); }
.stage-bar .track { flex: 1; background: #eef1f7; height: 14px; border-radius: 7px; overflow: hidden; }
.stage-bar .fill { height: 100%; background: var(--primary); border-radius: 7px; }
.stage-bar .amt { width: 90px; font-weight: 600; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 10px 14px; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--border); }
td { padding: 10px 14px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #fafbfe; }
.tag { display: inline-block; background: #fef3c7; color: #92400e; border-radius: 999px; padding: 2px 9px; font-size: 12px; margin: 1px; }
.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; }
.badge.lead { background: #e0e7ff; color: #3730a3; }
.badge.qualified { background: #cffafe; color: #155e75; }
.badge.proposal { background: #fef3c7; color: #92400e; }
.badge.negotiation { background: #fce7f3; color: #9d174d; }
.badge.won { background: #dcfce7; color: #166534; }
.badge.lost { background: #fee2e2; color: #991b1b; }
.badge.customer { background: #dcfce7; color: #166534; }
.badge.prospect { background: #e0e7ff; color: #3730a3; }
.badge.inactive { background: #f3f4f6; color: #4b5563; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* Deal card actions */
.deal-actions { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.deal-actions .btn { white-space: nowrap; }

/* Typeahead (searchable picker) */
.typeahead { position: relative; }
.typeahead .ta-input { padding-right: 34px; }
.ta-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.ta-clear:hover { background: #f1f3f9; color: var(--text); }
.ta-menu { margin-top: 4px; border: 1px solid var(--border); border-radius: 8px; background: #fff; max-height: 180px; overflow: auto; box-shadow: var(--shadow); }
.ta-item { padding: 8px 12px; font-size: 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.ta-item:last-child { border-bottom: 0; }
.ta-item:hover, .ta-item.active { background: #fef3c7; }

/* Pipeline board */
.pipeline { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.column { background: #eef1f7; border-radius: var(--radius); padding: 10px; }
.column h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); display: flex; justify-content: space-between; }
.deal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: pointer; }
.deal-card:hover { border-color: var(--primary); }
.deal-card .title { font-weight: 600; font-size: 14px; }
.deal-card .amount { font-size: 14px; color: var(--primary-dark); font-weight: 700; margin: 4px 0; }
.deal-card .meta { font-size: 12px; color: var(--muted); }

/* Activities */
.activity-list { padding: 6px 0; }
.activity-item { padding: 12px 18px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: flex-start; }
.activity-item:last-child { border-bottom: 0; }
.activity-item .type { font-size: 20px; }
.activity-item .subject { font-weight: 600; }
.activity-item .body { color: var(--muted); font-size: 13px; margin-top: 2px; }
.activity-item .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Empty state */
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { background: var(--panel); border-radius: 12px; width: 520px; max-width: 94vw; max-height: 90vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,0.25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 18px 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
label .opt { font-weight: 400; color: var(--muted); }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.import-errors { max-height: 320px; overflow: auto; display: grid; gap: 6px; font-size: 13px; }
.import-err { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; border-radius: 8px; padding: 8px 10px; }
.import-err b { color: #7f1d1d; }

/* Import mapping modal */
.import-map { display: grid; gap: 12px; }
.map-preview { width: 100%; border-collapse: collapse; font-size: 12px; }
.map-preview td { border: 1px solid var(--border); padding: 4px 8px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: #fafbfe; }
.map-preview td.hdr { background: #fef3c7; font-weight: 600; }
.map-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.map-table th { text-align: left; padding: 6px 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--border); }
.map-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.map-table .m-col { font-weight: 600; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-table .m-map select { padding: 6px 8px; }
.map-table .m-req { text-align: center; }
.map-table .m-req input { width: auto; }

/* Toast */
.toast { position: fixed; bottom: 24px; right: 24px; background: #111827; color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.25); z-index: 100; font-size: 14px; }
.toast.error { background: var(--danger); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

/* Auth screen */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(160deg, #131a26 0%, #1c2433 55%, #2a2110 100%); }
.auth-card { background: var(--panel); border-radius: 14px; width: 400px; max-width: 94vw; box-shadow: 0 24px 60px rgba(0,0,0,0.35); overflow: hidden; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 18px; font-weight: 700; color: #fff; background: #131a26; padding: 22px 16px; }
.auth-tabs { display: flex; border-bottom: 1px solid var(--border); }
.auth-tab { flex: 1; background: none; border: 0; padding: 12px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.auth-tab:hover { color: var(--text); }
.auth-tab.active { color: var(--primary-dark); border-bottom: 2px solid var(--primary); }
.auth-body { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.auth-hint { margin: 0; padding: 10px 22px; background: #fef3c7; color: #92400e; font-size: 13px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 44px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: 0; cursor: pointer; font-size: 16px; padding: 6px; border-radius: 6px; opacity: 0.65; }
.pw-toggle:hover { opacity: 1; background: #f1f3f9; }
.pw-toggle.revealed { opacity: 1; }
.user-box { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.user-email { font-size: 12px; color: #9aa5b5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.made-by { font-size: 11px; color: #8b95a6; margin-bottom: 8px; }
.made-by strong { color: #c8d0dd; }
.auth-tagline { margin: 0; padding: 10px 22px 4px; font-size: 12px; color: var(--muted); text-align: center; }

/* Bulk delete */
.sel-col { width: 34px; }
.sel-col input, .deal-top input[type="checkbox"], .activity-item input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--primary); cursor: pointer; }
.bulk-bar { display: flex; align-items: center; gap: 10px; padding: 10px 18px; background: #fef3c7; border-bottom: 1px solid #fde68a; }
.bulk-count { font-size: 13px; font-weight: 700; color: #92400e; }
.deal-top { display: flex; align-items: flex-start; gap: 8px; }
.deal-top .title { flex: 1; }
