:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #f0f3f9; --text: #1b2433; --muted: #66728a; --border: #dfe4ee;
  --primary: #2f5fe3; --primary-text: #ffffff; --primary-soft: #e6edff; --good: #138a4b; --good-soft: #e2f6ea;
  --warn: #a96300; --warn-soft: #fff1d6; --bad: #c7352f; --bad-soft: #fde7e6; --shadow: 0 1px 2px rgba(20,30,60,.06), 0 4px 14px rgba(20,30,60,.05);
  --radius: 10px; --sidebar-w: 232px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420; --surface: #171e2d; --surface-2: #1e2738; --text: #e6eaf3; --muted: #93a0ba; --border: #2a3550;
    --primary: #6b94ff; --primary-text: #0b1020; --primary-soft: #1f2d52; --good: #4cd08a; --good-soft: #14352a;
    --warn: #f0b24e; --warn-soft: #3a2c10; --bad: #ff7b74; --bad-soft: #3d1c1b; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html { color-scheme: light dark; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--primary); }
.muted { color: var(--muted); } .small { font-size: .82rem; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); flex: none; background: var(--surface); border-right: 1px solid var(--border); position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 1rem .75rem; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; padding: .25rem .5rem 1rem; }
.brand-mark { background: var(--primary); color: var(--primary-text); border-radius: 8px; padding: .2rem .45rem; font-size: .85rem; }
.sidebar nav a { display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; border-radius: 8px; color: var(--text); text-decoration: none; margin-bottom: 2px; }
.sidebar nav a:hover { background: var(--surface-2); }
.sidebar nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar nav .ico { width: 1.2rem; text-align: center; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { display: flex; gap: .75rem; align-items: center; padding: .75rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.menu-btn { display: none; }
.search { position: relative; flex: 1; max-width: 520px; }
.search input { width: 100%; }
.search-results { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 70vh; overflow: auto; z-index: 30; }
.search-results h4 { margin: 0; padding: .5rem .75rem .2rem; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.search-results a { display: block; padding: .4rem .75rem; color: var(--text); text-decoration: none; }
.search-results a:hover { background: var(--surface-2); }
.view { padding: 1.25rem; flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; outline: none; }
.page-head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.grid { display: grid; gap: 1rem; }
.grid.kpis { grid-template-columns: repeat(auto-fill, minmax(min(165px,100%),1fr)); margin-bottom: 1rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(320px,100%),1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(min(260px,100%),1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); min-width: 0; }
.card > h2, .card > h3 { margin-bottom: .75rem; }
.kpi .label { color: var(--muted); font-size: .8rem; }
.kpi .value { font-size: 1.5rem; font-weight: 700; margin-top: .15rem; }
.kpi .sub { color: var(--muted); font-size: .78rem; }
.btn, button { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .45rem .85rem; border-radius: 8px; }
.btn:hover, button:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.sm { padding: .2rem .55rem; font-size: .82rem; }
.icon-btn { padding: .35rem .6rem; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .45rem .6rem; width: 100%; max-width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
input[type=checkbox] { width: auto; }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .2rem; }
.field { margin-bottom: .75rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(210px,100%),1fr)); gap: 0 .9rem; }
.form-grid .full { grid-column: 1 / -1; }
.checks { display: flex; flex-wrap: wrap; gap: .35rem .9rem; max-height: 150px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: .5rem; }
.checks label { display: flex; align-items: center; gap: .35rem; margin: 0; color: var(--text); font-size: .85rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }
.toolbar input[type=search] { flex: 1; min-width: 200px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 1.5rem; text-align: center; color: var(--muted); }
.badge { display: inline-block; padding: .08rem .55rem; border-radius: 999px; font-size: .75rem; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: .75rem; padding: .5rem 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.list li:last-child { border-bottom: none; }
.list .grow { flex: 1; min-width: 0; }
.bars { display: flex; gap: .5rem; align-items: flex-end; height: 190px; padding-top: .5rem; }
.bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; min-width: 0; }
.bar { width: 100%; max-width: 54px; background: var(--primary); border-radius: 6px 6px 0 0; min-height: 2px; }
.bar.won { background: var(--good); } .bar.lost { background: var(--bad); }
.bar-val { font-size: .7rem; color: var(--muted); margin-bottom: 2px; white-space: nowrap; }
.bar-lbl { font-size: .68rem; color: var(--muted); text-align: center; margin-top: .3rem; line-height: 1.15; min-height: 2.3em; }
.tabs { display: flex; gap: .25rem; }
.seg button { border-radius: 0; margin: 0; }
.seg button:first-child { border-radius: 8px 0 0 8px; } .seg button:last-child { border-radius: 0 8px 8px 0; }
.seg button.on { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.kanban { display: flex; gap: .75rem; overflow-x: auto; padding-bottom: .75rem; align-items: flex-start; }
.col { flex: 0 0 255px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem; min-height: 200px; }
.col.over { outline: 2px dashed var(--primary); background: var(--primary-soft); }
.col-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .5rem; font-weight: 600; }
.col-head .sum { font-size: .75rem; color: var(--muted); font-weight: 400; }
.deal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .6rem .7rem; margin-bottom: .5rem; cursor: grab; box-shadow: var(--shadow); }
.deal-card.dragging { opacity: .4; }
.deal-card .t { font-weight: 600; font-size: .9rem; }
.modal-back { position: fixed; inset: 0; background: rgba(5,10,25,.55); display: flex; align-items: flex-start; justify-content: center; padding: 3vh .75rem; z-index: 100; overflow: auto; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; width: 100%; max-width: 720px; padding: 1.1rem 1.25rem; box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.modal.wide { max-width: 900px; }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 200; }
.toast { background: var(--text); color: var(--bg); padding: .6rem .9rem; border-radius: 8px; box-shadow: var(--shadow); max-width: 340px; }
.toast.err { background: var(--bad); color: #fff; }
.callout { border-left: 4px solid var(--primary); background: var(--primary-soft); padding: .6rem .8rem; border-radius: 6px; margin-bottom: .75rem; font-size: .88rem; }
.callout.warn { border-color: var(--warn); background: var(--warn-soft); }
.internal { border: 2px dashed var(--warn); background: var(--warn-soft); border-radius: var(--radius); padding: .8rem; margin-top: 1rem; }
.internal .tag { font-size: .72rem; font-weight: 700; text-transform: uppercase; color: var(--warn); letter-spacing: .05em; }
.sum-row { display: flex; justify-content: space-between; padding: .3rem 0; gap: 1rem; }
.sum-row.total { font-weight: 700; border-top: 1px solid var(--border); margin-top: .3rem; padding-top: .5rem; }
.qb { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
.qb > * { min-width: 0; }
.qb .sticky { position: sticky; top: 70px; }
.line { border: 1px solid var(--border); border-radius: 8px; padding: .7rem; margin-bottom: .6rem; background: var(--surface-2); }
.line-head { display: flex; justify-content: space-between; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.line-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(120px,100%),1fr)); gap: .5rem; }
.presets { display: flex; gap: .25rem; margin-top: .25rem; flex-wrap: wrap; }
.warnline { color: var(--warn); font-size: .8rem; margin-top: .25rem; }
.suggest { border: 1px solid var(--border); border-radius: 8px; padding: .5rem; margin-bottom: .75rem; background: var(--surface-2); }
.suggest .item { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem .4rem; border-radius: 6px; cursor: pointer; align-items: center; }
.suggest .item:hover { background: var(--primary-soft); }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; min-width: 70px; border: 1px solid var(--border); }
.progress > i { display: block; height: 100%; background: var(--primary); }
.progress.hot > i { background: var(--warn); }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .25rem .9rem; margin: 0; }
.dl dt { color: var(--muted); } .dl dd { margin: 0; overflow-wrap: anywhere; }
/* Auth */
.login { display: none; flex: 1; align-items: center; justify-content: center; padding: 1.25rem; }
body.auth-mode .login { display: flex; }
body.auth-mode .sidebar, body.auth-mode .topbar, body.auth-mode .view, body.auth-mode .scrim { display: none; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { padding: 0 0 .75rem; }
.login-card .btn { width: 100%; margin-top: .25rem; }
.user-box { margin-top: 1rem; padding: .75rem .5rem 0; border-top: 1px solid var(--border); font-size: .85rem; }
.user-box .uname { font-weight: 600; overflow-wrap: anywhere; }
.user-box .actions { margin-top: .5rem; }
/* Footer */
.cl-footer{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(280px,100%),1fr));gap:1.5rem 2.5rem;margin-top:3rem;padding:1.5rem 1.25rem;border-top:1px solid rgba(127,127,127,.3);font-size:.8rem;line-height:1.5;opacity:.8}
.cl-footer p{margin:0 0 .5rem}
.cl-footer__title{font-weight:600}
.cl-footer a{color:inherit;text-decoration:underline}
/* Proposal */
.proposal-bar { display: flex; gap: .5rem; justify-content: center; margin-bottom: 1rem; }
.proposal { background: #fff; color: #111; max-width: 820px; margin: 0 auto; padding: 2.2rem 2.4rem; border: 1px solid #ccd; border-radius: 6px; font-size: 14px; }
.proposal h1 { font-size: 1.7rem; margin: 0; } .proposal h2 { font-size: 1.1rem; margin: 1.4rem 0 .5rem; border-bottom: 2px solid #2f5fe3; padding-bottom: .2rem; color: #1b2f73; }
.proposal h3 { font-size: .95rem; margin: .9rem 0 .25rem; }
.proposal .ph { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; border-bottom: 3px solid #2f5fe3; padding-bottom: .8rem; margin-bottom: 1rem; }
.proposal table { width: 100%; margin: .5rem 0; } .proposal th { background: #eef2fb; color: #223; } .proposal th, .proposal td { border: 1px solid #d3d9e8; }
.proposal ul { margin: .25rem 0 .5rem; padding-left: 1.2rem; columns: 2; column-gap: 2rem; } .proposal li { break-inside: avoid; margin-bottom: .1rem; }
.proposal .tot td { font-weight: 700; background: #f4f6fb; }
.proposal .muted { color: #555; }
body.proposal-mode .sidebar, body.proposal-mode .topbar { display: none; }
body.proposal-mode .view { max-width: none; }
@media (max-width: 900px) {
  .qb { grid-template-columns: minmax(0, 1fr); } .qb .sticky { position: static; }
}
@media (max-width: 800px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 60; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: none; }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; }
  body.nav-open .scrim { display: block; }
  .menu-btn { display: inline-block; }
  .view { padding: .85rem; }
  .proposal { padding: 1.1rem; } .proposal ul { columns: 1; }
  .toolbar input, .toolbar select { flex: 1 1 140px; }
}
@media print {
  @page { margin: 14mm; }
  body { background: #fff; }
  .sidebar, .topbar, .scrim, .proposal-bar, .cl-footer, .toasts { display: none !important; }
  .app, .main { display: block; min-height: 0; }
  .view { padding: 0; max-width: none; }
  .proposal { border: none; padding: 0; max-width: none; border-radius: 0; }
  .proposal h2 { break-after: avoid; } .proposal table, .proposal .sect { break-inside: avoid; }
}
.deal-card .mv { display: none; margin-top: .4rem; font-size: .8rem; padding: .2rem .3rem; }
@media (hover: none) { .deal-card .mv { display: block; } }
