:root {
  --bg:         #f5f7fa;
  --surface:    #ffffff;
  --surface-2:  #f0f4f8;
  --text:       #15202b;
  --muted:      #5e6b78;
  --line:       #d9e2ec;
  --brand:      #8d1f1f;
  --brand-dark: #651515;
  --brand-soft: #f9ecec;
  --nav:        #0f1720;
  --nav-2:      #1e293b;
  --shadow:     0 16px 40px rgba(15,23,32,.08);
  --radius:     18px;
}
* { box-sizing: border-box }
html { scroll-behavior: smooth }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: Segoe UI, Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}
a { text-decoration: none; color: inherit }
main { flex: 1 0 auto }

/* ---- Top bar ---- */
.topbar { background: linear-gradient(90deg, var(--nav), var(--nav-2)); color: #fff; position: sticky; top: 0; z-index: 20; box-shadow: 0 8px 20px rgba(0,0,0,.12); }
.container { width: min(1240px, 92%); margin: 0 auto }
.nav-wrap { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 14px 0 }
.logo { font-size: 20px; font-weight: 800; letter-spacing: .02em }
.logo span { color: #fecaca }
.nav { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end }
.nav a { padding: 8px 12px; border-radius: 999px; font-size: 14px; color: #dbe4ee }
.nav a:hover, .nav a.active { background: rgba(255,255,255,.1); color: #fff }

/* ---- Page header ---- */
.page-header { padding: 28px 0 20px }
.page-header h1 { margin: 0 0 6px; font-size: 30px; line-height: 1.1 }
.page-header p  { margin: 0; color: var(--muted); font-size: 15px }

/* ---- Sections ---- */
main section { padding: 0 0 36px }
.section-head { margin-bottom: 20px }
.section-head h2 { margin: 0 0 8px; font-size: 28px }
.section-head p  { margin: 0; max-width: 860px; color: var(--muted) }

/* ---- Grid & Cards ---- */
.grid { display: grid; gap: 18px }
.grid.cols-2 { grid-template-columns: 1fr 1fr }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr) }
.grid.auto   { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)) }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow) }
.card h3, .card h4 { margin: 0 0 10px }
.card p  { margin: 0; color: var(--muted) }
.card ul { margin: 0; padding-left: 18px; color: var(--muted) }
.card li { margin-bottom: 8px }
.highlight { background: linear-gradient(180deg, #fff, #fcf8f8); border-color: #efd4d4 }

/* ---- KPI tiles ---- */
.kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 8px }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--shadow) }
.tile .num { font-size: 28px; font-weight: 800; color: var(--brand-dark); margin-bottom: 4px }

/* ---- Buttons ---- */
.btn { display: inline-block; padding: 10px 16px; border-radius: 12px; font-weight: 700; border: 1px solid transparent; cursor: pointer; font: inherit }
.btn.tertiary  { background: var(--surface-2); color: #334155; border-color: var(--line) }
.btn.btn-dark  { background: var(--nav-2); color: #fff; border-color: var(--nav-2) }
.btn:disabled  { opacity: .6; cursor: not-allowed }
.btn-row       { display: flex; gap: 10px; flex-wrap: wrap }

/* ---- Tags & Badges ---- */
.tag { background: var(--brand-soft); color: var(--brand-dark); padding: 5px 9px; border-radius: 999px; font-size: 12px; font-weight: 700 }
.badge { display: inline-block; padding: 5px 9px; border-radius: 999px; font-size: 12px; font-weight: 700 }
.badge.new         { background: #e8f2ff; color: #1d4ed8 }
.badge.draft       { background: #fff7e6; color: #b45309 }
.badge.submitted   { background: #ede9fe; color: #6d28d9 }
.badge.won         { background: #e9f8ef; color: #15803d }
.badge.lost        { background: #fdecec; color: #b91c1c }
.badge.negotiation { background: #fff1db; color: #c2410c }
.badge.dormant     { background: #f1f5f9; color: #475569 }

/* ---- Stage select (inline dropdown) ---- */
.stage-select {
  appearance: none; -webkit-appearance: none;
  border: none; border-radius: 999px;
  padding: 5px 9px; font-size: 12px; font-weight: 700;
  cursor: pointer; font-family: inherit;
}
.stage-select.stage-new         { background: #e8f2ff; color: #1d4ed8 }
.stage-select.stage-draft       { background: #fff7e6; color: #b45309 }
.stage-select.stage-submitted   { background: #ede9fe; color: #6d28d9 }
.stage-select.stage-won         { background: #e9f8ef; color: #15803d }
.stage-select.stage-lost        { background: #fdecec; color: #b91c1c }
.stage-select.stage-negotiation { background: #fff1db; color: #c2410c }
.stage-select.stage-dormant     { background: #f1f5f9; color: #475569 }
.stage-select:focus { outline: 2px solid #fecaca }

/* ---- Days-since badge ---- */
.days-badge { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 700 }
.days-badge.days-ok     { background: #e9f8ef; color: #15803d }
.days-badge.days-warn   { background: #fff7e6; color: #b45309 }
.days-badge.days-overdue{ background: #fdecec; color: #b91c1c }
.days-badge.days-closed { background: #f1f5f9; color: #475569 }
.days-badge.days-none   { background: #f1f5f9; color: #94a3b8 }

/* ---- Filters ---- */
.filters { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: 12px }
label { font-size: 13px; font-weight: 700; color: #334155; display: block; margin-bottom: 5px }
input, select { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid #cdd6df; background: #fff; color: var(--text); font: inherit }
input:focus, select:focus { outline: 2px solid #fecaca; border-color: #e5a3a3 }
.card-actions  { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-top: 14px; flex-wrap: wrap }
.action-buttons{ display: flex; gap: 8px; flex-wrap: wrap }

/* ---- Table ---- */
.table-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow) }
.table-spacing { margin-top: 18px }
table { width: 100%; border-collapse: collapse; min-width: 900px }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle }
th { background: var(--brand-dark); color: #fff; font-size: 12px; text-transform: uppercase; letter-spacing: .05em }
tbody tr:nth-child(even) td { background: #fbfcfd }
tbody tr:hover td { background: #f8fafc }
.small, .muted { font-size: 13px; color: var(--muted) }
.empty-row { text-align: center; color: var(--muted); padding: 32px !important }
.doc-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap }
.btn-link { background: none; border: none; cursor: pointer; padding: 0; color: #1d4ed8; text-decoration: underline; text-underline-offset: 2px; font: inherit; font-size: 13px }
.btn-link:hover { color: #1e3a8a }
.doc-link { color: #1d4ed8; text-decoration: underline; text-underline-offset: 2px; font-size: 13px }
.doc-link:hover { color: #1e3a8a }

/* ---- Icon buttons ---- */
.btn-icon { background: none; border: none; cursor: pointer; padding: 4px 7px; border-radius: 8px; font-size: 13px; line-height: 1 }
.btn-delete { color: #b91c1c }
.btn-delete:hover { background: #fdecec }

/* ---- Modal ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,32,.6); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50 }
.modal-backdrop.hidden { display: none }
.modal-card { width: min(860px, 100%); max-height: 92vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 24px; box-shadow: 0 20px 50px rgba(2,6,23,.22) }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px }
.modal-head h3 { margin: 0 }
.modal-close { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: #fff; color: #334155; font: inherit; font-size: 16px; cursor: pointer }
.doc-preview-card { width: min(760px, 100%) }
.doc-preview-body { margin-top: 10px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; min-height: 260px; background: #f8fafc; display: flex; align-items: center; justify-content: center }
.doc-preview-frame { width: 100%; height: 380px; border: 0; background: #fff }
.doc-preview-image { display: block; width: auto; max-width: 100%; max-height: 380px; height: auto }
.doc-preview-empty { padding: 20px; text-align: center; color: var(--muted); font-size: 14px }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 14px }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(200px, 1fr)); gap: 12px }
.form-field { display: grid }
.required { color: #b91c1c }
.field-error { min-height: 16px; font-size: 12px; color: #b91c1c; margin-top: 3px }
.input-error { border-color: #b91c1c !important }

/* ---- Toast ---- */
.toast-stack { position: fixed; top: 80px; right: 18px; display: grid; gap: 8px; z-index: 60; width: min(340px, 92vw) }
.toast { border-radius: 12px; padding: 11px 14px; border: 1px solid var(--line); background: #fff; box-shadow: 0 10px 24px rgba(15,23,32,.14); font-size: 14px }
.toast.success { border-color: #9fdeb6; background: #ecfdf3; color: #166534 }
.toast.error   { border-color: #f5b6b6; background: #fff1f2; color: #991b1b }
.toast.info    { border-color: #b7d5ff; background: #eef5ff; color: #1e3a8a }

/* ---- Charts ---- */
.chart-bars { display: grid; gap: 12px }
.bar-row { display: grid; grid-template-columns: 140px 1fr 36px; gap: 10px; align-items: center; font-size: 14px }
.bar { height: 13px; border-radius: 999px; background: #f1f5f9; overflow: hidden; border: 1px solid var(--line) }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), #d24b4b) }

/* ---- Company Tracker ---- */
.company-filters { grid-template-columns: repeat(4, minmax(130px, 1fr)) }
.company-grid { display: grid; gap: 20px }
.company-card { padding: 22px }
.company-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 14px; flex-wrap: wrap }
.company-info { flex: 1; min-width: 180px }
.company-name { margin: 0 0 8px; font-size: 20px }
.company-tags { display: flex; gap: 6px; flex-wrap: wrap }
.company-summary { display: flex; gap: 22px; flex-wrap: wrap; align-items: flex-start }
.stat-block { text-align: right; min-width: 68px }
.stat-num { font-size: 22px; font-weight: 800; color: var(--brand-dark); line-height: 1.1 }
.stat-value { font-size: 16px }
.stat-date { font-size: 14px; font-weight: 700; color: var(--muted) }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px }
.company-stages { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px }
.company-proposals-wrap .table-wrap { box-shadow: none; border-radius: 12px }
.company-proposals-wrap table { min-width: 680px }
.company-proposals-wrap th { font-size: 11px }
.company-proposals-wrap td { font-size: 13px; padding: 10px 12px }

/* ---- Footer ---- */
.footer { background: #0f1720; color: #dfe8f2; padding: 24px 0 32px; margin-top: auto }
.footer .inner { display: flex; justify-content: space-between; gap: 20px; align-items: center }
.footer .links { display: flex; gap: 12px; flex-wrap: wrap }
.footer .links a { font-size: 14px; color: #c8d3df }

/* ---- Responsive ---- */
@media (max-width: 980px) {
  .grid.cols-2, .grid.cols-3, .filters, .company-filters, .form-grid, .footer .inner { grid-template-columns: 1fr; display: grid }
  .nav-wrap { flex-direction: column; align-items: flex-start }
  .nav { justify-content: flex-start }
  .company-header { flex-direction: column }
  .company-summary { flex-direction: row; justify-content: flex-start }
  .stat-block { text-align: left }
}
