:root {
  --brand: #0b5cab; --brand-dark: #032d60; --brand-light: #eaf5fe; --accent: #1b96ff;
  --bg: #f3f3f3; --card: #fff; --text: #181818; --muted: #5c5c5c; --border: #dddbda;
  --ok: #2e844a; --warn: #dd7a01; --bad: #ba0517; --radius: 8px;
  --shadow: 0 2px 2px rgba(0,0,0,.08);
  font-family: -apple-system, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 60px; text-align: center; color: var(--muted); }

/* Top bar */
.topbar { background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 16px; padding: 8px 16px; position: sticky; top: 0; z-index: 20; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--brand-dark); white-space: nowrap; }
.logo img { width: 30px; height: 30px; }
.search { flex: 1; max-width: 560px; margin: 0 auto; position: relative; }
.search input { width: 100%; padding: 8px 12px 8px 34px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.search svg { position: absolute; left: 10px; top: 9px; width: 16px; height: 16px; fill: var(--muted); }
.search-results { position: absolute; top: 40px; left: 0; right: 0; background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.15); max-height: 420px; overflow: auto; }
.search-results a { display: flex; gap: 10px; align-items: center; padding: 8px 12px; color: var(--text); }
.search-results a:hover, .search-results a.active { background: var(--brand-light); text-decoration: none; }
.search-results .empty { padding: 12px; color: var(--muted); }
.userbtn { display: flex; align-items: center; gap: 8px; background: none; border: 0; cursor: pointer; padding: 4px; border-radius: 6px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; flex: none; }
.menu { position: absolute; right: 12px; top: 52px; background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.15); min-width: 200px; z-index: 30; }
.menu button, .menu a { display: block; width: 100%; text-align: left; padding: 10px 14px; background: none; border: 0; cursor: pointer; color: var(--text); }
.menu button:hover, .menu a:hover { background: var(--brand-light); text-decoration: none; }

/* Nav */
.nav { background: #fff; border-bottom: 3px solid var(--brand); display: flex; gap: 2px; padding: 0 16px; overflow-x: auto; }
.nav a { padding: 11px 14px; color: var(--text); white-space: nowrap; border-bottom: 3px solid transparent; margin-bottom: -3px; }
.nav a:hover { background: var(--brand-light); text-decoration: none; }
.nav a.active { border-bottom-color: var(--brand-dark); font-weight: 600; background: var(--brand-light); }
.nav .app-name { font-weight: 700; padding: 11px 14px 11px 0; color: var(--brand-dark); white-space: nowrap; }

main { padding: 16px; max-width: 1500px; margin: 0 auto; }

/* Cards & headers */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.card > h3, .card-h { margin: 0; padding: 12px 16px; font-size: 15px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); }
.card-h h3 { margin: 0; font-size: 15px; flex: 1; }
.card-b { padding: 16px; }
.page-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; line-height: 1.2; }
.page-head .sub { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.icon { width: 34px; height: 34px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 14px; flex: none; }
.icon.sm { width: 24px; height: 24px; font-size: 11px; border-radius: 4px; }
.icon.lg { width: 44px; height: 44px; font-size: 18px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border); background: #fff; color: var(--brand); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: #f3f3f3; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--bad); }
.btn.success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: 6px 0 0 6px; }
.btn-group .btn:last-child { border-radius: 0 6px 6px 0; }
.btn-group .btn.on { background: var(--brand-light); }

/* Tables */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafaf9; padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; white-space: nowrap; }
table.list th.sorted::after { content: " ▲"; font-size: 9px; }
table.list th.sorted.desc::after { content: " ▼"; }
table.list td { padding: 9px 12px; border-bottom: 1px solid #ecebea; vertical-align: top; }
table.list tr:hover td { background: #f8fbff; }
table.list td.num, table.list th.num { text-align: right; }
.list-tools { display: flex; gap: 8px; padding: 10px 16px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.list-tools input[type=search] { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; min-width: 220px; }
.list-tools select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.list-tools .count { color: var(--muted); margin-left: auto; font-size: 13px; }
.empty-state { padding: 40px 16px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: #ecebea; color: #3e3e3c; white-space: nowrap; }
.badge.green { background: #cdefc4; color: #194e31; }
.badge.red { background: #fddde3; color: #8e030f; }
.badge.blue { background: #d8e6fe; color: #0b5cab; }
.badge.orange { background: #fedfd0; color: #8c4b02; }

/* Path (stage bar) */
.path { display: flex; margin: 0 16px 16px; gap: 4px; flex-wrap: wrap; }
.path button { flex: 1; min-width: 90px; border: 0; background: #ecebea; padding: 9px 18px; cursor: pointer; font-size: 13px; clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%, 10px 50%); color: #3e3e3c; }
.path button:first-child { clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%); border-radius: 16px 0 0 16px; }
.path button:last-child { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 10px 50%); border-radius: 0 16px 16px 0; }
.path button.done { background: #3ba755; color: #fff; }
.path button.current { background: var(--brand-dark); color: #fff; font-weight: 600; }
.path button.lost { background: var(--bad); color: #fff; font-weight: 600; }
.path button:hover:not(.current) { filter: brightness(.95); }

/* Detail layout */
.detail-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; }
.highlights { display: flex; gap: 32px; padding: 0 16px 14px; flex-wrap: wrap; }
.highlights div small { display: block; color: var(--muted); font-size: 12px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.field { padding: 8px 0; border-bottom: 1px solid #ecebea; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.field .val { min-height: 20px; white-space: pre-wrap; overflow-wrap: anywhere; }
.section-title { grid-column: 1 / -1; font-weight: 600; background: #f3f3f3; padding: 6px 10px; border-radius: 4px; margin: 12px 0 4px; }

/* Activity */
.composer { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.composer .tabs { display: flex; gap: 4px; margin-bottom: 8px; flex-wrap: wrap; }
.composer .tabs button { background: none; border: 1px solid var(--border); border-radius: 14px; padding: 3px 10px; cursor: pointer; font-size: 13px; }
.composer .tabs button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.composer input, .composer textarea { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; margin-bottom: 8px; }
.timeline { list-style: none; margin: 0; padding: 8px 16px; }
.timeline li { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid #ecebea; }
.timeline li:last-child { border-bottom: 0; }
.timeline .t-body { flex: 1; min-width: 0; }
.timeline .t-meta { color: var(--muted); font-size: 12px; }
.timeline .t-text { white-space: pre-wrap; margin-top: 3px; overflow-wrap: anywhere; }
.timeline .system { color: var(--muted); font-size: 13px; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 12px; padding: 0; }
.link-btn:hover { color: var(--bad); }

/* Dashboard */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi small { color: var(--muted); display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi b { font-size: 26px; display: block; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: 12px; }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.dash-grid .card { margin: 0; }
.bars { padding: 12px 16px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 110px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.bar-row .track { background: #f3f3f3; border-radius: 4px; height: 18px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--accent); border-radius: 4px; min-width: 2px; }
.bar-row .v { text-align: right; font-variant-numeric: tabular-nums; }
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { padding: 9px 16px; border-bottom: 1px solid #ecebea; display: flex; gap: 10px; align-items: center; }
.mini-list li:last-child { border-bottom: 0; }
.mini-list .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.overdue { color: var(--bad); font-weight: 600; }

/* Kanban */
.kanban { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.kcol { background: #f3f3f3; border: 1px solid var(--border); border-radius: var(--radius); min-width: 250px; width: 250px; flex: none; display: flex; flex-direction: column; max-height: calc(100vh - 230px); }
.kcol-h { padding: 10px 12px; border-bottom: 1px solid var(--border); background: #fff; border-radius: var(--radius) var(--radius) 0 0; }
.kcol-h b { display: block; }
.kcol-h span { color: var(--muted); font-size: 12px; }
.kcol-b { padding: 8px; overflow-y: auto; flex: 1; min-height: 80px; }
.kcol.drop .kcol-b { background: var(--brand-light); outline: 2px dashed var(--accent); outline-offset: -4px; }
.kcard { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 10px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow); }
.kcard:active { cursor: grabbing; }
.kcard .t { font-weight: 600; color: var(--brand); }
.kcard .m { color: var(--muted); font-size: 12px; margin-top: 3px; }
.kcard .a { font-weight: 600; margin-top: 6px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(8,7,7,.5); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: var(--radius); width: 100%; max-width: 760px; box-shadow: 0 16px 48px rgba(0,0,0,.3); }
.modal.wide { max-width: 1000px; }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--border); font-size: 18px; font-weight: 600; text-align: center; }
.modal-b { padding: 16px 20px; max-height: calc(100vh - 220px); overflow-y: auto; }
.modal-f { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; background: #fafaf9; border-radius: 0 0 var(--radius) var(--radius); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; }
.form-grid .wide { grid-column: 1 / -1; }
.f label { display: block; font-size: 13px; color: #3e3e3c; margin-bottom: 4px; }
.f label .req { color: var(--bad); }
.f input, .f select, .f textarea { width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.f input:focus, .f select:focus, .f textarea:focus, .composer textarea:focus, .composer input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.f textarea { min-height: 70px; resize: vertical; }
.f input[type=checkbox] { width: auto; }
.form-error { background: #fddde3; color: #8e030f; padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; }

/* Quote lines */
table.lines { width: 100%; border-collapse: collapse; }
table.lines th { font-size: 12px; text-align: left; color: var(--muted); padding: 4px; }
table.lines td { padding: 3px 4px; }
table.lines input, table.lines select { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; }
table.lines .num { text-align: right; }
.totals { margin-left: auto; width: 300px; margin-top: 10px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { font-weight: 700; font-size: 16px; border-top: 2px solid var(--text); margin-top: 4px; padding-top: 8px; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, #032d60 0%, #0b5cab 55%, #1b96ff 100%); }
.login { background: #fff; border-radius: 12px; padding: 32px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login .logo { justify-content: center; font-size: 22px; margin-bottom: 6px; }
.login .logo img { width: 40px; height: 40px; }
.login p.lead { text-align: center; color: var(--muted); margin: 0 0 22px; }
.login .f { margin-bottom: 14px; }
.login .btn { width: 100%; justify-content: center; padding: 10px; }

/* Toast */
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; }
#toast div { background: #2e844a; color: #fff; padding: 10px 18px; border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.25); margin-top: 8px; }
#toast div.err { background: var(--bad); }

/* Quote print */
.print-page { background: #fff; max-width: 860px; margin: 0 auto; padding: 40px; border: 1px solid var(--border); }
.print-page h1 { margin: 0; color: var(--brand-dark); }
.print-head { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.print-page table { width: 100%; border-collapse: collapse; margin-top: 20px; }
.print-page th { text-align: left; border-bottom: 2px solid var(--text); padding: 8px 6px; font-size: 13px; }
.print-page td { border-bottom: 1px solid var(--border); padding: 8px 6px; vertical-align: top; }
.print-page .num { text-align: right; }
.print-bar { max-width: 860px; margin: 0 auto 12px; display: flex; gap: 8px; }
.muted { color: var(--muted); }

@media print {
  .topbar, .nav, .print-bar, #toast { display: none !important; }
  body, main { background: #fff; padding: 0; }
  .print-page { border: 0; padding: 0; }
}
@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .dash-grid { grid-template-columns: 1fr; }
  .fields, .form-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 100px 1fr 90px; }
  .logo span { display: none; }
  main { padding: 10px; }
}
