:root {
  color-scheme: light;
  --ink: #10212b;
  --muted: #667784;
  --line: #d9e4ea;
  --soft: #f3f7f9;
  --navy: #0f3d4c;
  --teal: #13737a;
  --green: #00b050;
  --green-dark: #2f8f59;
  --red: #d4232d;
  --amber: #f4b340;
  --white: #ffffff;
  --shadow: 0 16px 40px rgba(15, 61, 76, 0.12);
}

.agenda-panel .panel-header { flex-wrap: wrap; gap: 12px; }
body.agenda-view .top-actions { flex: 0 0 auto; }
.agenda-panel .panel-header span, #agendaDelivery { color: var(--muted); font-size: 14px; }
#agendaStatus, #agendaFormStatus { min-height: 20px; color: var(--teal); }
.agenda-toolbar, .agenda-toolbar > div, .agenda-form-actions, .agenda-event-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.agenda-toolbar { justify-content: space-between; margin: 18px 0; }
.agenda-toolbar h3 { margin: 0; text-transform: capitalize; }
.agenda-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 20px; }
.agenda-weekdays, .agenda-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.agenda-weekdays span { padding: 10px 0; text-align: center; color: var(--muted); font-size: 13px; }
.agenda-grid { border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.agenda-cell, .agenda-empty { min-width: 0; min-height: 106px; border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: white; padding: 7px; text-align: left; color: var(--ink); }
.agenda-cell { display: flex; flex-direction: column; gap: 4px; overflow: hidden; }
.agenda-cell:hover { background: var(--soft); }
.agenda-cell.is-selected { box-shadow: inset 0 0 0 2px var(--teal); background: #edf8f7; }
.agenda-cell strong { font-size: 13px; align-self: flex-start; padding: 4px; }
.agenda-cell.is-today strong { border-radius: 50%; color: white; background: var(--teal); }
.agenda-chip { width: 100%; display: block; font-size: 11px; padding: 4px; background: #d9eee8; border-left: 3px solid var(--green-dark); border-radius: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agenda-chip.is-completed { text-decoration: line-through; opacity: .6; }
.agenda-dot { display: none; color: var(--teal); }
.agenda-day { min-width: 0; border-left: 1px solid var(--line); padding-left: 16px; }
.agenda-day h3 { font-size: 16px; margin-top: 8px; }
.agenda-event { padding: 16px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.agenda-event small { display: block; color: var(--muted); margin: 10px 0; }
.agenda-notes { white-space: pre-wrap; font-size: 14px; }
.agenda-event-actions button { padding: 7px; font-size: 12px; }
.agenda-form-actions { justify-content: flex-end; margin-top: 16px; }
#agendaDialog { width: min(640px, calc(100% - 24px)); }
#agendaDialog label { display: flex; flex-direction: column; gap: 6px; }
#agendaDialog input, #agendaDialog select, #agendaDialog textarea { min-width: 0; width: 100%; }
@media (max-width: 1100px) { .agenda-layout { grid-template-columns: minmax(0, 1fr); } .agenda-day { border-left: 0; padding-left: 0; } }
@media (max-width: 600px) { .agenda-cell, .agenda-empty { min-height: 56px; padding: 3px; } .agenda-chip { display: none; } .agenda-dot { display: block; font-size: 10px; } .agenda-toolbar { gap: 12px; } .agenda-toolbar h3 { font-size: 16px; } .agenda-panel .panel-header > button { width: 100%; } }

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #edf3f6;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

body.locked {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  width: 100%;
  max-width: 100vw;
  min-height: 100vh;
  overflow-x: hidden;
}

.login-cover {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(15, 61, 76, 0.68), rgba(19, 115, 122, 0.42)),
    linear-gradient(rgba(15, 61, 76, 0.34), rgba(15, 61, 76, 0.62)),
    url("./assets/concrete-wall-bg.png") center / cover no-repeat,
    #0f3d4c;
}

.login-cover.hidden {
  display: none;
}

.login-panel {
  width: min(920px, 100%);
  background: var(--white);
  border: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.login-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.78fr);
}

.login-copy {
  display: grid;
  align-content: center;
  min-height: 520px;
  padding: 34px;
  background:
    linear-gradient(145deg, rgba(15, 61, 76, 0.94), rgba(19, 115, 122, 0.86)),
    var(--navy);
  color: var(--white);
}

.login-copy h2 {
  max-width: 390px;
  font-size: 36px;
  line-height: 1.05;
}

.login-copy > p {
  max-width: 420px;
  margin-top: 14px;
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.5;
}

.login-benefits {
  display: grid;
  gap: 8px;
  margin: 22px 0 0;
  padding: 0;
  list-style: none;
}

.login-benefits li {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255, 255, 255, 0.88);
  font-weight: 700;
}

.login-benefits li::before {
  content: "";
  width: 9px;
  height: 9px;
  background: var(--green);
}
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-mark.large {
  width: 58px;
  height: 58px;
  background: var(--navy);
  color: var(--white);
  border: 0;
  font-size: 20px;
}

.logo.large {
  display: block;
  width: 58px;
  height: 58px;
}

.login-brand h1 {
  font-size: 24px;
}

.login-brand p {
  color: inherit;
  opacity: 0.72;
  margin-top: 4px;
}

.login-form {
  display: grid;
  align-content: center;
  gap: 14px;
  padding: 34px;
}

.login-form > div {
  display: grid;
  gap: 4px;
  margin-bottom: 4px;
}

.login-form > div strong {
  font-size: 22px;
}

.login-form > div span {
  color: var(--muted);
  line-height: 1.35;
}

.login-error {
  min-height: 20px;
  color: var(--red);
  font-weight: 700;
}

.access-request {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--green-dark);
  font-weight: 800;
  text-decoration: none;
}

.sidebar {
  background: var(--navy);
  color: var(--white);
  padding: 20px 16px;
  min-width: 0;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.08);
  font-weight: 800;
}

.logo {
  display: block;
  width: 44px;
  height: 44px;
}

.brand strong,
.brand small {
  display: block;
  overflow-wrap: anywhere;
}

.brand small {
  color: rgba(255, 255, 255, 0.72);
  margin-top: 3px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.82);
  text-align: left;
  padding: 12px 14px;
}

.nav-tab.active,
.nav-tab:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--white);
}

button.srv-has-icon { display: inline-flex; align-items: center; justify-content: center; gap: 8px; vertical-align: middle; }
.srv-icon { width: 18px; height: 18px; flex: 0 0 18px; display: block; pointer-events: none; }
.srv-icon * { pointer-events: none; }
.nav-tab.srv-has-icon { justify-content: flex-start; width: 100%; gap: 12px; }
.nav-tab .srv-icon { width: 20px; height: 20px; flex-basis: 20px; opacity: .9; }
.nav-tab.active .srv-icon, .nav-tab:hover .srv-icon { opacity: 1; }
button.srv-has-icon.hidden, button.srv-has-icon[hidden] { display: none; }

#pwaInstallDialog { width: min(580px, calc(100% - 24px)); padding: 22px; }
#pwaInstallDialog p, #pwaInstallDialog li { line-height: 1.6; }
#pwaInstallDialog > p { margin: 16px 0; color: var(--muted); }
#pwaInstallDialog label { display: block; margin-bottom: 7px; font-weight: 700; }
#pwaInstallDialog select { width: 100%; }
.pwa-install-brand { display: flex; align-items: center; gap: 14px; margin: 16px 0; }
.pwa-install-brand img { width: 64px; height: 64px; border-radius: 14px; }
.pwa-install-brand strong { font-size: 20px; }
.pwa-install-brand p { color: var(--muted); margin-top: 4px; }
#pwaInstructions ol { padding-left: 23px; margin: 18px 0; }
#pwaInstructions li { margin-bottom: 9px; }
#pwaInstallStatus { color: var(--teal); font-size: 14px; }
.pwa-connection, .pwa-update { position: fixed; z-index: 2000; left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); margin: auto; max-width: 740px; border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; box-shadow: var(--shadow); line-height: 1.5; }
.pwa-connection { top: max(12px, env(safe-area-inset-top)); background: #fff4dc; color: #704f09; }
.pwa-update { bottom: max(12px, env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; background: white; }
.pwa-connection[hidden], .pwa-update[hidden] { display: none; }
.login-cover { overflow-y: auto; }
.login-panel { margin-block: auto; }
@media (max-width: 720px) { .top-actions { flex: 0 0 auto; } }
@media (display-mode: standalone) {
  body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .app-shell, .login-cover { min-height: 100dvh; }
  [data-pwa-install] { display: none !important; }
}

body.client-activity-view .top-actions { flex: 0 1 640px; }
.activity-panel .panel-header { flex-wrap: wrap; gap: 16px; }
.activity-panel .panel-header p { color: var(--muted); margin-top: 6px; line-height: 1.5; }
.activity-controls { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; align-items: end; margin: 22px 0 14px; }
.activity-controls label { display: flex; flex-direction: column; gap: 7px; min-width: 0; font-size: 14px; font-weight: 700; }
.activity-controls input, .activity-controls select { width: 100%; min-width: 0; }
.activity-explanation { font-size: 13px; line-height: 1.6; color: var(--muted); margin: 14px 0; }
#clientActivityError { color: var(--red); line-height: 1.5; }
.activity-kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin: 22px 0; }
.activity-kpis article { border: 1px solid var(--line); border-top: 3px solid var(--teal); padding: 16px; min-width: 0; background: white; }
.activity-kpis span { font-size: 13px; color: var(--muted); display: block; min-height: 32px; }
.activity-kpis strong { display: block; margin-top: 10px; font-size: 24px; overflow-wrap: anywhere; }
.activity-chart-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.activity-chart-head h3 { font-size: 18px; margin: 12px 0; }
.activity-chart-head > span { color: var(--muted); font-size: 13px; }
.activity-legend { display: flex; gap: 8px 16px; flex-wrap: wrap; font-size: 12px; margin: 8px 0 20px; }
.activity-legend span::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; margin-right: 6px; }
.activity-active { color: #2f8f59; }
.activity-attention { color: #966411; }
.activity-critical { color: #bb2733; }
.activity-unknown { color: #667b8a; }
.activity-chart { max-height: 660px; overflow: auto; padding-right: 8px; }
.activity-bar-row { display: grid; grid-template-columns: minmax(140px, 30%) minmax(80px, 1fr) minmax(95px, auto); align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.activity-bar-row > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-bar-row > strong { font-size: 13px; text-align: right; }
.activity-track { height: 20px; background: #edf1f3; overflow: hidden; border-radius: 3px; }
.activity-fill { height: 100%; border-radius: 3px; background: currentColor; }
.activity-fill.activity-ranking { color: var(--teal); }
.activity-fill.activity-attention { color: #bf861c; }
.activity-fill.activity-critical { color: #c93842; }
.activity-table { max-height: 620px; }
.activity-table table { min-width: 1460px; }
.activity-table th { position: sticky; top: 0; z-index: 1; }
.activity-table td { white-space: normal; height: auto; }
.activity-table td:nth-child(2) { min-width: 260px; max-width: 360px; }
.activity-table small { display: block; color: var(--muted); margin-top: 5px; }
.activity-badge { display: inline-block; padding: 6px 9px; border-radius: 4px; background: #f0f4f6; font-size: 12px; font-weight: 700; }
.activity-pagination, .activity-pagination > div { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 14px; }
.activity-pagination > span { color: var(--muted); font-size: 13px; }
#clientActivityHistory { width: min(1020px, calc(100% - 24px)); padding: 20px; }
#clientActivityHistory > p { color: var(--muted); line-height: 1.5; margin: 12px 0; }
#clientActivityHistory .table-wrap { max-height: 500px; }
#clientActivityHistory th { position: sticky; top: 0; }
@media (max-width: 1100px) { .activity-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); } .activity-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 720px) { body.client-activity-view .top-actions { flex: 0 0 auto; } }
@media (max-width: 640px) { .activity-controls { grid-template-columns: minmax(0, 1fr); } .activity-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .activity-kpis strong { font-size: 20px; } .activity-bar-row { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; } .activity-bar-row > span { grid-column: 1 / -1; } .activity-bar-row > strong { max-width: 120px; } .activity-panel .panel-header > button { width: 100%; } }

.workspace {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 16px;
}

.topbar p,
.panel-header span,
.thermometer-head span {
  color: var(--muted);
  margin-top: 4px;
}

.top-actions {
  display: flex;
  flex: 1 1 560px;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
  max-width: 100%;
}

.date-filter {
  align-items: center;
  background: var(--white);
  border: 1px solid var(--line);
  display: inline-flex;
  gap: 7px;
  min-height: 40px;
  padding: 0 10px;
}

.date-filter span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.date-filter input {
  border: 0;
  width: 145px;
  min-height: 38px;
  padding: 0;
}

.period-bar {
  align-items: center;
  background: var(--white);
  border: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px 14px;
  max-width: 100%;
}

.period-bar strong {
  color: var(--ink);
  flex: 0 0 auto;
  margin-right: 4px;
}

.period-bar .primary,
.period-bar .ghost {
  flex: 0 0 auto;
}

.period-bar .month-filter { display: flex; align-items: center; gap: 7px; font-size: 13px; }
#periodYear { width: 100px; }
#periodError { color: var(--red); width: 100%; font-size: 13px; }
#periodError:empty { display: none; }
@media (max-width: 720px) {
  .period-bar .month-filter { width: 100%; }
  #periodMonth, #periodYear { width: 100%; }
  .period-bar > button { width: 100%; }
}

select,
input,
textarea {
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  padding: 10px 11px;
  min-height: 40px;
}

textarea {
  resize: vertical;
}

.primary,
.ghost,
.icon-button {
  border: 1px solid transparent;
  min-height: 40px;
  padding: 10px 14px;
  font-weight: 700;
}

.primary {
  background: var(--green-dark);
  color: var(--white);
}

.ghost,
.icon-button {
  background: var(--white);
  border-color: var(--line);
  color: var(--ink);
}

.compact {
  padding-left: 10px;
  padding-right: 10px;
}

.icon-button {
  width: 40px;
  padding: 0;
  font-size: 24px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.kpi,
.panel,
.thermometer-panel {
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.kpi {
  min-height: 96px;
  display: grid;
  align-content: center;
  text-align: center;
  border-top: 8px solid var(--teal);
}

.kpi-action {
  border-right-color: var(--line);
  border-bottom-color: var(--line);
  border-left-color: var(--line);
  color: var(--ink);
}

.kpi-action:hover,
.kpi-action:focus-visible {
  transform: translateY(-1px);
  outline: 2px solid rgba(47, 143, 89, 0.24);
  outline-offset: 2px;
}

.kpi.warning {
  border-top-color: var(--amber);
}

.kpi.success {
  border-top-color: var(--green-dark);
}

.kpi.danger {
  border-top-color: var(--red);
}

.kpi span {
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
}

.kpi strong {
  font-size: 22px;
  margin-top: 7px;
}

.thermometer-panel {
  padding: 16px;
  margin-bottom: 14px;
}

.thermometer-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.thermometer-head strong {
  font-size: 24px;
}

.thermometer {
  position: relative;
  height: 28px;
  background: var(--red);
  overflow: hidden;
  border: 1px solid #b61c25;
}

.thermo-fill {
  height: 100%;
  width: 0%;
  background: var(--green);
  transition: width 180ms ease;
}

.thermo-over {
  position: absolute;
  inset: 0;
  display: none;
  background: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.22) 8px, transparent 8px, transparent 16px);
}

.thermometer.over .thermo-over {
  display: block;
}

.scale {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 0.8fr);
  gap: 14px;
}

.panel {
  padding: 14px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.hidden {
  display: none !important;
}

.table-wrap {
  overflow: auto;
  max-width: 100%;
}

/* Scroll the budget rows inside their own viewport, keeping column titles and
   the native horizontal scrollbar reachable without going to the last row. */
#recordsView .table-wrap {
  max-height: 65vh;
  max-height: 65dvh;
  min-height: 160px;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
#recordsView table { border-collapse: separate; border-spacing: 0; }
#recordsView thead th { position: sticky; top: 0; z-index: 2; }
#recordsView .table-wrap::-webkit-scrollbar { width: 14px; height: 0; }
#recordsView .table-wrap::-webkit-scrollbar-track { background: #f1f3f5; }
#recordsView .table-wrap::-webkit-scrollbar-thumb { background: #90979b; border: 3px solid #f1f3f5; border-radius: 8px; }
#recordsView .table-wrap::-webkit-scrollbar-corner { background: #f1f3f5; }
.records-scrollbar-footer { flex: 0 0 auto; padding: 7px 0 2px; background: var(--white); }
.records-scrollbar-footer[hidden] { display: none; }
.records-scrollbar-footer input { display: block; width: 100%; height: 18px; min-height: 18px; margin: 0; padding: 0; border: 0; background: transparent; appearance: none; -webkit-appearance: none; cursor: ew-resize; }
.records-scrollbar-footer input::-webkit-slider-runnable-track { height: 12px; border-radius: 6px; background: #eceeef; }
.records-scrollbar-footer input::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: var(--thumb-width, 80px); height: 12px; border-radius: 6px; background: #898f93; }
.records-scrollbar-footer input::-moz-range-track { height: 12px; border-radius: 6px; background: #eceeef; }
.records-scrollbar-footer input::-moz-range-thumb { width: var(--thumb-width, 80px); height: 12px; border: 0; border-radius: 6px; background: #898f93; }
.records-scrollbar-footer input:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
@media (min-width: 1101px) and (min-height: 600px) {
  body.records-table-view { overflow: hidden; }
  body.records-table-view .app-shell { height: 100vh; height: 100dvh; min-height: 0; }
  body.records-table-view .sidebar { height: 100%; overflow-y: auto; }
  body.records-table-view .workspace { display: flex; flex-direction: column; height: 100%; min-height: 0; }
  body.records-table-view .topbar, body.records-table-view .period-bar { flex: 0 0 auto; }
  body.records-table-view #recordsView.active { display: flex; flex: 1 1 0; min-height: 0; }
  body.records-table-view #recordsView > .panel { display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; min-height: 0; }
  body.records-table-view #recordsView .panel-header { flex: 0 0 auto; }
  body.records-table-view #recordsView .table-wrap { flex: 1 1 0; max-height: none; min-height: 0; }
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1420px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 9px;
  text-align: right;
  white-space: nowrap;
}

th {
  background: var(--navy);
  color: var(--white);
  font-size: 12px;
  text-transform: uppercase;
}

td:first-child,
th:first-child,
td:nth-child(2),
th:nth-child(2) {
  text-align: left;
}

.status-pill {
  display: inline-flex;
  min-width: 78px;
  justify-content: center;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 800;
}

.status-pill.open {
  color: var(--red);
  background: #fde3e5;
}

.status-pill.closed {
  color: var(--green-dark);
  background: #daf4e3;
}

.status-pill.lost {
  color: #9a5b00;
  background: #fff1cc;
}

.danger-text {
  color: var(--red);
  font-weight: 700;
}

.success-text {
  color: var(--green-dark);
  font-weight: 700;
}

.status-chart {
  display: grid;
  place-items: center;
  gap: 18px;
  min-height: 260px;
}

.donut {
  width: 170px;
  height: 170px;
  border-radius: 50%;
  background: conic-gradient(var(--green-dark) 0deg, var(--green-dark) 0deg, var(--red) 0deg);
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 42px;
  background: var(--white);
  border-radius: 50%;
}

.legend {
  display: flex;
  gap: 16px;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
}

.dot.open {
  background: var(--red);
}

.dot.closed {
  background: var(--green-dark);
}

.dot.lost {
  background: var(--amber);
}

.industry-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
}

.industry-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 180px auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

.industry-form label {
  display: grid;
  gap: 6px;
}

.plan-guidance { color: #607982; font-size: 14px; line-height: 1.5; margin: 12px 0; }
.plan-usage { display: block; margin-top: 6px; color: #607982; font-size: 12px; }
.company-plan-picker { display: inline-grid; gap: 5px; font-size: 12px; text-align: left; }
.company-plan-picker select { min-width: 180px; max-width: 240px; }

.user-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  align-items: end;
}

.user-form label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.user-form input, .user-form select { width: 100%; min-width: 0; }
.form-message.error { color: var(--red); }

.form-message {
  min-height: 22px;
  margin-top: 10px;
  color: var(--green-dark);
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 82px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  color: #166534;
  background: #dcfce7;
}

.badge.neutral {
  color: var(--ink);
  background: #eaf2f5;
}

.badge.blocked {
  color: #991b1b;
  background: #fee2e2;
}

.actions-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.empty-row {
  padding: 18px !important;
  color: var(--muted);
  text-align: center !important;
}

.industry-card {
  border: 1px solid var(--line);
  background: var(--soft);
  padding: 12px;
  min-width: 0;
  overflow-wrap: anywhere;
}

#industryForm { margin-bottom: 16px; }
#industryForm button { margin: 0 10px 8px 0; }
.office-preview-head > div { flex-wrap: wrap; }
.industry-card-head { flex-wrap: wrap; }
.industry-card-head h2 { margin: 0; }
.industry-card p { margin: 8px 0; line-height: 1.4; }

.industry-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.industry-card label {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.empty-state {
  grid-column: 1 / -1;
  border: 1px dashed var(--line);
  background: var(--soft);
  color: var(--muted);
  padding: 18px;
}

dialog {
  width: min(720px, calc(100% - 24px));
  border: 0;
  padding: 0;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
}

dialog::backdrop {
  background: rgba(15, 33, 43, 0.38);
}

.office-view { min-width: 0; }
.office-view .panel-header { flex-wrap: wrap; }
.office-view .panel-header span { display: block; max-width: 750px; color: var(--muted); line-height: 1.5; }
.office-view h2 { margin: 4px 0 8px; }
.office-table { min-width: 700px; table-layout: auto; }
.office-table th, .office-table td { text-align: left; white-space: normal; padding: 13px 10px; height: auto; }
.office-table td { overflow-wrap: anywhere; }
.office-request-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.request-budget-notice { padding: 12px; margin: 12px 0; line-height: 1.5; background: #edf7f0; color: #1d603c; border: 1px solid #c4decf; }
.request-budget-notice[hidden] { display: none; }
#portfolioLinksDialog { width: min(900px, calc(100% - 24px)); padding: 20px; }
#portfolioLinksDialog p { line-height: 1.5; margin: 12px 0; }
#portfolioLinksDialog .table-wrap { max-height: 420px; }
#portfolioLinksDialog th { position: sticky; top: 0; }
#officeRequestsView .office-table th:last-child, #officeRequestsView .office-table td:last-child { width: 240px; }
.office-table th:last-child, .office-table td:last-child { width: 140px; }
.office-view .form-grid { max-width: 1000px; }
.office-status, .office-form-status { font-size: 14px; line-height: 1.5; }
.office-form-status { color: var(--teal); }
.monthly-goal-note { color: var(--muted); margin: 12px 0; font-size: 13px; line-height: 1.5; }
#monthlyGoalSupplier, #monthlyGoalReference { margin: 12px 0; line-height: 1.5; }
#monthlyGoalReference:empty { display: none; }
.comparison-controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; margin: 18px 0; }
.comparison-controls fieldset { display: flex; flex-wrap: wrap; gap: 10px; border: 1px solid var(--line); padding: 10px; margin: 0; }
.comparison-controls fieldset { min-width: 0; }
.comparison-controls fieldset label { flex: 1 1 150px; min-width: 0; }
.comparison-controls fieldset input { width: 100%; min-width: 0; }
#comparisonView .panel-header { flex-wrap: wrap; }
.comparison-controls legend { font-weight: bold; font-size: 13px; }
.comparison-controls label[hidden] { display: none; }
.comparison-controls fieldset[hidden] { display: none; }
.comparison-reading { padding: 12px 16px; border-left: 4px solid var(--teal); background: #f3f8f8; line-height: 1.6; }
.comparison-highlights { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 16px 0; }
.comparison-highlights article { border: 1px solid var(--line); padding: 16px; min-width: 0; }
.comparison-highlights span, .comparison-highlights small { display: block; color: var(--muted); font-size: 12px; line-height: 1.5; }
.comparison-highlights strong { display: block; font-size: 20px; margin: 8px 0; }
.comparison-month-table { max-height: 520px; overflow: auto; }
.comparison-month-table table { min-width: 1100px; border-collapse: separate; border-spacing: 0; }
.comparison-month-table th { position: sticky; top: 0; z-index: 1; }
.comparison-controls select { max-width: 300px; }
.comparison-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 18px 0; }
.comparison-kpis article { border: 1px solid var(--line); border-top: 4px solid var(--teal); padding: 16px; background: white; min-width: 0; }
.comparison-kpis span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.comparison-kpis strong { font-size: 22px; overflow-wrap: anywhere; }
.comparison-ranges { line-height: 1.6; }
.comparison-legend { display: flex; gap: 20px; flex-wrap: wrap; font-size: 13px; margin: 16px 0; }
.comparison-legend i { display: inline-block; width: 16px; height: 12px; margin-right: 6px; }
.comparison-legend .base { background: #8b9caa; }.comparison-legend .current { background: #13737a; }
.comparison-chart { overflow: auto; margin: 14px 0 24px; max-height: 540px; }
.comparison-chart svg { width: 100%; min-width: 680px; display: block; }
#comparisonView h3 { font-size: 16px; margin: 16px 0 8px; }
#comparisonError { color: var(--red); }
#productImportDialog { width: min(1120px, calc(100% - 24px)); }
#changePasswordDialog { width: min(520px, calc(100% - 24px)); }
#changePasswordDialog label { display: flex; flex-direction: column; gap: 7px; margin-top: 15px; }
#changePasswordDialog p { line-height: 1.5; }
#passwordHelp { font-size: 13px; color: var(--muted); margin: 6px 0; }
#changePasswordStatus { color: var(--green); margin-top: 16px; }
#changePasswordStatus.password-error { color: var(--red); }
#productImportDialog label[hidden] { display: none; }
.import-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 16px 0; }
.import-toolbar label { display: flex; align-items: center; gap: 8px; }
#productImportDialog .import-toolbar label { flex-direction: row; }
#productImportHeader { width: 18px; height: 18px; min-height: 0; padding: 0; flex: 0 0 18px; }
.import-preview { max-height: 340px; }
.import-preview table { min-width: 750px; border-collapse: separate; border-spacing: 0; }
.import-preview th { position: sticky; top: 0; z-index: 1; }
.import-preview td { max-width: 420px; }
#productImportStatus { margin: 14px 0; line-height: 1.5; }
@media (max-width: 720px) {
  body.comparison-view .top-actions { flex: 0 0 auto; }
  #comparisonView .panel-header > button { width: 100%; }
  .comparison-kpis { grid-template-columns: 1fr 1fr; }
  .comparison-highlights { grid-template-columns: 1fr; }
  .comparison-kpis strong { font-size: 18px; }
  .comparison-controls > label, .comparison-controls > fieldset, .comparison-controls > button { width: 100%; }
  .comparison-controls select { width: 100%; max-width: 100%; }
  .comparison-controls fieldset label { flex-basis: 100%; }
}
.office-lookup { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.office-logo-row { display: flex; align-items: center; flex-wrap: wrap; gap: 15px; margin: 15px 0; }
#officeLogoPreview { max-width: 240px; max-height: 100px; object-fit: contain; }
.office-dialog { max-height: 92vh; overflow: auto; border-radius: 10px; }
.office-dialog form { padding: 20px; }
#officeRequestDialog { width: min(1040px, calc(100% - 24px)); }
.office-request-line { display: grid; grid-template-columns: 2fr 1fr 1fr 1.2fr auto; gap: 10px; align-items: end; padding: 14px; background: var(--soft); border: 1px solid var(--line); margin: 12px 0; }
.office-request-line input, .office-request-line select { width: 100%; min-width: 0; }
.office-request-line label { min-width: 0; font-size: 13px; }
#officePreviewDialog { width: min(1050px, calc(100% - 24px)); }
.office-preview-head { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; padding: 14px; }
.office-preview-head > div { display: flex; gap: 10px; }
#officePreviewFrame { width: 100%; height: 74vh; border: 0; background: white; display: block; }
@media (max-width: 720px) {
  .office-request-line { grid-template-columns: 1fr 1fr; }
  .office-line-product { grid-column: 1 / -1; }
  .office-request-line > button { grid-column: 1 / -1; }
  .office-view .panel-header > button { width: 100%; }
  .office-dialog form { padding: 16px; }
}

#recordForm, #clientForm {
  padding: 18px;
}

.client-registry { margin-bottom: 18px; }
.client-tools, .cnpj-lookup { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.client-tools label, .cnpj-lookup label { flex: 1; min-width: 200px; }
.registry-table { min-width: 950px; }
.registry-table td:first-child, .registry-table th:first-child { text-align: left; }
.registry-actions { white-space: normal; min-width: 230px; }
#clientLookupStatus, #clientSyncStatus { color: var(--muted); font-size: 13px; }
#clientFormMessage { color: var(--red); }
#clientForm .muted-text { font-size: 12px; line-height: 1.6; }
#clientDialog { max-height: 90vh; overflow: auto; border-radius: 12px; }
@media (max-width: 640px) {
  .client-registry .panel-header { align-items: stretch; flex-direction: column; }
  #clientForm .form-grid { grid-template-columns: 1fr; }
  #clientForm .span-2 { grid-column: auto; }
  .cnpj-lookup button { width: 100%; }
}

.dialog-head,
.dialog-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.dialog-actions {
  margin-top: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

label:not(.date-filter) {
  display: grid;
  gap: 6px;
  font-weight: 700;
  color: var(--ink);
}

.span-2 {
  grid-column: span 2;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 14px;
  }

  .brand {
    margin: 0;
  }

  .nav-tabs {
    display: flex;
    overflow-x: auto;
  }

  .nav-tab {
    white-space: nowrap;
  }

  .nav-tab.srv-has-icon { width: auto; flex: 0 0 auto; }

  .kpi-grid {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 14px;
  }

  .topbar,
  .thermometer-head,
  .period-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .panel-actions,
  .top-actions select,
  .date-filter,
  .date-filter input,
  .top-actions button {
    width: 100%;
  }

  .kpi-grid,
  .industry-grid,
  .industry-form,
  .user-form,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  h1 {
    font-size: 22px;
  }

  .login-panel {
    width: min(520px, 100%);
  }

  .login-layout {
    grid-template-columns: 1fr;
  }

  .login-copy {
    min-height: auto;
    padding: 24px;
  }

  .login-copy h2 {
    font-size: 28px;
  }

  .login-form {
    padding: 24px;
  }

  .login-brand {
    align-items: flex-start;
    flex-direction: column;
  }

  .sidebar {
    align-items: stretch;
    flex-direction: column;
  }
}

/* Conversão: base de todos os status, mantendo período/carteira/cliente. */
.conversion-panel { margin-bottom: 14px; }
.conversion-panel .panel-header { margin-bottom: 16px; }
.conversion-panel .panel-header span { display: block; line-height: 1.5; font-size: 13px; }
.conversion-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.conversion-card { min-width: 0; display: flex; flex-direction: column; gap: 10px; text-align: left; padding: 18px; background: var(--soft); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; }
.conversion-card:hover { border-color: var(--teal); }
.conversion-card:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.conversion-card > span:first-child { font-size: 14px; font-weight: 700; min-height: 32px; }
.conversion-card strong { font-size: 30px; }
.conversion-card small { color: var(--muted); line-height: 1.4; }
.conversion-closed strong { color: var(--green-dark); }
.conversion-open strong { color: #996515; }
.conversion-lost strong { color: var(--red); }
.conversion-track { display: block; width: 100%; height: 5px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: auto; }
.conversion-track > span { display: block; height: 100%; width: 0; }
.conversion-open .conversion-track > span { background: var(--amber); }
.conversion-closed .conversion-track > span { background: var(--green-dark); }
.conversion-lost .conversion-track > span { background: var(--red); }
@media (max-width: 1100px) { .conversion-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .conversion-grid { grid-template-columns: minmax(0, 1fr); } .conversion-card > span:first-child { min-height: 0; } }
