:root {
  /* Identidade visual do Grupo DEMX: azul #001B38, vermelho-laranja #EE3025, grafite #383838. */
  --brand: #001B38;
  --brand-2: #0d3563;
  --brand-soft: #e7ecf3;
  --primary: #001B38;
  --primary-2: #0d3563;
  --accent: #EE3025;
  --sidebar: #001B38;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #383838;
  --muted: #667085;
  --border: #e3e7ed;
  --won: #1f9d55;
  --won-soft: #e5f6ec;
  --lost: #d64545;
  --lost-soft: #fdecec;
  --warn: #c77700;
  --warn-soft: #fff4e0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #7fa8dc; --brand-2: #a3c1e8; --brand-soft: #16263a;
    --primary: #2d5f99; --primary-2: #3a70ad; --accent: #F2553D; --sidebar: #001B38;
    --bg: #11151b; --surface: #1a2029; --text: #e6eaf0; --muted: #98a2b3; --border: #2b3340;
    --won: #3cc37a; --won-soft: #173226; --lost: #f07070; --lost-soft: #3a1f22; --warn: #f0a93a; --warn-soft: #3a2d17;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* Layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: #fff; display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; letter-spacing: .02em; padding: 6px 10px 20px; }
.logo img { height: 24px; width: auto; display: block; }
.logo span { opacity: .75; font-weight: 600; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; padding-top: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; color: rgba(255,255,255,.85); padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.1); text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.nav .badge { margin-left: auto; background: var(--lost); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; }
.sidebar .me { margin-top: auto; font-size: 13px; padding: 10px; border-top: 1px solid rgba(255,255,255,.15); }
.sidebar .me button { background: none; border: 0; color: rgba(255,255,255,.75); padding: 0; cursor: pointer; font-size: 12px; }
.shell > div { min-width: 0; }
.main { padding: 22px 28px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .spacer { flex: 1; }

/* Mobile */
.topbar { display: none; }
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .shell.nav-open .sidebar { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--brand); color: #fff; font-weight: 700; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .main { padding: 16px; }
}

/* Components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 14px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.two-col { grid-template-columns: 2fr 1fr; }
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 13px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--brand-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.won { background: var(--won); border-color: var(--won); color: #fff; }
.btn.lost { background: var(--lost); border-color: var(--lost); color: #fff; }
.btn.ghost { border-color: transparent; background: none; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.danger { color: var(--lost); }
.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand-2); }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: auto; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; }

table.list { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table-wrap { overflow-x: auto; }
.list th, .list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.list th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: var(--bg); }
.list tr:last-child td { border-bottom: 0; }
.list tbody tr:hover { background: var(--brand-soft); cursor: pointer; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 24px; text-align: center; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; color: var(--muted); }

.pill { display: inline-block; padding: 1px 9px; border-radius: 12px; font-size: 12px; font-weight: 600; background: var(--brand-soft); color: var(--brand); }
.pill.won { background: var(--won-soft); color: var(--won); }
.pill.lost { background: var(--lost-soft); color: var(--lost); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.stars { color: #f5b301; letter-spacing: 1px; }

/* Kanban */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.column { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 260px; width: 260px; flex-shrink: 0; display: flex; flex-direction: column; max-height: calc(100vh - 170px); }
.column-head { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.column-head .name { font-weight: 700; }
.column-head .meta { font-size: 12px; color: var(--muted); }
.column-body { padding: 8px; overflow-y: auto; flex: 1; min-height: 80px; }
.column-body.drop { background: var(--brand-soft); }
.deal-card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; margin-bottom: 8px; cursor: grab; }
.deal-card:hover { border-color: var(--brand-2); }
.deal-card.dragging { opacity: .5; }
.deal-card .t { font-weight: 600; }
.deal-card .o { font-size: 12px; color: var(--muted); }
.deal-card .v { display: flex; justify-content: space-between; font-size: 12px; margin-top: 4px; }
.deal-card .v b { color: var(--won); }
.deal-card .age { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* Detail */
.detail-head { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 14px; }
.detail-head .title { flex: 1; min-width: 200px; }
.detail-head .title .sub { color: var(--muted); margin-top: 2px; }
.stagebar { display: flex; gap: 3px; margin-bottom: 14px; }
.stagebar button { flex: 1; border: 0; padding: 8px 6px; font: inherit; font-size: 12px; background: var(--border); color: var(--muted); cursor: pointer; clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 0 100%, 8px 50%); }
.stagebar button:first-child { clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 50%, calc(100% - 8px) 100%, 0 100%); border-radius: 6px 0 0 6px; }
.stagebar button.done { background: var(--brand-2); color: #fff; }
.stagebar button.current { background: var(--brand); color: #fff; font-weight: 700; }
dl.info { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; word-break: break-word; }
.section { margin-bottom: 14px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 12px; cursor: pointer; font: inherit; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 2px solid var(--border); padding: 0 0 14px 14px; position: relative; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand-2); }
.timeline li.system::before { background: var(--muted); }
.timeline .when { font-size: 12px; color: var(--muted); }
.timeline .body { white-space: pre-wrap; }

.task-row { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--border); }
.task-row:last-child { border-bottom: 0; }
.task-row .ti { flex: 1; min-width: 0; }
.task-row .ti .rel { font-size: 12px; color: var(--muted); }
.task-row.done .ti > span { text-decoration: line-through; color: var(--muted); }
.task-row .due { font-size: 12px; white-space: nowrap; }
.task-row .due.overdue { color: var(--lost); font-weight: 600; }

/* Bars */
.bars .row { display: grid; grid-template-columns: 140px 1fr auto; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 13px; }
.bars .track { background: var(--bg); border-radius: 6px; height: 14px; overflow: hidden; }
.bars .fill { background: var(--brand-2); height: 100%; border-radius: 6px; }

/* Modal & forms */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 100; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal header { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal header h2 { margin: 0; flex: 1; }
.modal .content { padding: 18px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .sep { grid-column: 1 / -1; font-weight: 700; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin-top: 6px; border-top: 1px solid var(--border); padding-top: 12px; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 4px; }
.checks .check { display: inline-flex; align-items: center; gap: 5px; font-weight: 400; color: var(--text); }
.checks .check input { width: auto; }
label.f, div.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.f .req { color: var(--lost); }
.error { color: var(--lost); margin-top: 8px; }

.lookup { position: relative; }
.lookup .opts { position: absolute; left: 0; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); z-index: 10; max-height: 220px; overflow-y: auto; }
.lookup .opts div { padding: 7px 10px; cursor: pointer; color: var(--text); }
.lookup .opts div:hover { background: var(--brand-soft); }

.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth .card { width: 100%; max-width: 380px; padding: 28px; }
.auth .logo { color: var(--brand); padding: 0 0 10px; font-size: 26px; }
.auth .logo img { height: 38px; }
.auth .logo span { color: var(--muted); }
.auth form { display: grid; gap: 12px; margin-top: 16px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1c2430; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 200; }
#toast.show { opacity: 1; }
#toast.err { background: var(--lost); }

.lookup-list { list-style: none; padding: 0; margin: 0; }
.lookup-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.lookup-list li span { flex: 1; }
.progress { background: var(--bg); border-radius: 8px; padding: 12px; margin-top: 12px; font-size: 13px; }

/* Acesso: somente leitura esconde ações de escrita; exportação só para administradores. */
.not-admin .admin-only { display: none !important; }
.ro #new-deal, .ro #new, .ro #edit, .ro #del, .ro #won, .ro #lost, .ro #reopen, .ro #edit-products,
.ro #note-form, .ro #add-task, .ro #new-person, .ro #edit-shares { display: none !important; }
.ro .stagebar button, .ro .task input[type=checkbox] { pointer-events: none; }
.shares { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.shares .pill small { opacity: .7; }
.temp-pass { font-family: ui-monospace, Consolas, monospace; font-size: 20px; letter-spacing: .08em; padding: 10px 14px; border: 1px dashed var(--border); border-radius: 8px; user-select: all; text-align: center; margin: 8px 0; }

/* Processo (Onda 1) */
.size-badge { display: inline-block; min-width: 22px; padding: 0 5px; border-radius: 5px; font-size: 11px; font-weight: 700; text-align: center; background: var(--brand-soft); color: var(--brand); vertical-align: 1px; }
.size-badge.size-G, .size-badge.size-GG { background: var(--accent); color: #fff; }
.deal-card .na { font-size: 12px; margin-top: 5px; padding: 3px 6px; border-radius: 6px; background: var(--bg); }
.deal-card .na.overdue, .next-action .overdue { color: var(--lost); font-weight: 600; }
.deal-card .na.missing { color: var(--warn); font-weight: 600; background: var(--warn-soft); }
.next-action { border-left: 4px solid var(--primary); }
.next-action.missing { border-left-color: var(--warn); }
.next-action .na-line { margin-bottom: 10px; }
.next-action .na-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.stagebar.readonly button { cursor: default; pointer-events: none; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
