/* ReqForge — editorial / document-grade. Typography-forward, calm monochrome paper,
   serif display headings, one restrained accent, muted per-project tones. */
:root {
  --accent: #3f4a63;          /* restrained slate-indigo: focus, active, primary */
  --accent-weak: #e7eaf1;
  --ink: #20232b;             /* primary text + near-black buttons */
  --ink-2: #2c303a;
  --muted: #636974;
  --faint: #969ca7;
  --line: #d8dbe1;            /* table/border lines */
  --line-soft: #e8eaee;
  --line-strong: #c8ccd4;
  --bg: #f5f4f1;             /* warm paper canvas */
  --bg-2: #eceef1;
  --surface: #ffffff;
  --theme: #eef0f3;          /* per-project page wash (overridden in JS) */
  --theme-row: #f4f5f7;      /* quiet zebra tint */
  --theme-edge: #5b6472;     /* muted identifier accent */
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(20,22,30,.05);
  --shadow: 0 1px 3px rgba(20,22,30,.06), 0 10px 28px rgba(20,22,30,.06);
  --shadow-lg: 0 14px 40px rgba(20,22,30,.16);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: "Inter", system-ui, "Segoe UI", sans-serif;
  margin: 0; color: var(--ink);
  background-color: var(--bg);
  transition: background-color .4s ease;
  -webkit-font-smoothing: antialiased; font-size: 13px; line-height: 1.45;
}

/* Serif display for headings — the editorial signature. */
.brand, .page-head h2, .panel-head h2, .proj-card h3, dialog h3, .diagram-head h2 {
  font-family: var(--serif);
}

/* ---------- Icons ---------- */
.ic { flex: 0 0 auto; display: inline-block; vertical-align: -2px; }
button .ic + span { margin-left: 1px; }

/* ---------- Buttons ---------- */
button {
  font: inherit; font-weight: 500; font-size: 12.5px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 6px 12px; border-radius: var(--radius-sm);
  transition: background .14s, border-color .14s, box-shadow .14s, transform .04s, color .14s;
}
button:hover { background: #f5f6f8; border-color: var(--line-strong); }
button:active { transform: translateY(.5px); }
button.primary {
  background: var(--ink); border-color: var(--ink); color: #fff; box-shadow: var(--shadow-sm);
}
button.primary:hover { background: #14161d; border-color: #14161d; }
button.danger { color: #b23b30; border-color: var(--line); background: var(--surface); }
button.danger:hover { background: #fbecea; border-color: #e6b8b4; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { background: var(--bg-2); color: var(--ink); }
/* Compact square icon-only buttons. */
button.icon-btn { padding: 5px; color: var(--muted); }
button.icon-btn:hover { color: var(--ink); }
button.danger.icon-btn { color: var(--muted); }
button.danger.icon-btn:hover { color: #b23b30; background: #fbecea; border-color: #e6b8b4; }
select {
  font: inherit; font-size: 12.5px; padding: 5px 9px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
}
select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }

/* ---------- App bar ---------- */
.appbar {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 11px 22px; position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 9px; font-size: 16px; font-weight: 600; cursor: pointer; letter-spacing: -.01em; white-space: nowrap; }
.logo {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px;
  background: var(--ink); color: #fff; font-weight: 600; font-size: 13px; font-family: var(--serif);
}
/* Primary "back to projects" nav, next to the brand. Divider signals it's a nav step. */
.nav-back { position: relative; font-weight: 600; }
.nav-back::before { content: ""; position: absolute; left: -8px; top: 50%; transform: translateY(-50%); width: 1px; height: 20px; background: var(--line); }
/* No brand to separate from when editing → drop the divider. */
.appbar.is-editing .nav-back::before { display: none; }
.appbar-context { flex: 1; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar-context strong { color: var(--ink); font-weight: 600; }
.appbar-actions { display: flex; gap: 6px; align-items: center; }
#authSlot { display: flex; gap: 6px; align-items: center; }
.user-chip { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink); }
.user-chip .user-ini {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent, #2B6CB0); color: #fff; font-weight: 600; font-size: 11px;
}
.user-chip .user-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- People (avatars, chips, pickers) ---------- */
.avatar {
  display: inline-grid; place-items: center; border-radius: 50%; overflow: hidden; flex: 0 0 auto;
  background: var(--accent, #2B6CB0); color: #fff; font-weight: 600; line-height: 1;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.user-chip-sm { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink); max-width: 100%; }
.user-chip-sm .ucs-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip-sm.clickable { cursor: pointer; }
.person-field { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; }
.person-add { border: 1px dashed var(--line); background: transparent; color: var(--muted); border-radius: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer; }
.person-add:hover { color: var(--ink); border-color: var(--line-soft); }
.person-clear { border: none; background: transparent; color: var(--faint); cursor: pointer; font-size: 14px; line-height: 1; padding: 0 2px; }
.person-clear:hover { color: #c0392b; }
.person-search { width: 100%; min-width: 120px; padding: 4px 7px; border: 1px solid var(--accent); border-radius: 6px; font: inherit; font-size: 12px; }
.person-search:focus { outline: none; box-shadow: 0 0 0 2px var(--accent-weak); }
.person-results { padding: 4px; max-height: 280px; overflow-y: auto; z-index: 1000; }
.person-result { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; background: transparent; border: none; border-radius: 6px; padding: 6px 7px; cursor: pointer; }
.person-result:hover { background: var(--bg-2); }
.pr-text { display: flex; flex-direction: column; min-width: 0; }
.pr-name { font-size: 12.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pr-role { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-empty { display: block; padding: 6px 8px; font-size: 12px; }
.proj-owner { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.proj-owner-lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 700; }

/* Library: Todos / A minha área toggle */
.lib-toggle { display: inline-flex; background: var(--bg-2); border-radius: 999px; padding: 2px; margin-left: 4px; }
.lib-toggle-btn { border: none; background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 600; padding: 5px 13px; border-radius: 999px; cursor: pointer; }
.lib-toggle-btn.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* "Atribuídos a mim" panel */
/* Compact list rows (person detail panel). */
.pd-item .ai-code { font-weight: 600; color: var(--accent); font-size: 12.5px; min-width: 48px; }
.pd-item .ai-desc { flex: 1; min-width: 0; color: var(--ink); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pd-item .ai-proj { color: var(--muted); font-size: 11.5px; background: var(--bg-2); border-radius: 999px; padding: 2px 9px; }

/* Team (Entra group) chip */
.team-chip { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-weak); border-radius: 999px; padding: 3px 11px; }
.team-chip.clickable { cursor: pointer; }

/* Editor bar: push Histórico toward the export side */
.tgroup-history { margin-left: auto; }
.tgroup-end { margin-left: 14px; }

/* Document History drawer */
.history-backdrop { position: fixed; inset: 0; background: rgba(20,24,33,.34); z-index: 200; animation: rfFade .14s ease both; }
.history-drawer { position: fixed; top: 0; right: 0; height: 100vh; width: 440px; max-width: 94vw; background: var(--surface); box-shadow: -8px 0 30px rgba(0,0,0,.16); z-index: 201; display: flex; flex-direction: column; animation: hdSlide .18s ease both; }
@keyframes hdSlide { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.hd-head { display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.hd-head h3 { margin: 0; flex: 1; font-size: 15px; }
.hd-close { border: none; background: transparent; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; }
.hd-close:hover { color: var(--ink); }
.hd-body { flex: 1; overflow-y: auto; padding: 8px 0 30px; }
.hd-section-title, .hd-day { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: 12px 18px 6px; }
/* Day headers stay pinned while scrolling a long timeline so context is never lost. */
.hd-day { position: sticky; top: 0; z-index: 1; background: var(--surface); }
.hd-badge { display: inline-block; margin-left: 4px; padding: 1px 7px; border-radius: 999px; background: var(--bg-2); color: var(--muted); font-size: 10px; }
.hd-versions { border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.hd-vmore, .hd-vnote { margin: 4px 18px 2px; }
.hd-vmore { padding: 4px 10px; font-size: 11.5px; }
.hd-vnote { font-size: 11px; }
.hd-more { display: flex; justify-content: center; padding: 12px 18px 4px; }
.hd-more button { padding: 7px 16px; font-size: 12px; }
.hd-version { display: flex; flex-direction: column; gap: 3px; padding: 8px 18px; }
.hd-vlabel { font-size: 12.5px; font-weight: 600; color: var(--ink); display: flex; align-items: center; gap: 6px; }
.hd-vlabel .ic { width: 13px; height: 13px; color: var(--accent); }
.hd-vmeta { font-size: 11px; color: var(--muted); }
.hd-vactions { display: flex; gap: 6px; margin-top: 4px; }
.hd-vactions button { padding: 3px 10px; font-size: 11.5px; }
.hd-entry { display: flex; gap: 10px; padding: 9px 18px; }
.hd-entry:hover { background: var(--theme-row); }
.hd-entry-main { flex: 1; min-width: 0; }
.hd-entry-top { display: flex; align-items: baseline; gap: 8px; }
.hd-who { font-weight: 600; font-size: 12.5px; color: var(--ink); }
.hd-when { font-size: 11px; color: var(--faint); margin-left: auto; white-space: nowrap; }
.hd-summary { font-size: 12.5px; color: var(--muted); }
.hd-changes { margin-top: 4px; }
.hd-changes summary { font-size: 11.5px; color: var(--accent); cursor: pointer; }
.hd-change { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 11.5px; margin: 4px 0 0; }
.hd-field { font-weight: 600; color: var(--muted); }
.hd-old { color: #b85450; text-decoration: line-through; opacity: .8; }
.hd-new { color: #2f7d4f; }
.hd-arrow { color: var(--faint); }

/* Recent activity feed (library) */
.activity-panel { margin-bottom: 18px; }
.activity-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: transparent; border: none; border-bottom: 1px solid var(--line); padding: 9px 16px; cursor: pointer; }
.activity-item:last-child { border-bottom: none; }
.activity-item:hover { background: var(--theme-row); }
.activity-item .act-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.activity-item .act-summary { font-size: 12.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-item .act-meta { font-size: 11px; color: var(--muted); }

/* Field-level "a teammate changed this" marker */
td { position: relative; }
.field-stale { background: #fff7e6 !important; border-color: #f0d6a0 !important; opacity: .85; }
.field-refresh {
  position: absolute; top: 3px; right: 3px; z-index: 5; width: 20px; height: 20px; padding: 0;
  border: 1px solid #f0d6a0; background: #fff; color: #9a5b00; border-radius: 50%;
  font-size: 12px; line-height: 1; cursor: pointer; display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
}
.field-refresh:hover { background: #fff7e6; }

/* "Changes available" collaboration banner */
.changes-banner { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 250; display: flex; align-items: center; gap: 12px; background: var(--ink); color: #fff; border-radius: 999px; padding: 9px 10px 9px 18px; box-shadow: var(--shadow); font-size: 13px; animation: rfFade .18s ease both; }
.changes-banner button { padding: 5px 14px; font-size: 12.5px; }
.changes-banner .ghost { color: #cfd6e0; }
.changes-banner .ghost:hover { color: #fff; background: rgba(255,255,255,.12); }

/* Live presence strip (app bar) */
.presence-strip { display: inline-flex; align-items: center; gap: 4px; margin-left: 12px; }
.presence-strip[hidden] { display: none; }
.presence-chip { display: inline-flex; margin-left: -6px; border: 2px solid var(--surface); border-radius: 50%; }
.presence-chip:first-child { margin-left: 0; }
.presence-label { font-size: 11.5px; color: var(--muted); margin-left: 8px; white-space: nowrap; }

/* Read-only version banner */
.version-banner { display: flex; align-items: center; gap: 12px; background: #fff7e6; border: 1px solid #f0d6a0; color: #8a5b00; border-radius: var(--radius); padding: 10px 16px; margin-bottom: 16px; }
.version-banner .vb-text { flex: 1; font-size: 13px; }
.version-banner b { color: #6a4600; }
.ro-table input, .ro-table textarea { pointer-events: none; }

/* Contact (mailto) affordance on chips */
.chip-mail, .pc-mail { text-decoration: none; color: var(--muted); font-size: 12px; padding: 0 3px; border-radius: 4px; }
.chip-mail:hover, .pc-mail:hover { color: var(--accent); background: var(--accent-weak); }

/* Pessoas page */
.people-grid { margin-top: 16px; }
.people-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); margin: 18px 0 12px; }
.people-section-title:first-child { margin-top: 6px; }
.people-section-title .pst-count { font-weight: 600; color: var(--muted); background: var(--bg-2); border-radius: 999px; padding: 1px 8px; margin-left: 6px; }
.people-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.person-card { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow-sm); }
.person-card.clickable { cursor: pointer; transition: border-color .14s, box-shadow .14s; }
.person-card.clickable:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.person-card .pc-info { flex: 1; min-width: 0; }
.person-card .pc-name { font-weight: 600; font-size: 13.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-card .pc-sub { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-card .pc-pills { display: flex; flex-wrap: wrap; gap: 4px; }
.person-card .pc-mail { font-size: 15px; }

/* Person detail dialog */
.person-dialog { border: none; border-radius: 12px; padding: 20px; max-width: 560px; width: 92vw; box-shadow: var(--shadow); }
.person-dialog::backdrop { background: rgba(20,24,33,.42); }
.pd-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.pd-head h3 { margin: 0; }
.pd-section { margin-top: 14px; }
.pd-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); margin-bottom: 6px; }
.pd-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: transparent; border: none; border-bottom: 1px solid var(--line); padding: 8px 4px; cursor: pointer; }
.pd-item:hover { background: var(--theme-row); }

/* Wizard "Envolvidos" roster */
.wz-roster { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.wz-roster-group { margin-bottom: 8px; }
.wz-roster-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 700; margin-bottom: 4px; }
.wz-roster-group .user-chip-sm { display: flex; margin: 3px 0; }
.mode-badge { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.mode-badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.mode-badge.is-local { background: #fef3e2; color: #9a5b00; border: 1px solid #f3d09a; }
.mode-badge.is-shared { background: #e7f0fb; color: #1d5fae; border: 1px solid #bcd6f3; }
.login-gate { max-width: 420px; margin: 14vh auto 0; text-align: center; display: grid; gap: 12px; justify-items: center; }
.login-gate h2 { margin: 0; }
.login-gate p { margin: 0; }

/* ---------- Editor toolbar ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center;
  padding: 10px 22px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.tgroup { display: flex; align-items: center; gap: 6px; }
.tgroup + .tgroup { padding-left: 16px; border-left: 1px solid var(--line-soft); }
.tlabel { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); margin-right: 1px; }
.tgroup-end { margin-left: auto; padding-left: 0; border-left: none; }

/* ---------- Tabs (segmented) ---------- */
nav#tabs {
  display: inline-flex; gap: 2px; margin: 0; padding: 3px;
  background: var(--bg-2); border-radius: 8px;
}
nav#tabs button {
  border: none; background: transparent; color: var(--muted); font-weight: 500; font-size: 12.5px;
  padding: 5px 13px; border-radius: 6px;
}
nav#tabs button:hover { color: var(--ink); background: transparent; }
nav#tabs button.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm); }

.workspace { display: flex; gap: 22px; align-items: flex-start; padding: 26px 24px 48px; max-width: 1500px; margin: 0 auto; }
main { flex: 1; min-width: 0; }

/* ---------- Smooth entrance / loading ---------- */
/* Opacity-only fade: must NOT animate transform — a filling transform animation makes the
   panel a containing block for position:fixed children, trapping the Tipo dropdown inside the
   panel's overflow:hidden. Opacity keeps the entrance smooth without that side effect. */
@keyframes rfFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rfSpin { to { transform: rotate(360deg); } }
/* Section panels swap instantly (no per-switch fade → no flicker); the library/login still fade. */
.lib-group, .login-gate, .page-head { animation: rfFade .18s ease both; }
.boot-loader { display: grid; place-items: center; min-height: 55vh; }
.boot-loader::after {
  content: ''; width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: rfSpin .7s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .panel, .lib-group, .login-gate, .page-head { animation: none; }
  .boot-loader::after { animation-duration: 1.6s; }
}

/* ---------- Section progress wizard ---------- */
.wizard {
  position: sticky; top: 22px; width: 250px; flex: 0 0 250px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 17px 16px 15px; box-shadow: var(--shadow-sm);
}
.wz-title { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; color: var(--faint); margin-bottom: 11px; }
.wz-progress-row { display: flex; align-items: center; gap: 9px; margin-bottom: 16px; }
.wz-bar { flex: 1; height: 5px; background: var(--bg-2); border-radius: 999px; overflow: hidden; }
.wz-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .35s ease; }
.wz-count { font-size: 11.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.wz-steps { display: flex; flex-direction: column; gap: 2px; }
.wstep {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: transparent; border: 1px solid transparent; border-radius: 7px; padding: 7px 8px;
  cursor: pointer; transition: background .12s;
}
.wstep:hover { background: var(--bg-2); border-color: transparent; }
.wstep.active { background: var(--accent-weak); }
.wstep.active .wstep-name { color: var(--accent); font-weight: 600; }
.wstep-mark {
  flex: 0 0 auto; width: 17px; height: 17px; border-radius: 50%;
  border: 1.5px solid var(--line); display: grid; place-items: center;
  font-size: 10px; color: transparent; background: var(--surface);
}
.wstep-mark.done { background: var(--accent); border-color: var(--accent); color: #fff; }
.wstep-mark.todo-essential { border-color: var(--accent); border-style: dashed; }
.wstep-body { flex: 1; min-width: 0; }
.wstep-name { display: block; font-size: 12.5px; color: var(--ink); line-height: 1.25; }
.wstep-sub { display: block; font-size: 10.5px; color: var(--faint); }
.wstep-num { font-size: 11px; font-weight: 700; color: var(--muted); background: var(--bg-2); padding: 1px 7px; border-radius: 999px; min-width: 20px; text-align: center; }
.wstep-num.zero { color: var(--faint); background: transparent; }
.wz-hint { margin-top: 13px; padding-top: 12px; border-top: 1px solid var(--line-soft); font-size: 11.5px; color: var(--muted); line-height: 1.4; display: flex; gap: 7px; align-items: flex-start; }
.wz-hint .ic { color: var(--accent); margin-top: 1px; }
.wz-hint b { color: var(--ink); font-weight: 600; }
@media (max-width: 860px) { .wizard { display: none !important; } }

/* ---------- Content panel (frames the table) ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 11px;
  padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.panel-head h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.panel-head .grow { flex: 1; }
.panel-count { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--bg-2); padding: 2px 9px; border-radius: 999px; }
.panel-updated { font-size: 11px; color: var(--faint); white-space: nowrap; }
/* Little "Guardar" button beside the stamp — same subtle weight as the timestamp. */
.panel-save {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  font-size: 11px; font-weight: 500; color: var(--faint); cursor: pointer;
  background: transparent; border: 1px solid transparent; border-radius: 999px;
  padding: 2px 9px; transition: color .12s, background .12s, border-color .12s;
}
.panel-save .ic { width: 13px; height: 13px; }
.panel-save:hover { color: var(--ink); background: var(--bg-2); border-color: var(--line-soft); }
.panel-body { padding: 0; }
.panel-empty { padding: 44px 22px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.6; }
.panel-empty b { color: var(--ink); }

/* ---------- Data tables — quiet grid, comfortable ---------- */
table {
  border-collapse: collapse; width: 100%; font-size: 12.5px;
  background: var(--surface); table-layout: fixed;
}
td { word-break: break-word; }
.panel-body table { border: none; }
.panel-body th { border-top: none; }
.panel-body tr td:first-child, .panel-body tr th:first-child { border-left: none; }
.panel-body tr td:last-child, .panel-body tr th:last-child { border-right: none; }
.panel-body tr:last-child td { border-bottom: none; }
th, td { padding: 5px 9px; text-align: left; vertical-align: top; border: 1px solid var(--line-soft); }
th {
  background: var(--surface); font-weight: 600; color: var(--faint);
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em;
  padding: 9px 9px; border-bottom: 1.5px solid var(--line);
  position: relative; /* anchors the column resize grip */
}
/* Draggable column-resize grip on the right edge of a header cell. */
.col-resizer {
  position: absolute; top: 0; right: -4px; width: 9px; height: 100%; z-index: 3;
  cursor: col-resize; touch-action: none;
}
.col-resizer::after {
  content: ""; position: absolute; top: 20%; right: 4px; width: 2px; height: 60%;
  background: transparent; border-radius: 1px; transition: background .12s;
}
.col-resizer:hover::after { background: var(--accent); }
/* While dragging, keep the resize cursor everywhere and stop text selection. */
body.col-resizing { cursor: col-resize; user-select: none; }
body.col-resizing * { cursor: col-resize !important; }
/* Zebra interlines use the project's muted tone. */
.panel-body table tr:nth-child(even) td { background: var(--theme-row); }
.panel-body table tr:hover td { box-shadow: inset 0 0 0 9999px rgba(40,45,60,.035); }
td input, td textarea, td select {
  width: 100%; border: 1px solid transparent; padding: 3px 5px; font: inherit; font-size: 12.5px;
  background: transparent; resize: vertical; border-radius: 4px; color: var(--ink);
}
/* Editor text boxes auto-grow in height (JS) so they never show a vertical scrollbar; the
   user may still drag the height (resize: vertical) but never the width. */
td textarea, .sg-field textarea {
  box-sizing: border-box; overflow: hidden; resize: vertical; min-height: 2.4em;
}
td input:focus, td textarea:focus, td select:focus { border-color: var(--accent); background: #fff; outline: none; box-shadow: 0 0 0 2px var(--accent-weak); }
th.actions, td.actions { width: 96px; white-space: nowrap; text-align: center; }
/* Keep the cell a real table-cell so it fills the full row height (its background too);
   lay the buttons out inline-centered rather than turning the <td> into a flex box. */
td.actions { vertical-align: middle; }
td.actions button { padding: 4px; display: inline-flex; vertical-align: middle; }
td.actions button + button { margin-left: 3px; }
.add-row { margin-top: 14px; }
.drag-handle { cursor: grab; color: var(--faint); user-select: none; font-size: 14px; }
tr.dragging { opacity: .4; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.6; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--ink); color: #fff; padding: 10px 15px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s;
  max-width: 320px;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #b23b30; }

/* ---------- Library page ---------- */
.library-search-wrap { position: relative; width: 100%; max-width: 440px; margin-bottom: 22px; }
.library-search-wrap .ic { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.library-search {
  width: 100%; padding: 10px 14px 10px 38px;
  border: 1px solid var(--line-strong); border-radius: 8px; font: inherit; font-size: 13px; background: var(--surface);
}
.library-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.page-head { display: flex; align-items: center; gap: 9px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -.02em; flex: 1; }
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.lib-group { margin-bottom: 30px; }
.lib-group-head { display: flex; align-items: center; gap: 9px; margin-bottom: 13px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.lib-group-name { font-family: var(--serif); font-size: 15px; font-weight: 600; color: var(--ink); letter-spacing: -.01em; }
.lib-group-count { font-size: 11px; font-weight: 600; color: var(--muted); background: var(--bg-2); padding: 1px 9px; border-radius: 999px; }
.proj-card {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 17px 17px 17px 19px; display: flex; flex-direction: column; gap: 9px; box-shadow: var(--shadow-sm);
  transition: box-shadow .16s, transform .16s, border-color .16s; cursor: pointer; overflow: hidden;
}
/* Thin muted identifier stripe per project. */
.proj-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--card-edge, var(--theme-edge)); }
.proj-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); border-color: var(--line-strong); }
.proj-top { display: flex; align-items: center; gap: 11px; }
.proj-avatar {
  width: 36px; height: 36px; border-radius: 8px; flex: 0 0 auto; display: grid; place-items: center;
  color: var(--ink); font-weight: 600; font-size: 15px; font-family: var(--serif);
  background: var(--bg-2); border: 1px solid var(--line-soft);
}
.proj-card h3 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
.proj-meta { font-size: 12px; color: var(--muted); }
.proj-stats { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.pill { background: var(--bg-2); color: var(--muted); font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line-soft); }
.pill.accent { background: var(--accent-weak); color: var(--accent); border-color: transparent; }
.proj-actions { display: flex; gap: 6px; margin-top: 8px; padding-top: 13px; border-top: 1px solid var(--line-soft); }
.proj-actions .grow { flex: 1; }
.proj-actions button { padding: 6px 12px; }
.proj-actions button.icon-btn { padding: 6px; }

/* ---------- Project origin (desktop: local vs shared) ---------- */
.origin-badge {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px; border: 1px solid transparent;
}
.origin-badge.is-local  { background: #eef1f4; color: #47525f; border-color: #dde2e8; }
.origin-badge.is-shared { background: #e7f1e9; color: #2f6b45; border-color: #cfe6d6; }
/* Project scope (shared with team vs personal). */
.origin-badge.is-team     { background: #e7f1e9; color: #2f6b45; border-color: #cfe6d6; }
.origin-badge.is-personal { background: #f3ecdf; color: #8a5a1f; border-color: #e6d6bd; }

/* Shared/personal choice in the project dialog. */
.scope-toggle { display: inline-flex; gap: 4px; background: var(--bg-2); border-radius: 8px; padding: 3px; margin-bottom: 6px; }
.scope-opt { border: none; background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 600; padding: 6px 14px; border-radius: 6px; cursor: pointer; }
.scope-opt.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.lib-source {
  display: flex; align-items: center; gap: 9px; margin-bottom: 16px; padding: 9px 14px;
  border-radius: var(--radius-sm); font-size: 12.5px; color: var(--ink);
  background: var(--bg-2); border: 1px solid var(--line-soft);
}
.lib-source .ls-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.lib-source.is-local  .ls-dot { background: #7d8894; }
.lib-source.is-shared .ls-dot { background: #3f9c63; }

/* ---------- Anchored action menu (project cards, "Mais") ---------- */
.card-menu {
  position: fixed; z-index: 1100; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 5px; min-width: 210px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 1px;
}
.card-menu-item {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  border: none; background: transparent; color: var(--ink); font: inherit; font-size: 12.5px;
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.card-menu-item:hover { background: var(--bg-2); }
.card-menu-item .ic { color: var(--muted); }
.card-menu-item.danger { color: #b23b30; }
.card-menu-item.danger .ic { color: #b23b30; }
.card-menu-item.danger:hover { background: #fbecea; }
.card-menu-sep { height: 1px; background: var(--line-soft); margin: 4px 2px; }

/* ---------- Ecrãs (two-level screen groups) ---------- */
.screens-body { padding: 14px; display: flex; flex-direction: column; gap: 16px; background: transparent; }
.screen-group { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; }
.sg-hdr { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--theme-row); border-bottom: 1px solid var(--line); }
.sg-title { flex: 1; font-weight: 600; font-size: 13.5px; border: 1px solid transparent !important; background: transparent; padding: 4px 6px; border-radius: 5px; }
.sg-title:focus { border-color: var(--accent) !important; background: #fff; box-shadow: 0 0 0 2px var(--accent-weak); outline: none; }
.sg-hdr .danger { padding: 4px 10px; font-size: 11.5px; }
.sg-meta { display: flex; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
.sg-field { flex: 1; font-size: 11px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.sg-field > span { font-weight: 600; text-transform: uppercase; letter-spacing: .05em; font-size: 10px; }
.sg-field textarea, .sg-field select { border: 1px solid var(--line); border-radius: 5px; padding: 5px 7px; font: inherit; font-size: 12.5px; background: #fff; color: var(--ink); }
.sg-field textarea:focus, .sg-field select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px var(--accent-weak); }
.sg-req { flex: 0 0 130px; }
.sg-type { flex: 0 0 170px; }
.sg-table { padding: 0; }
.sg-table table { border: none; border-radius: 0; box-shadow: none; }
.sg-table th { border-top: none; }
.sg-table tr td:first-child, .sg-table tr th:first-child { border-left: none; }
.sg-table tr td:last-child, .sg-table tr th:last-child { border-right: none; }
.sg-add { margin: 10px 12px; padding: 5px 12px; font-size: 12px; }

/* ---------- Diagram cell + editor ---------- */
.diagram-cell { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.diagram-thumb {
  max-width: 100%; max-height: 84px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; cursor: pointer; box-shadow: var(--shadow-sm);
}
.diagram-cell button { padding: 4px 10px; font-size: 12px; }
.diagram-dialog {
  width: 94vw; height: 90vh; max-width: none; max-height: none; padding: 0; border-radius: 12px; overflow: hidden;
}
.diagram-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.diagram-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.diagram-head .grow { flex: 1; }
.diagram-frame { width: 100%; height: calc(90vh - 53px); border: none; display: block; }
/* bpmn-js modeler canvas — must have an explicit height and be positioned for the palette. */
.bpmn-canvas { width: 100%; height: calc(90vh - 53px); position: relative; background: #fff; overflow: hidden; }
.bpmn-canvas .djs-palette { top: 12px; left: 12px; }

/* ---------- Multi-tag dropdown ---------- */
details.multitag { position: relative; }
details.multitag > summary {
  cursor: pointer; list-style: none; padding: 3px 7px; border: 1px solid var(--line);
  border-radius: 5px; background: #fff; min-height: 22px; font-size: 12px; color: var(--ink);
}
details.multitag > summary::-webkit-details-marker { display: none; }
details.multitag[open] > summary { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-weak); }
.multitag-list {
  /* Positioned (top/left) in JS as `fixed` so it escapes the panel's
     overflow:hidden clip — see setupMultitagDropdown() in app.js. */
  position: fixed; z-index: 1000; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px; min-width: 158px; box-shadow: var(--shadow);
}
.multitag-list label { display: flex; align-items: center; gap: 8px; padding: 5px 7px; border-radius: 5px; cursor: pointer; font-size: 12.5px; }
.multitag-list label:hover { background: var(--bg-2); }
.multitag-list input { width: auto; accent-color: var(--accent); }

/* ---------- Dialogs ---------- */
dialog {
  border: none; border-radius: 12px; padding: 26px; min-width: 380px; max-width: 480px;
  box-shadow: var(--shadow-lg); color: var(--ink); animation: pop .15s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.985); } to { opacity: 1; transform: none; } }
dialog::backdrop { background: rgba(18,20,30,.42); backdrop-filter: blur(2px); }
dialog h3 { margin: 0 0 14px; font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
dialog label { display: block; margin: 13px 0 5px; font-size: 12px; font-weight: 500; color: var(--muted); }
dialog input { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 7px; font: inherit; }
dialog input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 22px; }
.dialog-checks { display: flex; flex-wrap: wrap; gap: 7px; padding: 3px 0 2px; }
.dialog-checks .check {
  display: flex; align-items: center; gap: 6px; font-size: 12.5px; cursor: pointer;
  padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px; transition: border-color .12s, background .12s;
}
.dialog-checks .check:hover { border-color: var(--accent); background: var(--accent-weak); }
.dialog-checks .check input { width: auto; accent-color: var(--accent); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0 2px; }
.swatch {
  width: 32px; height: 32px; padding: 0; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line-soft); box-shadow: var(--shadow-sm);
  transition: transform .1s, box-shadow .12s;
}
.swatch:hover { transform: translateY(-1px); }
.swatch.sel { border: 2px solid var(--ink); box-shadow: 0 0 0 3px var(--accent-weak); }

/* ---------- Row edit modal (buffered form) ---------- */
dialog.row-edit { min-width: 520px; max-width: 560px; }
.row-edit .re-body { max-height: 68vh; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.row-edit .re-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 15px; }
.row-edit .re-field > label { margin: 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.row-edit .re-field select { width: 100%; }
.row-edit .re-textarea {
  width: 100%; min-height: 92px; resize: vertical; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 7px; font: inherit; line-height: 1.5;
}
.row-edit .re-textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.row-edit .re-checks { display: flex; flex-wrap: wrap; gap: 7px; }
.row-edit .re-check {
  display: flex; align-items: center; gap: 6px; margin: 0; font-size: 12.5px; color: var(--ink); cursor: pointer;
  padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px; transition: border-color .12s, background .12s;
}
.row-edit .re-check:hover { border-color: var(--accent); background: var(--accent-weak); }
.row-edit .re-check input { width: auto; accent-color: var(--accent); }
.row-edit .re-diagram { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.row-edit .re-hint { font-size: 11.5px; color: var(--muted); }
.row-edit .re-foot { margin-top: 8px; }
