:root {
  --bg: #f4f5f7; --panel: #ffffff; --panel2: #f9fafb; --line: #e3e5e9; --line2: #eef0f3;
  --text: #1f2430; --muted: #6b7280; --faint: #9aa1ad;
  --primary: #4f46e5; --primary-ink: #ffffff; --primary-soft: #eef0ff;
  --ok: #15803d; --ok-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fff4e0; --bad: #c62828; --bad-soft: #fdecec;
  --nav: #1e1b4b; --nav-ink: #e0e7ff; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.18); --r: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141a; --panel: #1b1e26; --panel2: #20242d; --line: #2d323d; --line2: #262a33;
    --text: #e6e8ee; --muted: #9aa3b2; --faint: #6f7786;
    --primary: #7c74ff; --primary-soft: #26254a; --ok: #4ade80; --ok-soft: #14301f; --warn: #fbbf24; --warn-soft: #33270f;
    --bad: #f87171; --bad-soft: #3a1b1b; --nav: #0d0f1a; --nav-ink: #c7d2fe; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12141a; --panel: #1b1e26; --panel2: #20242d; --line: #2d323d; --line2: #262a33;
  --text: #e6e8ee; --muted: #9aa3b2; --faint: #6f7786;
  --primary: #7c74ff; --primary-soft: #26254a; --ok: #4ade80; --ok-soft: #14301f; --warn: #fbbf24; --warn-soft: #33270f;
  --bad: #f87171; --bad-soft: #3a1b1b; --nav: #0d0f1a; --nav-ink: #c7d2fe; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
svg.i { width: 16px; height: 16px; vertical-align: -3px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12px; } .nowrap { white-space: nowrap; }
.bad { color: var(--bad); } .ok { color: var(--ok); } .warn { color: var(--warn); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.right { margin-left: auto; } .hidden { display: none !important; } .mt { margin-top: 12px; } .mb { margin-bottom: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* top nav */
.nav { position: sticky; top: 0; z-index: 50; background: var(--nav); color: var(--nav-ink); display: flex; align-items: center; gap: 4px; padding: 0 12px; height: 50px; }
.brand { font-weight: 700; font-size: 16px; color: #fff; margin-right: 12px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand .logo { width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, #818cf8, #4f46e5); display: grid; place-items: center; color: #fff; font-size: 13px; }
.navlinks { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.navlinks a { color: var(--nav-ink); padding: 7px 11px; border-radius: 6px; white-space: nowrap; opacity: .85; }
.navlinks a:hover { background: rgba(255,255,255,.08); text-decoration: none; opacity: 1; }
.navlinks a.on { background: rgba(255,255,255,.14); opacity: 1; color: #fff; }
.navbtn { position: relative; background: none; border: 0; color: var(--nav-ink); padding: 7px 9px; border-radius: 6px; cursor: pointer; }
.navbtn:hover { background: rgba(255,255,255,.1); }
.badge { position: absolute; top: 1px; right: 0; background: #ef4444; color: #fff; border-radius: 9px; font-size: 10px; padding: 0 5px; line-height: 16px; min-width: 16px; text-align: center; }
.badge.orange { background: #f59e0b; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; flex: none; }
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }

/* layout */
main { padding: 0 16px 40px; max-width: 1600px; margin: 0 auto; }
.cp { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 0 12px; }
.cp h1 { font-size: 19px; margin: 0; font-weight: 650; }
.crumbs { font-size: 19px; font-weight: 650; display: flex; gap: 6px; align-items: center; min-width: 0; }
.crumbs a { font-weight: 500; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.pad { padding: 16px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; margin: 0 0 8px; }

/* forms */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=tel], input[type=email], input[type=number], input[type=password], input[type=date], input[type=datetime-local], input[type=search], select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; min-width: 0; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; min-height: 64px; }
label.f { display: block; font-size: 12px; color: var(--muted); margin: 0 0 4px; font-weight: 600; }
.field { margin-bottom: 12px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 7px 12px; cursor: pointer; white-space: nowrap; line-height: 1.2; }
.btn:hover { background: var(--panel2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 6px 10px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; border: 1px solid var(--line); background: var(--panel2); border-radius: 12px; padding: 2px 9px; cursor: pointer; white-space: nowrap; }
.chip:hover { border-color: var(--primary); }
.chip.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.tag { display: inline-block; font-size: 11px; border-radius: 10px; padding: 1px 8px; background: var(--primary-soft); color: var(--primary); margin: 0 4px 2px 0; }
.pill { display: inline-block; font-size: 11px; font-weight: 600; border-radius: 10px; padding: 1px 8px; color: #fff; white-space: nowrap; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.check input { width: 16px; height: 16px; }

/* search / filters */
.searchbox { position: relative; flex: 1; min-width: 220px; max-width: 520px; }
.searchbox input { padding-left: 32px; }
.searchbox svg { position: absolute; left: 10px; top: 10px; color: var(--faint); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters select { width: auto; padding: 6px 8px; }

/* kanban */
.kanban { display: flex; gap: 12px; overflow-x: auto; align-items: flex-start; padding-bottom: 12px; min-height: 60vh; }
.col { flex: 0 0 280px; background: var(--panel2); border: 1px solid var(--line2); border-radius: var(--r); display: flex; flex-direction: column; max-height: calc(100vh - 170px); }
.col.drop { outline: 2px dashed var(--primary); outline-offset: -2px; }
.colhead { padding: 10px 10px 8px; border-top: 3px solid var(--c, var(--primary)); border-radius: var(--r) var(--r) 0 0; }
.colhead .t { font-weight: 650; display: flex; gap: 6px; align-items: center; }
.colhead .meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; margin-top: 2px; }
.colbody { padding: 4px 8px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
.col.folded { flex: 0 0 42px; cursor: pointer; align-items: center; padding: 10px 0; }
.col.folded .vt { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; font-weight: 600; color: var(--muted); margin-top: 8px; }
.kcard { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 9px 10px; cursor: pointer; box-shadow: var(--shadow); border-left: 3px solid transparent; }
.kcard:hover { border-color: var(--primary); }
.kcard.dragging { opacity: .4; }
.kcard .t { font-weight: 600; margin-bottom: 3px; word-break: break-word; }
.kcard .sub { font-size: 12px; color: var(--muted); }
.kcard .foot { display: flex; align-items: center; gap: 8px; margin-top: 7px; }
.stars { display: inline-flex; gap: 0; }
.stars button { background: none; border: 0; padding: 0 1px; cursor: pointer; color: var(--faint); font-size: 15px; line-height: 1; }
.stars button.on { color: #f59e0b; }
.actdot { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; border-radius: 10px; padding: 1px 6px; }
.actdot.overdue { color: var(--bad); background: var(--bad-soft); }
.actdot.today { color: var(--warn); background: var(--warn-soft); }
.actdot.planned { color: var(--ok); background: var(--ok-soft); }
.actdot.none { color: var(--faint); }

/* tables */
.tablewrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; background: var(--panel); }
table.t th, table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line2); text-align: left; vertical-align: middle; }
table.t th { font-size: 12px; color: var(--muted); font-weight: 650; background: var(--panel2); position: sticky; top: 0; cursor: default; white-space: nowrap; }
table.t th.sort { cursor: pointer; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--panel2); }
table.t td.num, table.t th.num { text-align: right; }
.bulkbar { display: flex; gap: 8px; align-items: center; background: var(--primary-soft); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; flex-wrap: wrap; }
.bulkbar select { width: auto; }

/* form view */
.formwrap { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; align-items: start; }
.statusbar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; justify-content: flex-end; }
.stagebtn { border: 1px solid var(--line); background: var(--panel); padding: 5px 11px; font-size: 12px; cursor: pointer; border-radius: 14px; white-space: nowrap; }
.stagebtn:hover { border-color: var(--primary); }
.stagebtn.on { color: #fff; border-color: transparent; font-weight: 650; }
.titlein { font-size: 22px; font-weight: 650; border: 0 !important; border-bottom: 1px solid transparent !important; border-radius: 0 !important; padding: 2px 0 !important; box-shadow: none !important; background: transparent !important; }
.titlein:focus { border-bottom-color: var(--primary) !important; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 14px 0 12px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); white-space: nowrap; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.contactbox { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--panel2); }
.ribbon { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 6px; display: inline-block; }

/* lines editor */
.lines td input { padding: 5px 7px; }
.lines td.q input { width: 70px; text-align: right; }
.lines td.p input { width: 110px; text-align: right; }
.thumb { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; background: var(--panel2); border: 1px solid var(--line2); flex: none; }
.picker { position: relative; }
.dropdown { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow-lg); z-index: 40; max-height: 380px; overflow-y: auto; }
.ditem { display: flex; gap: 10px; align-items: center; padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line2); }
.ditem:hover, .ditem.hl { background: var(--primary-soft); }
.ditem .n { font-weight: 550; }

/* chatter */
.chatter { position: sticky; top: 62px; max-height: calc(100vh - 76px); overflow-y: auto; }
.msg { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line2); }
.msg .b { white-space: pre-wrap; word-break: break-word; }
.msg.sys .b { color: var(--muted); font-size: 13px; }
.act { display: flex; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--panel); border-left: 4px solid var(--ok); }
.act.overdue { border-left-color: var(--bad); } .act.today { border-left-color: var(--warn); } .act.done { border-left-color: var(--faint); opacity: .8; }
.acticon { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }

/* activities list */
.alist .act { align-items: center; }
.bucket-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.bucket-tabs button { border: 1px solid var(--line); background: var(--panel); border-radius: 18px; padding: 6px 14px; cursor: pointer; }
.bucket-tabs button.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.bucket-tabs .n { font-weight: 700; margin-left: 4px; }

/* calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-left: 1px solid var(--line); border-top: 1px solid var(--line); background: var(--panel); border-radius: 8px; overflow: hidden; }
.cal .dh { padding: 6px 8px; font-size: 12px; font-weight: 650; color: var(--muted); background: var(--panel2); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cal .day { min-height: 112px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal.week .day { min-height: 60vh; }
.cal .day.other { background: var(--panel2); }
.cal .day.today .dn span { background: var(--primary); color: #fff; border-radius: 10px; padding: 0 7px; }
.cal .dn { font-size: 12px; font-weight: 650; align-self: flex-start; display: flex; gap: 6px; width: 100%; }
.cal .dn button { margin-left: auto; border: 0; background: none; cursor: pointer; color: var(--faint); padding: 0 2px; }
.cal .dn button:hover { color: var(--primary); }
.cev { font-size: 11.5px; border-radius: 4px; padding: 2px 5px; cursor: pointer; background: var(--ok-soft); color: var(--text); border-left: 3px solid var(--ok); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cev.overdue { background: var(--bad-soft); border-left-color: var(--bad); }
.cev.done { opacity: .55; text-decoration: line-through; border-left-color: var(--faint); background: var(--panel2); }
.cev.today { background: var(--warn-soft); border-left-color: var(--warn); }

/* reports */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px; }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 2px; }
.kpi .l { font-size: 12px; color: var(--muted); font-weight: 600; }
.repgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.hbar { display: grid; grid-template-columns: 160px 1fr 90px; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.hbar .track { background: var(--panel2); border-radius: 4px; height: 14px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 4px; background: var(--primary); }
.vbars { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 10px; }
.vbars .b { flex: 1; background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.vbars .b:hover::after { content: attr(data-t); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--panel); font-size: 11px; padding: 2px 6px; border-radius: 4px; white-space: nowrap; }

/* modal / toast / popover */
.overlay { position: fixed; inset: 0; background: rgba(15,18,30,.45); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-width: 620px; }
.modal.wide { max-width: 860px; }
.modal .mh { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 650; font-size: 16px; }
.modal .mb { padding: 16px 18px; }
.modal .mf { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.x { margin-left: auto; background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1; }
.toasts { position: fixed; right: 16px; top: 60px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--panel); border-radius: 8px; padding: 10px 14px; box-shadow: var(--shadow-lg); display: flex; gap: 10px; align-items: flex-start; }
.toast.err { background: var(--bad); color: #fff; }
.toast.reminder { background: var(--panel); color: var(--text); border: 2px solid var(--warn); }
.toast .tt { font-weight: 650; }
.toast button { background: none; border: 0; color: inherit; cursor: pointer; font-size: 16px; opacity: .7; }
.pop { position: absolute; z-index: 90; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg); width: 360px; max-width: calc(100vw - 20px); max-height: 70vh; overflow-y: auto; color: var(--text); }
.pop .ph { padding: 10px 14px; font-weight: 650; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.pop .pi { padding: 10px 14px; border-bottom: 1px solid var(--line2); cursor: pointer; }
.pop .pi:hover { background: var(--panel2); }
.pop .pi.unread { border-left: 3px solid var(--primary); }
.menu { position: absolute; z-index: 90; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow-lg); min-width: 190px; padding: 4px 0; color: var(--text); }
.menu button, .menu a { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 14px; cursor: pointer; color: var(--text); }
.menu button:hover, .menu a:hover { background: var(--panel2); text-decoration: none; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.lookup { border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); padding: 10px 12px; margin-bottom: 12px; font-size: 13px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* auth */
.authwrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #1e1b4b, #312e81 55%, #4338ca); }
.authcard { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 400px; padding: 28px; }
.authcard h1 { margin: 0 0 4px; font-size: 22px; }

@media (max-width: 1100px) {
  .formwrap { grid-template-columns: 1fr; }
  .chatter { position: static; max-height: none; }
}
@media (max-width: 760px) {
  main { padding: 0 10px 40px; }
  .nav { flex-wrap: wrap; height: auto; padding: 6px 10px; }
  .brand { margin-right: auto; }
  .navlinks { order: 3; flex: 0 0 100%; padding-bottom: 4px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .col { flex-basis: 84vw; }
  .hbar { grid-template-columns: 100px 1fr 70px; }
  .repgrid { grid-template-columns: 1fr; }
  .cal .day { min-height: 70px; }
  .cev { font-size: 10px; }
  .hide-m { display: none !important; }
  .statusbar { justify-content: flex-start; }
}
