:root {
  --bg: #f4f5f7; --panel: #fff; --text: #1f2430; --muted: #6b7280; --line: #e3e6eb; --accent: #2f6fde; --accent-2: #e8f0fd;
  --ok: #1e8e3e; --ok-bg: #e6f4ea; --bad: #c5221f; --bad-bg: #fce8e6; --warn: #b06000; --warn-bg: #fef3e0; --side: #1d2433;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 12px; } h3 { font-size: 15px; margin: 0 0 10px; }
input, select, textarea, button { font: inherit; }
input, select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; color: var(--text); max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); border-color: var(--accent); }
input:disabled, select:disabled, textarea:disabled { background: #f7f7f9; color: #555; }
textarea { width: 100%; resize: vertical; }
button { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 12px; cursor: pointer; color: var(--text); }
button:hover { background: #f0f2f5; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(.95); }
button.danger { color: var(--bad); border-color: #f1c4c0; }
button.sm { padding: 2px 8px; font-size: 12px; }
button.icon { border: 0; background: none; padding: 2px 6px; }
button:disabled { opacity: .5; cursor: default; }
code { background: #f0f2f5; padding: 1px 5px; border-radius: 4px; font-size: 12px; word-break: break-all; }

.loading { padding: 40px; text-align: center; }
.layout { display: flex; min-height: 100vh; }
.side { width: 220px; background: var(--side); color: #cfd6e4; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; color: #fff; padding: 16px 18px; font-size: 16px; }
.side nav a { display: block; padding: 7px 18px; color: #cfd6e4; }
.side nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.side nav a.active { background: rgba(255,255,255,.12); color: #fff; border-left: 3px solid #7aa7ff; padding-left: 15px; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #8792a8; padding: 14px 18px 4px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.top .user { color: var(--text); }
.burger { display: none; font-size: 18px; }
.content { padding: 20px; }
.spacer { flex: 1; }
.lang-switch a { color: var(--muted); font-weight: 600; } .lang-switch a.on { color: var(--accent); }

.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.filters, .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.card.warn { border-color: #f5c989; background: #fffaf2; }
.card.narrow { max-width: 420px; }
.cols { display: flex; gap: 16px; align-items: flex-start; }
.col-main { flex: 1 1 0; min-width: 0; }
.col-side { flex: 0 0 380px; min-width: 0; }
.form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.form label, label.form { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form label > input, .form label > select, .form label > textarea { color: var(--text); font-size: 14px; }
label.inline { display: inline-flex; flex-direction: row; align-items: center; gap: 5px; font-size: 13px; color: var(--text); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.w70 { width: 70px; } .w100 { width: 100px; } .w150 { width: 150px; } .w200 { width: 200px; }

.tbl { width: 100%; border-collapse: collapse; background: var(--panel); }
.tbl th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); padding: 7px 8px; white-space: nowrap; }
.tbl td { border-bottom: 1px solid var(--line); padding: 7px 8px; vertical-align: top; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl th.sorted { color: var(--accent); }
.sort-ind { margin-left: 4px; font-size: 10px; opacity: .45; }
.tbl th.sorted .sort-ind { opacity: 1; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: #f7f9fc; }
.tbl tr.done td { color: var(--muted); }
.content > div > .tbl { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.overdue, .bad { color: var(--bad); font-weight: 600; } .good { color: var(--ok); }
.err { color: var(--bad); } .warn-text { color: var(--warn); margin: 6px 0; }
.pre { white-space: pre-wrap; }
.link { cursor: pointer; }

.badge { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 10px; background: #eef0f4; color: #3b4252; margin-right: 4px; white-space: nowrap; }
.status-won, .dnc-clear, .camp-active { background: var(--ok-bg); color: var(--ok); }
.status-lost, .status-no_response, .dnc-listed { background: var(--bad-bg); color: var(--bad); }
.camp-paused { background: var(--warn-bg); color: var(--warn); }
.st-new_lead { background: #fff4d6; } .st-qualification { background: #f3e8fd; } .st-mockup_sent, .st-approval { background: #e3f0ff; }
.st-invoice_sent { background: #fdebd8; } .st-paid, .st-production { background: #e1f5ee; } .st-shipped, .st-delivered { background: var(--ok-bg); }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.kpi-v { font-size: 22px; font-weight: 700; } .kpi-v small { font-size: 13px; color: var(--muted); font-weight: 400; }
.kpi-l { color: var(--muted); font-size: 12px; }

.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.tabs a { padding: 5px 12px; color: var(--text); background: #fff; }
.tabs a.on { background: var(--accent); color: #fff; }
.tabs a:hover { text-decoration: none; }

.board { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.board .col { flex: 0 0 230px; background: #e9ecf1; border-radius: 10px; padding: 8px; min-height: 200px; }
.col-head { display: flex; flex-direction: column; padding: 4px 4px 8px; font-size: 13px; }
.deal-card { background: #fff; border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.deal-card:hover { box-shadow: 0 2px 6px rgba(0,0,0,.12); }
.dc-name { font-weight: 600; }
.dc-foot { display: flex; gap: 6px; align-items: center; margin-top: 4px; font-size: 13px; flex-wrap: wrap; }

.stages { display: flex; gap: 2px; margin: 6px 0 10px; overflow-x: auto; }
.stage { flex: 1; min-width: 95px; text-align: center; padding: 6px 4px; font-size: 12px; background: #e9ecf1; cursor: pointer; }
.stage:first-child { border-radius: 6px 0 0 6px; } .stage:last-child { border-radius: 0 6px 6px 0; }
.stage.done { background: #cfe0fb; } .stage.cur { background: var(--accent); color: #fff; font-weight: 600; }

.bant { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.bant-item { display: flex; gap: 8px; align-items: flex-start; }
.timeline { max-height: 420px; overflow-y: auto; margin-top: 8px; }
.tl-item { border-left: 2px solid var(--line); padding: 2px 0 8px 10px; }
.list-item { padding: 6px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; }
.chip { display: inline-flex; gap: 4px; align-items: center; background: var(--accent-2); border-radius: 12px; padding: 2px 4px 2px 10px; font-size: 12px; color: var(--text); }
.chip small { color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.naics-picker, .contact-select { position: relative; }
.dropdown { position: absolute; z-index: 20; background: #fff; border: 1px solid var(--line); border-radius: 6px; max-height: 260px; overflow-y: auto; width: 100%; box-shadow: 0 4px 14px rgba(0,0,0,.12); }
.dd-item { padding: 6px 10px; cursor: pointer; font-size: 13px; color: var(--text); } .dd-item:hover { background: #f0f4fb; }

.modal-bg { position: fixed; inset: 0; background: rgba(15,20,30,.45); display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 40px 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 560px; max-width: 100%; }
.modal.wide { width: 980px; }
.modal.xl { width: min(1400px, 96vw); }
/* templates page: sections (General + industry groups) on the left */
.tpl-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.tpl-sections { padding: 8px 0; position: sticky; top: 12px; }
.tpl-sections a { display: flex; justify-content: space-between; gap: 8px; padding: 7px 16px; color: var(--text); }
.tpl-sections a:hover { background: #f3f5f9; text-decoration: none; }
.tpl-sections a.on { background: var(--accent-2); color: var(--accent); font-weight: 600; border-left: 3px solid var(--accent); padding-left: 13px; }
.nav-sep2 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 12px 16px 4px; }
@media (max-width: 900px) { .tpl-layout { grid-template-columns: 1fr; } .tpl-sections { position: static; } }
/* template editor: wide text column + preview column */
.tpl-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.tpl-cols textarea { min-height: 420px; font-family: inherit; }
@media (max-width: 1000px) { .tpl-cols { grid-template-columns: 1fr; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 16px 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.preview { margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #fafbfc; font-size: 13px; }

.pager { display: flex; gap: 10px; align-items: center; margin: 10px 0; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1f2937; color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 380px; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.toast.err { background: var(--bad); }

.bar-row { display: grid; grid-template-columns: 140px 1fr auto; gap: 8px; align-items: center; font-size: 12px; margin-bottom: 4px; }
.bar { height: 10px; background: var(--accent); border-radius: 5px; min-width: 2px; }
.bar-v { white-space: nowrap; color: var(--muted); }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { background: #fff; padding: 28px; border-radius: 12px; width: 340px; max-width: 100%; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.08); }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.login .lang-switch { text-align: right; }
.proposal h2 { margin-top: 0; }

@media (max-width: 1100px) { .cols { flex-direction: column; } .col-side { flex-basis: auto; width: 100%; } .grid3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 760px) {
  .side { position: fixed; left: -240px; z-index: 60; transition: left .2s; }
  .layout.menuopen .side { left: 0; }
  .burger { display: inline-block; }
  .content { padding: 12px; }
  .grid2, .grid3, .bant { grid-template-columns: 1fr; }
  .tbl { display: block; overflow-x: auto; }
  .top .user .small { display: none; }
}
@media print {
  body * { visibility: hidden; }
  #proposal, #proposal * { visibility: visible; }
  #proposal { position: absolute; left: 0; top: 0; width: 100%; }
}
