:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef4f4;
  --ink: #182123;
  --muted: #657174;
  --line: #d9e1e2;
  --accent: #146c72;
  --accent-strong: #0d4e52;
  --warning: #a76000;
  --warning-bg: #fff3dc;
  --danger: #b42318;
  --danger-bg: #fde7e4;
  --ok: #1f7a4d;
  --ok-bg: #e5f6ee;
  --income: #166534;
  --shadow: 0 18px 45px rgba(22, 44, 48, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Visual refresh */
.app-shell {
  grid-template-columns: 270px minmax(0, 1fr);
  background:
    linear-gradient(180deg, rgba(20, 108, 114, 0.08), rgba(20, 108, 114, 0)),
    var(--bg);
}

.sidebar {
  position: sticky;
  top: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0)),
    #10282c;
}

.brand {
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}

.nav-tab::before {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #f2c94c;
  content: "*";
}

.nav-tab[data-view="dashboard"]::before { content: "P"; }
.nav-tab[data-view="companies"]::before { content: "E"; }
.nav-tab[data-view="patients"]::before { content: "P"; }
.nav-tab[data-view="records"]::before { content: "R"; }
.nav-tab[data-view="calls"]::before { content: "C"; }
.nav-tab[data-view="fleet"]::before { content: "F"; }
.nav-tab[data-view="schedule"]::before { content: "E"; }
.nav-tab[data-view="checklists"]::before { content: "K"; }
.nav-tab[data-view="stock"]::before { content: "S"; }
.nav-tab[data-view="loans"]::before { content: "L"; }
.nav-tab[data-view="finance"]::before { content: "$"; }
.nav-tab[data-view="admin"]::before { content: "A"; }

.nav-tab.active::before,
.nav-tab:hover::before {
  background: rgba(23, 48, 51, 0.12);
  color: #173033;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  margin: -28px -28px 26px;
  padding: 22px 28px;
  background: rgba(245, 247, 248, 0.92);
  border-bottom: 1px solid rgba(217, 225, 226, 0.9);
  backdrop-filter: blur(10px);
}

.metric {
  position: relative;
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.metric:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 70px rgba(10, 33, 38, 0.13);
}

.metric::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 14px;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.form-grid {
  border-top: 4px solid var(--accent);
}

.badge.warning {
  color: var(--warning);
  background: var(--warning-bg);
}

.kanban-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  gap: 16px;
  align-items: start;
}

.kanban-column {
  min-height: 320px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.kanban-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
}

.kanban-header span {
  min-width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #173033;
  color: #fff;
  font-weight: 900;
}

.kanban-list {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.call-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #fff;
}

.call-card-head,
.call-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.call-patient {
  font-weight: 900;
  font-size: 1rem;
}

.call-meta,
.call-route {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.call-route {
  color: var(--ink);
  font-weight: 700;
}

.kanban-empty {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

@media (max-width: 980px) {
  .kanban-board {
    grid-template-columns: 1fr;
  }
}

/* Mobile final override - must remain last */
@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .app-shell {
    display: block;
    width: 100%;
    min-width: 0;
    grid-template-columns: 1fr;
    background: var(--bg);
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 30;
    width: 100%;
    min-height: auto;
    padding: 12px;
    gap: 10px;
  }

  .brand {
    padding-bottom: 10px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .nav-tabs {
    display: flex;
    grid-template-columns: none;
    gap: 8px;
    width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding: 0 2px 6px;
    scrollbar-width: thin;
  }

  .nav-tab {
    flex: 0 0 auto;
    width: auto;
    min-width: 116px;
    min-height: 40px;
    justify-content: center;
    padding: 8px 10px;
    font-size: 0.86rem;
    white-space: nowrap;
  }

  .nav-tab::before {
    width: 22px;
    height: 22px;
    font-size: 0.72rem;
  }

  .content {
    width: 100%;
    min-width: 0;
    padding: 12px;
  }

  .topbar {
    position: static;
    display: grid;
    margin: 0 0 14px;
    padding: 0;
    gap: 12px;
    background: transparent;
    border: 0;
    backdrop-filter: none;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    width: 100%;
  }

  .topbar-actions > *,
  .tenant-switcher,
  .user-chip,
  .primary-action,
  .secondary-action,
  .link-action {
    width: 100%;
  }

  h1 {
    font-size: 1.28rem;
    line-height: 1.25;
  }

  h2 {
    font-size: 1.18rem;
  }

  .section-heading {
    display: grid;
    gap: 10px;
  }

  .metrics-grid,
  .dashboard-grid,
  .form-grid,
  .record-form,
  .finance-form,
  .permissions,
  .filters,
  .kanban-board {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .metric,
  .panel,
  .form-grid,
  .filters,
  .table-wrap,
  .kanban-column {
    box-shadow: 0 10px 26px rgba(22, 44, 48, 0.07);
  }

  .metric {
    padding: 13px;
  }

  .metric::after {
    display: none;
  }

  .metric span {
    min-height: 0;
    font-size: 0.84rem;
  }

  .metric strong {
    font-size: 1.45rem;
  }

  .form-grid,
  .filters {
    padding: 12px;
  }

  label {
    font-size: 0.84rem;
  }

  input,
  select,
  textarea {
    min-height: 44px;
    font-size: 16px;
    padding: 9px 10px;
  }

  .login-screen {
    grid-template-columns: 1fr;
    padding: 12px;
    place-content: start center;
  }

  .login-card {
    padding: 16px;
  }

  .login-actions,
  .password-row {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 680px;
  }

  th,
  td {
    padding: 9px;
    font-size: 0.84rem;
  }

  .table-action {
    min-height: 34px;
    margin: 2px 0;
    padding: 0 10px;
  }

  .kanban-column {
    min-height: auto;
  }

  .kanban-header {
    padding: 12px;
  }

  .kanban-list {
    padding: 12px;
  }

  .call-card {
    padding: 12px;
  }

  .call-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .call-actions .table-action {
    width: 100%;
  }
}

/* Mobile final override: keep this at the end so desktop polish cannot override it */
@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .app-shell {
    display: block;
    width: 100%;
    min-width: 0;
    background: var(--bg);
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 30;
    width: 100%;
    min-height: auto;
    padding: 12px;
    gap: 10px;
  }

  .brand {
    padding-bottom: 10px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .nav-tabs {
    display: flex;
    grid-template-columns: none;
    gap: 8px;
    width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding: 0 2px 6px;
    scrollbar-width: thin;
  }

  .nav-tab {
    flex: 0 0 auto;
    width: auto;
    min-width: 116px;
    min-height: 40px;
    justify-content: center;
    padding: 8px 10px;
    font-size: 0.86rem;
    white-space: nowrap;
  }

  .nav-tab::before {
    width: 22px;
    height: 22px;
    font-size: 0.72rem;
  }

  .content {
    width: 100%;
    min-width: 0;
    padding: 12px;
  }

  .topbar {
    position: static;
    display: grid;
    margin: 0 0 14px;
    padding: 0;
    gap: 12px;
    background: transparent;
    border: 0;
    backdrop-filter: none;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    width: 100%;
  }

  .topbar-actions > *,
  .tenant-switcher,
  .user-chip,
  .primary-action,
  .secondary-action,
  .link-action {
    width: 100%;
  }

  h1 {
    font-size: 1.28rem;
    line-height: 1.25;
  }

  h2 {
    font-size: 1.18rem;
  }

  .section-heading {
    display: grid;
    gap: 10px;
  }

  .metrics-grid,
  .dashboard-grid,
  .form-grid,
  .record-form,
  .finance-form,
  .permissions,
  .filters,
  .kanban-board {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .metric,
  .panel,
  .form-grid,
  .filters,
  .table-wrap,
  .kanban-column {
    box-shadow: 0 10px 26px rgba(22, 44, 48, 0.07);
  }

  .metric {
    padding: 13px;
  }

  .metric::after {
    display: none;
  }

  .metric span {
    min-height: 0;
    font-size: 0.84rem;
  }

  .metric strong {
    font-size: 1.45rem;
  }

  .form-grid,
  .filters {
    padding: 12px;
  }

  label {
    font-size: 0.84rem;
  }

  input,
  select,
  textarea {
    min-height: 44px;
    font-size: 16px;
    padding: 9px 10px;
  }

  .login-screen {
    grid-template-columns: 1fr;
    padding: 12px;
    place-content: start center;
  }

  .login-card {
    padding: 16px;
  }

  .login-actions,
  .password-row {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 680px;
  }

  th,
  td {
    padding: 9px;
    font-size: 0.84rem;
  }

  .table-action {
    min-height: 34px;
    margin: 2px 0;
    padding: 0 10px;
  }

  .kanban-column {
    min-height: auto;
  }

  .kanban-header {
    padding: 12px;
  }

  .kanban-list {
    padding: 12px;
  }

  .call-card {
    padding: 12px;
  }

  .call-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .call-actions .table-action {
    width: 100%;
  }
}

/* Mobile usability pass */
@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    position: sticky;
    top: 0;
    z-index: 20;
    gap: 14px;
  }

  .brand {
    padding-bottom: 12px;
  }

  .nav-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-tab {
    flex: 0 0 auto;
    width: auto;
    min-width: 128px;
    justify-content: center;
  }

  .topbar {
    position: static;
    margin: 0 0 20px;
    padding: 0;
    background: transparent;
    border-bottom: 0;
    backdrop-filter: none;
  }
}

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

  .login-screen {
    padding: 14px;
  }

  .login-card {
    padding: 18px;
  }

  .topbar-actions,
  .section-heading {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .topbar-actions > *,
  .primary-action,
  .secondary-action {
    width: 100%;
  }

  .metrics-grid,
  .dashboard-grid,
  .form-grid,
  .record-form,
  .finance-form,
  .permissions,
  .filters,
  .kanban-board {
    grid-template-columns: 1fr;
  }

  .metric {
    padding: 14px;
  }

  .metric span {
    min-height: auto;
  }

  .metric strong {
    font-size: 1.55rem;
  }

  .form-grid,
  .filters {
    padding: 14px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  .table-wrap {
    border-radius: 8px;
  }

  table {
    min-width: 720px;
  }

  th,
  td {
    padding: 10px;
  }

  .table-action {
    margin: 2px 0;
  }

  .call-card-head,
  .call-actions {
    align-items: stretch;
  }

  .call-actions .table-action {
    flex: 1 1 100%;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 440px);
  align-items: stretch;
  gap: 28px;
  padding: 32px;
  background:
    radial-gradient(circle at 20% 12%, rgba(46, 196, 182, 0.22), transparent 32%),
    linear-gradient(135deg, rgba(13, 28, 31, 0.94), rgba(20, 108, 114, 0.9)),
    #173033;
}

.login-screen.hidden,
.app-shell.hidden {
  display: none !important;
}

.hidden {
  display: none !important;
}

.login-card {
  width: 100%;
  display: grid;
  gap: 14px;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 8px;
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(8px);
}

.landing-content {
  display: grid;
  align-content: center;
  gap: 28px;
  color: #ffffff;
  max-width: 1040px;
}

.landing-auth {
  display: grid;
  align-content: center;
  gap: 16px;
}

.ambugestao-logo {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  color: #ffffff;
}

.ambugestao-logo svg {
  width: 68px;
  height: 68px;
  flex: 0 0 auto;
}

.ambugestao-logo rect,
.ambugestao-logo path {
  fill: none;
  stroke: #f7d65b;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ambugestao-logo circle {
  fill: #f7d65b;
}

.ambugestao-logo strong {
  display: block;
  font-size: clamp(2rem, 4vw, 3.9rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.ambugestao-logo span {
  display: block;
  margin-top: 6px;
  color: rgba(255, 255, 255, 0.84);
  font-weight: 800;
  font-size: clamp(0.95rem, 1.6vw, 1.28rem);
}

.landing-hero {
  display: grid;
  gap: 16px;
  max-width: 920px;
}

.landing-hero .eyebrow {
  color: #f7d65b;
  font-weight: 900;
}

.landing-hero h1 {
  margin: 0;
  font-size: clamp(2.4rem, 5vw, 5.6rem);
  line-height: 0.96;
  max-width: 980px;
}

.landing-hero p {
  margin: 0;
  max-width: 760px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 1.05rem;
  line-height: 1.55;
}

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

.landing-actions .primary-action,
.landing-actions .secondary-action {
  width: auto;
  min-width: 180px;
}

.landing-feature-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.landing-feature-grid article {
  min-height: 132px;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
}

.landing-feature-grid strong {
  color: #ffffff;
  font-size: 0.98rem;
}

.landing-feature-grid span {
  color: rgba(255, 255, 255, 0.74);
  font-size: 0.88rem;
  line-height: 1.4;
}

.brand-inline {
  display: grid;
  min-height: 58px;
  min-width: 0;
  width: 100%;
}

.login-brand {
  color: var(--ink);
  margin-bottom: 8px;
}

.login-logo {
  width: 100%;
  max-width: 240px;
  max-height: 170px;
  object-fit: contain;
  justify-self: center;
  display: block;
  border-radius: 8px;
}

.login-logo-fallback {
  display: none;
  justify-self: center;
  min-height: 74px;
  min-width: 220px;
  place-items: center;
  border-radius: 8px;
  background: #173033;
  color: #ffffff;
  font-weight: 900;
  font-size: 1.5rem;
  letter-spacing: 0;
}

.login-title {
  display: grid;
  gap: 4px;
  text-align: center;
  line-height: 1.35;
}

.login-title strong {
  display: block;
  font-size: 1.2rem;
}

.login-title span {
  display: block;
  color: var(--muted);
  font-size: 0.92rem;
}

.login-status {
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.35;
}

.login-status.online {
  color: var(--ok);
  background: var(--ok-bg);
}

.login-status.warning {
  color: var(--warning);
  background: var(--warning-bg);
}

.password-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
}

.password-row label {
  min-width: 0;
}

.icon-action {
  min-height: 45px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent-strong);
  font-weight: 800;
  cursor: pointer;
}

.login-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

@media (max-width: 1180px) {
  .login-screen {
    grid-template-columns: 1fr;
  }

  .landing-content,
  .landing-auth {
    align-content: start;
  }

  .landing-feature-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .landing-auth {
    max-width: 560px;
    width: 100%;
  }
}

@media (max-width: 720px) {
  .ambugestao-logo {
    align-items: flex-start;
  }

  .ambugestao-logo svg {
    width: 54px;
    height: 54px;
  }

  .landing-hero h1 {
    font-size: 2.35rem;
  }

  .landing-feature-grid {
    grid-template-columns: 1fr;
  }

  .landing-feature-grid article {
    min-height: 0;
  }

  .landing-actions {
    display: grid;
  }
}

.master-card.hidden,
.signup-card.hidden {
  display: none !important;
}

.login-hint {
  color: var(--danger);
  font-size: 0.9rem;
  min-height: 1.2rem;
  font-weight: 700;
}

.support-link {
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: none;
  font-size: 0.9rem;
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  background: #173033;
  color: #f8fbfb;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: #f2c94c;
  color: #173033;
  border-radius: 8px;
  font-weight: 800;
}

.brand-logo {
  width: 58px;
  height: 58px;
  max-width: 58px;
  max-height: 58px;
  object-fit: contain;
  object-position: center;
  border-radius: 10px;
  background: #ffffff;
  padding: 5px;
  border: 1px solid rgba(217, 225, 226, 0.9);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #bdd1d3;
  font-size: 0.88rem;
  margin-top: 2px;
}

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

.nav-tab {
  width: 100%;
  border: 0;
  border-radius: 8px;
  text-align: left;
  padding: 12px 14px;
  color: #dce9ea;
  background: transparent;
  cursor: pointer;
}

.nav-tab:hover,
.nav-tab.active {
  color: #173033;
  background: #f2c94c;
}

.content {
  padding: 28px;
  min-width: 0;
}

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

.topbar-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.tenant-switcher {
  min-width: 190px;
}

.user-chip {
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--muted);
  background: #fff;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.76rem;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 780px;
  font-size: 2rem;
  line-height: 1.16;
  margin-bottom: 0;
}

h2 {
  font-size: 1.45rem;
  margin-bottom: 5px;
}

h3 {
  font-size: 1rem;
  margin-bottom: 0;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.section-heading p {
  color: var(--muted);
  margin-bottom: 0;
}

.primary-action {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.primary-action:hover {
  background: var(--accent-strong);
}

.secondary-action,
.table-action {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--accent-strong);
  min-height: 36px;
  padding: 0 12px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.link-action {
  display: grid;
  place-items: center;
  text-decoration: none;
}

.secondary-action:hover,
.table-action:hover {
  border-color: var(--accent);
  background: var(--surface-soft);
}

.table-action {
  min-height: 30px;
  font-size: 0.82rem;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.master-metrics {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin: 0 0 16px;
}

.master-metrics .metric {
  padding: 14px;
}

.master-metrics .metric span {
  min-height: 32px;
  font-size: 0.82rem;
}

.master-metrics .metric strong {
  font-size: 1.65rem;
}

.metric,
.panel,
.form-grid,
.filters,
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  min-height: 38px;
}

.metric strong {
  font-size: 2rem;
  line-height: 1;
}

.metric.warning strong {
  color: var(--warning);
}

.metric.danger strong {
  color: var(--danger);
}

.metric.positive strong {
  color: var(--income);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
}

.finance-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.panel {
  overflow: hidden;
}

.panel-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.list {
  display: grid;
  gap: 0;
}

.list-row {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.list-row:last-child {
  border-bottom: 0;
}

.list-row span {
  color: var(--muted);
  font-size: 0.9rem;
}

.form-grid,
.filters {
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
  margin-bottom: 18px;
}

.record-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.finance-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  padding: 10px 11px;
  min-height: 42px;
}

textarea {
  resize: vertical;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin: 0;
}

legend {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  padding: 0 6px;
}

.permissions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.permissions label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.permissions input {
  width: 18px;
  min-height: 18px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(20, 108, 114, 0.18);
  border-color: var(--accent);
}

.wide {
  grid-column: 1 / -1;
}

.filters {
  grid-template-columns: minmax(220px, 320px) minmax(260px, 1fr);
}

.table-wrap {
  overflow-x: auto;
}

.table-wrap.embedded {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  margin-bottom: 0;
}

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

th,
td {
  padding: 13px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

td span {
  color: var(--muted);
  font-size: 0.86rem;
}

th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

tr:last-child td {
  border-bottom: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.badge.ok {
  color: var(--ok);
  background: var(--ok-bg);
}

.badge.expiring {
  color: var(--warning);
  background: var(--warning-bg);
}

.badge.expired {
  color: var(--danger);
  background: var(--danger-bg);
}

.badge.income {
  color: var(--income);
  background: var(--ok-bg);
}

.badge.expense {
  color: var(--danger);
  background: var(--danger-bg);
}

.empty {
  padding: 18px;
  color: var(--muted);
}

.import-export-panel {
  margin-top: 18px;
}

.import-status {
  padding: 0 18px 18px;
  color: var(--muted);
  font-size: 0.9rem;
}

.logo-preview-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.logo-preview-row img {
  display: none;
  max-width: 180px;
  max-height: 110px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 16px;
  }

  .nav-tabs {
    grid-template-columns: repeat(4, 1fr);
  }

  .nav-tab {
    text-align: center;
    padding-inline: 8px;
  }

  .dashboard-grid,
  .form-grid,
  .record-form,
  .finance-form,
  .permissions,
  .filters {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .content {
    padding: 18px;
  }

  .topbar,
  .section-heading {
    display: grid;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .tenant-switcher,
  .user-chip {
    width: 100%;
  }

  h1 {
    font-size: 1.45rem;
  }

  .nav-tabs {
    grid-template-columns: 1fr 1fr;
  }

  .metrics-grid,
  .dashboard-grid,
  .form-grid,
  .record-form,
  .finance-form,
  .permissions,
  .filters {
    grid-template-columns: 1fr;
  }

  .primary-action {
    width: 100%;
  }
}

/* Final visual polish overrides */
.app-shell {
  grid-template-columns: 270px minmax(0, 1fr);
  background:
    linear-gradient(180deg, rgba(20, 108, 114, 0.08), rgba(20, 108, 114, 0)),
    var(--bg);
}

.sidebar {
  position: sticky;
  top: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0)),
    #10282c;
}

.brand {
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}

.nav-tab::before {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #f2c94c;
  content: "*";
}

.nav-tab[data-view="dashboard"]::before { content: "P"; }
.nav-tab[data-view="companies"]::before { content: "E"; }
.nav-tab[data-view="patients"]::before { content: "P"; }
.nav-tab[data-view="records"]::before { content: "R"; }
.nav-tab[data-view="calls"]::before { content: "C"; }
.nav-tab[data-view="fleet"]::before { content: "F"; }
.nav-tab[data-view="schedule"]::before { content: "E"; }
.nav-tab[data-view="checklists"]::before { content: "K"; }
.nav-tab[data-view="stock"]::before { content: "S"; }
.nav-tab[data-view="finance"]::before { content: "$"; }
.nav-tab[data-view="billing"]::before { content: "B"; }
.nav-tab[data-view="budgets"]::before { content: "O"; }
.nav-tab[data-view="admin"]::before { content: "A"; }

.nav-tab.active::before,
.nav-tab:hover::before {
  background: rgba(23, 48, 51, 0.12);
  color: #173033;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  margin: -28px -28px 26px;
  padding: 22px 28px;
  background: rgba(245, 247, 248, 0.92);
  border-bottom: 1px solid rgba(217, 225, 226, 0.9);
  backdrop-filter: blur(10px);
}

.metric {
  position: relative;
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.metric:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 70px rgba(10, 33, 38, 0.13);
}

.metric::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 14px;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.form-grid {
  border-top: 4px solid var(--accent);
}

.badge.warning {
  color: var(--warning);
  background: var(--warning-bg);
}

.nav-tab[data-view="collaborators"]::before { content: "C"; }

/* Aparencia clara e profissional */
:root {
  --bg: #f6f8fb;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-soft: #f1f5f9;
  --ink: #172026;
  --muted: #667085;
  --line: #dfe7ef;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --warning: #b45309;
  --warning-bg: #fff7ed;
  --danger: #b42318;
  --danger-bg: #fef2f2;
  --ok: #047857;
  --ok-bg: #ecfdf5;
  --income: #047857;
  --shadow: 0 14px 38px rgba(15, 23, 42, 0.08);
}

body {
  background:
    radial-gradient(circle at top left, rgba(14, 165, 233, 0.12), transparent 30%),
    linear-gradient(180deg, #fbfdff 0%, #f5f7fb 100%);
  color: var(--ink);
}

.app-shell {
  background: transparent;
}

.sidebar {
  background: rgba(255, 255, 255, 0.82);
  border-right: 1px solid rgba(226, 232, 240, 0.95);
  box-shadow: 18px 0 48px rgba(15, 23, 42, 0.05);
  backdrop-filter: blur(18px);
}

.brand strong,
.nav-tab {
  color: #111827;
}

.brand span,
.eyebrow {
  color: #64748b;
}

.brand-mark {
  background: linear-gradient(135deg, #0f766e, #38bdf8);
  color: #fff;
}

.nav-tab {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 12px;
}

.nav-tab::before {
  background: #eef6f7;
  color: #0f766e;
}

.nav-tab.active,
.nav-tab:hover {
  background: #ffffff;
  border-color: #dbe7ee;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.07);
}

.topbar {
  background: rgba(246, 248, 251, 0.82);
}

.metric,
.form-grid,
.record-form,
.finance-form,
.table-wrap,
.panel,
.kanban-column,
.call-card {
  border: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.form-grid,
.record-form,
.finance-form {
  border-top: 0;
}

input,
select,
textarea {
  border-color: #d8e2ec;
  border-radius: 11px;
  background: #fbfdff;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.16);
}

.primary-action {
  border-radius: 11px;
  background: linear-gradient(135deg, #0f766e, #0ea5e9);
  box-shadow: 0 10px 24px rgba(14, 165, 233, 0.18);
}

.secondary-action,
.link-action,
.table-action {
  border-radius: 10px;
  background: #ffffff;
}

.inline-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.checklist-items {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fafc;
}

.checklist-item-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(260px, 1.5fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #fff;
}

.segmented-status {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.segmented-status label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid #d8e2ec;
  border-radius: 999px;
  background: #f8fafc;
  font-weight: 800;
}

.fleet-photos {
  display: flex;
  gap: 6px;
  align-items: center;
}

.fleet-thumb {
  width: 58px;
  height: 42px;
  object-fit: cover;
  border: 1px solid #d8e2ec;
  border-radius: 10px;
  background: #f8fafc;
}

.attachments-panel {
  margin-top: 18px;
}

.attachments-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  padding: 0 18px 18px;
  color: var(--muted);
  flex-wrap: wrap;
}

.attachments-toolbar label {
  min-width: min(320px, 100%);
}

.attachments-toolbar span {
  font-weight: 800;
  color: var(--accent);
}

.app-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(8px);
}

.app-modal.hidden {
  display: none;
}

.app-modal-card {
  width: min(780px, 100%);
  max-height: min(86vh, 820px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.22);
}

.app-modal-head,
.app-modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.app-modal-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.app-modal-head h3 {
  margin: 0;
}

.app-modal-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 18px;
  overflow: auto;
}

.app-modal-body label.wide {
  grid-column: 1 / -1;
}

.app-toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 120;
  max-width: min(420px, calc(100vw - 44px));
  padding: 14px 16px;
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: 16px;
  background: #ecfdf5;
  color: #065f46;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.18);
  font-weight: 900;
}

.app-toast.warning {
  border-color: rgba(245, 158, 11, 0.35);
  background: #fffbeb;
  color: #92400e;
}

.app-toast.error {
  border-color: rgba(220, 38, 38, 0.28);
  background: #fef2f2;
  color: #991b1b;
}

.call-ambulance-plate {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-width: 150px;
  padding: 10px 16px;
  border-radius: 12px;
  background: #111827;
  color: #ffffff;
  font-size: 1.65rem;
  font-weight: 950;
  letter-spacing: 0;
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.18);
}

.sound-active {
  border-color: rgba(16, 185, 129, 0.45);
  background: #ecfdf5;
  color: #047857;
}

body[data-theme="apple"] {
  --bg: #f7f9fc;
  --surface: rgba(255, 255, 255, 0.94);
  --surface-soft: #f1f5f9;
  --ink: #111827;
  --muted: #667085;
  --line: #dce5ef;
  --accent: #0f766e;
  --accent-strong: #0f5f59;
  --shadow: 0 16px 42px rgba(15, 23, 42, 0.08);
  background: linear-gradient(180deg, #fbfdff 0%, #f4f7fb 100%);
}

body[data-theme="apple"] .sidebar {
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.16) 0 7px, transparent 7px),
    rgba(255, 255, 255, 0.88);
}

body[data-theme="apple"] .primary-action,
body[data-theme="apple"] .secondary-action,
body[data-theme="apple"] .link-action,
body[data-theme="apple"] .table-action,
body[data-theme="apple"] input,
body[data-theme="apple"] select,
body[data-theme="apple"] textarea,
body[data-theme="apple"] .metric,
body[data-theme="apple"] .form-grid,
body[data-theme="apple"] .table-wrap,
body[data-theme="apple"] .call-card {
  border-radius: 18px;
}

body[data-theme="premium"] {
  --bg: #f3f4f6;
  --surface: rgba(255, 255, 255, 0.95);
  --surface-soft: #e5e7eb;
  --ink: #111827;
  --muted: #6b7280;
  --line: #d1d5db;
  --accent: #4b5563;
  --accent-strong: #1f2937;
  --shadow: 0 18px 48px rgba(17, 24, 39, 0.1);
  background: linear-gradient(180deg, #ffffff 0%, #eef0f3 100%);
}

body[data-theme="premium"] .sidebar {
  background:
    linear-gradient(90deg, #6b7280 0 7px, transparent 7px),
    rgba(250, 250, 250, 0.92);
}

body[data-theme="premium"] .brand-mark,
body[data-theme="premium"] .primary-action {
  background: linear-gradient(135deg, #111827, #6b7280);
}

body[data-theme="premium"] .nav-tab::before {
  background: #e5e7eb;
  color: #374151;
}

body[data-theme="emergency"] {
  --bg: #fff7f7;
  --surface: rgba(255, 255, 255, 0.96);
  --surface-soft: #fff1f2;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #fecdd3;
  --accent: #dc2626;
  --accent-strong: #991b1b;
  --warning: #b45309;
  --danger: #b91c1c;
  --shadow: 0 18px 48px rgba(153, 27, 27, 0.11);
  background:
    radial-gradient(circle at top right, rgba(220, 38, 38, 0.12), transparent 32%),
    linear-gradient(180deg, #fff 0%, #fff7f7 100%);
}

body[data-theme="emergency"] .sidebar {
  background:
    linear-gradient(90deg, #dc2626 0 7px, transparent 7px),
    rgba(255, 255, 255, 0.92);
}

body[data-theme="emergency"] .brand-mark,
body[data-theme="emergency"] .primary-action {
  background: linear-gradient(135deg, #dc2626, #f59e0b);
}

body[data-theme="emergency"] .call-ambulance-plate {
  background: #991b1b;
  box-shadow: 0 14px 32px rgba(185, 28, 28, 0.22);
}

/* Identidade AmbuGestao - dashboard medico claro */
:root {
  --bg-main: #f6f8fb;
  --bg-card: #ffffff;
  --bg-soft: #f1f5f9;
  --bg-hover: #eef6f8;
  --bg-input: #fbfdff;

  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-soft: #dff4f2;
  --secondary: #2563eb;

  --success: #059669;
  --success-soft: #dcfce7;
  --success-text: #047857;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --warning-text: #92400e;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --danger-text: #991b1b;
  --info: #0e7490;
  --info-soft: #cffafe;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  --border: #e2e8f0;
  --shadow-soft: 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-hover: 0 16px 36px rgba(15, 23, 42, 0.09);
  --radius-card: 18px;
  --radius-button: 12px;

  /* Compatibilidade com as classes antigas do sistema */
  --bg: var(--bg-main);
  --surface: var(--bg-card);
  --surface-soft: var(--bg-soft);
  --ink: var(--text-main);
  --muted: var(--text-muted);
  --line: var(--border);
  --accent: var(--primary);
  --accent-strong: var(--primary-hover);
  --warning-bg: var(--warning-soft);
  --danger-bg: var(--danger-soft);
  --ok: var(--success);
  --ok-bg: var(--success-soft);
  --income: var(--success);
  --shadow: var(--shadow-soft);
}

body,
body[data-theme="apple"],
body[data-theme="premium"],
body[data-theme="emergency"] {
  background: var(--bg-main);
  color: var(--text-main);
}

.app-shell {
  background: var(--bg-main);
}

.sidebar,
body[data-theme="apple"] .sidebar,
body[data-theme="premium"] .sidebar,
body[data-theme="emergency"] .sidebar {
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.12) 0 5px, transparent 5px),
    rgba(255, 255, 255, 0.94);
  border-right: 1px solid var(--border);
  box-shadow: 12px 0 32px rgba(15, 23, 42, 0.04);
  color: var(--text-main);
}

.brand {
  border-bottom: 1px solid var(--border);
}

.brand strong,
.nav-tab {
  color: var(--text-main);
}

.brand span,
.eyebrow,
.muted,
td span {
  color: var(--text-muted);
}

.brand-mark,
body[data-theme="premium"] .brand-mark,
body[data-theme="emergency"] .brand-mark {
  background: var(--info-soft);
  color: var(--info);
  border-radius: 14px;
}

.brand-logo {
  border-color: var(--border);
  box-shadow: var(--shadow-soft);
}

.nav-tabs {
  gap: 7px;
}

.nav-tab {
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: var(--text-main);
}

.nav-tab::before {
  background: var(--info-soft);
  color: var(--info);
}

.nav-tab:hover,
.nav-tab.active {
  border-color: var(--border);
  background: var(--bg-hover);
  color: var(--primary-hover);
  box-shadow: none;
}

.nav-tab.active::before,
.nav-tab:hover::before {
  background: var(--primary-soft);
  color: var(--primary);
}

.nav-tab[data-view="calls"] {
  color: var(--success);
}

.nav-tab[data-view="calls"]::before {
  background: var(--success-soft);
  color: var(--success);
}

.nav-tab[data-view="calls"]:hover,
.nav-tab[data-view="calls"].active {
  border-color: var(--success-soft);
  background: var(--success-soft);
  color: var(--success);
}

.nav-tab[data-view="calls"]:hover::before,
.nav-tab[data-view="calls"].active::before {
  background: var(--bg-card);
  color: var(--success);
}

.content {
  background: var(--bg-main);
}

.topbar {
  background: rgba(246, 248, 251, 0.88);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

h1,
h2,
h3,
.section-heading h2,
.panel-header h3 {
  color: var(--text-main);
  letter-spacing: 0;
}

.section-heading p {
  color: var(--text-muted);
}

.metric,
.form-grid,
.record-form,
.finance-form,
.table-wrap,
.panel,
.embedded-panel,
.kanban-column,
.call-card,
.app-modal-card,
.login-card,
.master-card,
.signup-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--bg-card);
  box-shadow: var(--shadow-soft);
}

.metric {
  padding: 20px;
}

.metric:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-hover);
}

.metric::after {
  background: var(--bg-soft);
  opacity: 0.86;
}

.metric span {
  color: var(--text-muted);
}

.metric strong {
  color: var(--text-main);
}

.metric.warning strong {
  color: var(--warning);
}

.metric.danger strong {
  color: var(--danger);
}

.metric.positive strong {
  color: var(--success);
}

.metric.info strong {
  color: var(--info);
}

.call-response-time {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin: 8px 0 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--info-soft);
  color: var(--info);
  font-size: 0.78rem;
  font-weight: 800;
}

.call-response-time.income {
  background: var(--success-soft);
  color: var(--success);
}

.call-response-time.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.call-response-time.expense {
  background: var(--danger-soft);
  color: var(--danger);
}

.form-grid,
.record-form,
.finance-form,
.filters {
  border-top: 0;
  gap: 16px;
}

label {
  color: var(--text-muted);
}

input,
select,
textarea {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-input);
  color: var(--text-main);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--info);
  outline: 3px solid rgba(14, 116, 144, 0.14);
  box-shadow: none;
}

.primary-action,
body[data-theme="premium"] .primary-action,
body[data-theme="emergency"] .primary-action {
  border: 0;
  border-radius: var(--radius-button);
  background: var(--primary);
  color: var(--text-inverse);
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.16);
}

.primary-action:hover {
  background: var(--primary-hover);
}

.secondary-action,
.link-action,
.table-action,
.icon-action {
  border: 1px solid var(--border);
  border-radius: var(--radius-button);
  background: var(--bg-card);
  color: var(--primary-hover);
  box-shadow: none;
}

.secondary-action:hover,
.link-action:hover,
.table-action:hover,
.icon-action:hover {
  border-color: rgba(14, 116, 144, 0.26);
  background: var(--bg-hover);
  color: var(--primary);
}

.user-chip,
.tenant-switcher select {
  border-color: var(--border);
  border-radius: var(--radius-button);
  background: var(--bg-card);
  color: var(--text-main);
}

table {
  color: var(--text-main);
}

thead th,
th {
  background: var(--bg-soft);
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

td {
  border-bottom: 1px solid var(--border);
}

tbody tr:hover {
  background: var(--bg-input);
}

.badge,
.login-status {
  border-radius: 999px;
  font-weight: 900;
}

.badge.ok,
.badge.income,
.login-status.ok {
  color: var(--success-text);
  background: var(--success-soft);
}

.badge.warning,
.badge.expiring,
.login-status.warning {
  color: var(--warning);
  background: var(--warning-soft);
}

.badge.expired,
.badge.expense {
  color: var(--danger);
  background: var(--danger-soft);
}

.badge.info {
  color: var(--info);
  background: var(--info-soft);
}

.stock-alerts .badge.expired,
.stock-alerts .badge.expense,
.badge.danger {
  color: var(--danger);
  background: var(--danger-soft);
}

.stock-alerts .badge.expiring,
.stock-alerts .badge.warning {
  color: var(--warning);
  background: var(--warning-soft);
}

.kanban-column {
  background: var(--bg-card);
}

.kanban-header {
  background: var(--bg-soft);
  border-bottom-color: var(--border);
}

.kanban-header span {
  background: var(--primary);
  color: var(--text-inverse);
}

.call-card {
  border-left-color: var(--info);
}

.call-ambulance-plate,
body[data-theme="emergency"] .call-ambulance-plate {
  background: var(--text-main);
  color: var(--text-inverse);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.14);
}

.call-meta,
.call-route {
  color: var(--text-muted);
}

.call-route {
  color: var(--text-main);
}

.app-toast {
  border-color: rgba(5, 150, 105, 0.24);
  background: var(--success-soft);
  color: var(--success-text);
  box-shadow: var(--shadow-hover);
}

.app-toast.warning {
  border-color: rgba(217, 119, 6, 0.28);
  background: var(--warning-soft);
  color: var(--warning-text);
}

.app-toast.error {
  border-color: rgba(220, 38, 38, 0.24);
  background: var(--danger-soft);
  color: var(--danger-text);
}

.checklist-items,
.checklist-item-row,
.segmented-status label,
.attachments-toolbar,
.logo-preview-row img {
  border-color: var(--border);
  background: var(--bg-card);
}

body[data-theme="premium"] {
  --primary: #4b5563;
  --primary-hover: #1f2937;
  --info: #475569;
  --info-soft: #e2e8f0;
}

body[data-theme="emergency"] {
  --primary: #0e7490;
  --primary-hover: #155e75;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --warning-soft: #fef3c7;
}

/* AmbuGestao premium operational themes */
:root {
  --bg-main: #f6f8fb;
  --bg-card: #ffffff;
  --bg-soft: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-soft: #e2e8f0;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --success: #059669;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #2563eb;
  --info-soft: #dbeafe;
  --shadow-soft: 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-medium: 0 18px 45px rgba(15, 23, 42, 0.10);
  --radius-card: 18px;
  --radius-button: 14px;
  --sidebar-gradient: linear-gradient(160deg, #064e4a 0%, #0f766e 58%, #14b8a6 100%);
}

body.theme-green {
  --primary: #0f766e;
  --primary-hover: #064e4a;
  --info: #0f766e;
  --info-soft: #ccfbf1;
  --sidebar-gradient: linear-gradient(160deg, #064e4a 0%, #0f766e 58%, #14b8a6 100%);
}

body.theme-blue {
  --primary: #1d4ed8;
  --primary-hover: #0f3a8c;
  --info: #2563eb;
  --info-soft: #dbeafe;
  --sidebar-gradient: linear-gradient(160deg, #0f3a8c 0%, #1d4ed8 58%, #2563eb 100%);
}

body.theme-premium-gray {
  --primary: #374151;
  --primary-hover: #1f2937;
  --info: #4b5563;
  --info-soft: #e5e7eb;
  --sidebar-gradient: linear-gradient(160deg, #1f2937 0%, #374151 58%, #4b5563 100%);
}

body.theme-apple-light {
  --bg-main: #f8fafc;
  --bg-soft: #eef2f7;
  --primary: #0f766e;
  --primary-hover: #0f5f59;
  --info: #0ea5e9;
  --info-soft: #e0f2fe;
  --radius-card: 24px;
  --radius-button: 999px;
  --sidebar-gradient: linear-gradient(160deg, #0f172a 0%, #1f2937 48%, #0f766e 100%);
}

body.theme-premium-light {
  --bg-main: #f5f7fb;
  --bg-soft: #eef0f4;
  --primary: #475569;
  --primary-hover: #1f2937;
  --info: #64748b;
  --info-soft: #e2e8f0;
  --radius-card: 20px;
  --radius-button: 16px;
  --sidebar-gradient: linear-gradient(160deg, #111827 0%, #334155 58%, #64748b 100%);
}

body.theme-hospital-soft {
  --bg-main: #f7fbff;
  --bg-soft: #eaf6ff;
  --primary: #0e7490;
  --primary-hover: #155e75;
  --info: #2563eb;
  --info-soft: #dbeafe;
  --success: #059669;
  --success-soft: #dcfce7;
  --radius-card: 18px;
  --radius-button: 14px;
  --sidebar-gradient: linear-gradient(160deg, #083344 0%, #0e7490 54%, #38bdf8 100%);
}

body.theme-green,
body.theme-blue,
body.theme-premium-gray,
body.theme-apple-light,
body.theme-premium-light,
body.theme-hospital-soft {
  background: var(--bg-main);
  color: var(--text-main);
}

body.theme-green .sidebar,
body.theme-blue .sidebar,
body.theme-premium-gray .sidebar,
body.theme-apple-light .sidebar,
body.theme-premium-light .sidebar,
body.theme-hospital-soft .sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar-gradient);
  border-right: 0;
  box-shadow: 18px 0 45px rgba(15, 23, 42, 0.14);
  color: #ffffff;
}

body.theme-green .brand,
body.theme-blue .brand,
body.theme-premium-gray .brand,
body.theme-apple-light .brand,
body.theme-premium-light .brand,
body.theme-hospital-soft .brand {
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

body.theme-green .brand strong,
body.theme-green .brand span,
body.theme-blue .brand strong,
body.theme-blue .brand span,
body.theme-premium-gray .brand strong,
body.theme-premium-gray .brand span,
body.theme-apple-light .brand strong,
body.theme-apple-light .brand span,
body.theme-premium-light .brand strong,
body.theme-premium-light .brand span,
body.theme-hospital-soft .brand strong,
body.theme-hospital-soft .brand span {
  color: #ffffff;
}

body.theme-green .brand span,
body.theme-blue .brand span,
body.theme-premium-gray .brand span,
body.theme-apple-light .brand span,
body.theme-premium-light .brand span,
body.theme-hospital-soft .brand span,
.sidebar-footer span {
  opacity: 0.78;
}

body.theme-green .brand-mark,
body.theme-blue .brand-mark,
body.theme-premium-gray .brand-mark,
body.theme-apple-light .brand-mark,
body.theme-premium-light .brand-mark,
body.theme-hospital-soft .brand-mark {
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

body.theme-green .brand-logo,
body.theme-blue .brand-logo,
body.theme-premium-gray .brand-logo,
body.theme-apple-light .brand-logo,
body.theme-premium-light .brand-logo,
body.theme-hospital-soft .brand-logo {
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(255, 255, 255, 0.36);
}

body.theme-green .nav-tabs,
body.theme-blue .nav-tabs,
body.theme-premium-gray .nav-tabs,
body.theme-apple-light .nav-tabs,
body.theme-premium-light .nav-tabs,
body.theme-hospital-soft .nav-tabs {
  gap: 8px;
}

body.theme-green .nav-tab,
body.theme-blue .nav-tab,
body.theme-premium-gray .nav-tab,
body.theme-apple-light .nav-tab,
body.theme-premium-light .nav-tab,
body.theme-hospital-soft .nav-tab {
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 14px;
  color: rgba(255, 255, 255, 0.90);
  font-weight: 800;
}

body.theme-green .nav-tab::before,
body.theme-blue .nav-tab::before,
body.theme-premium-gray .nav-tab::before,
body.theme-apple-light .nav-tab::before,
body.theme-premium-light .nav-tab::before,
body.theme-hospital-soft .nav-tab::before {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

body.theme-green .nav-tab:hover,
body.theme-green .nav-tab.active,
body.theme-blue .nav-tab:hover,
body.theme-blue .nav-tab.active,
body.theme-premium-gray .nav-tab:hover,
body.theme-premium-gray .nav-tab.active,
body.theme-apple-light .nav-tab:hover,
body.theme-apple-light .nav-tab.active,
body.theme-premium-light .nav-tab:hover,
body.theme-premium-light .nav-tab.active,
body.theme-hospital-soft .nav-tab:hover,
body.theme-hospital-soft .nav-tab.active {
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

body.theme-green .nav-tab:hover::before,
body.theme-green .nav-tab.active::before,
body.theme-blue .nav-tab:hover::before,
body.theme-blue .nav-tab.active::before,
body.theme-premium-gray .nav-tab:hover::before,
body.theme-premium-gray .nav-tab.active::before,
body.theme-apple-light .nav-tab:hover::before,
body.theme-apple-light .nav-tab.active::before,
body.theme-premium-light .nav-tab:hover::before,
body.theme-premium-light .nav-tab.active::before,
body.theme-hospital-soft .nav-tab:hover::before,
body.theme-hospital-soft .nav-tab.active::before {
  background: #ffffff;
  color: var(--primary);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 16px 10px 4px;
  color: #ffffff;
}

.sidebar-footer strong,
.sidebar-footer span {
  display: block;
}

.online-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 999px;
  background: #22c55e;
  box-shadow: 0 0 0 5px rgba(34, 197, 94, 0.20);
}

body.theme-green .content,
body.theme-blue .content,
body.theme-premium-gray .content,
body.theme-apple-light .content,
body.theme-premium-light .content,
body.theme-hospital-soft .content {
  background: var(--bg-main);
}

body.theme-green .topbar,
body.theme-blue .topbar,
body.theme-premium-gray .topbar,
body.theme-apple-light .topbar,
body.theme-premium-light .topbar,
body.theme-hospital-soft .topbar {
  background: rgba(246, 248, 251, 0.88);
  border-bottom: 1px solid var(--border-soft);
}

body.theme-green .metric,
body.theme-blue .metric,
body.theme-premium-gray .metric,
body.theme-apple-light .metric,
body.theme-premium-light .metric,
body.theme-hospital-soft .metric,
body.theme-green .panel,
body.theme-blue .panel,
body.theme-premium-gray .panel,
body.theme-apple-light .panel,
body.theme-premium-light .panel,
body.theme-hospital-soft .panel,
body.theme-green .table-wrap,
body.theme-blue .table-wrap,
body.theme-premium-gray .table-wrap,
body.theme-apple-light .table-wrap,
body.theme-premium-light .table-wrap,
body.theme-hospital-soft .table-wrap,
body.theme-green .call-card,
body.theme-blue .call-card,
body.theme-premium-gray .call-card,
body.theme-apple-light .call-card,
body.theme-premium-light .call-card,
body.theme-hospital-soft .call-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-card);
  background: var(--bg-card);
  box-shadow: var(--shadow-soft);
}

body.theme-green .metric,
body.theme-blue .metric,
body.theme-premium-gray .metric,
body.theme-apple-light .metric,
body.theme-premium-light .metric,
body.theme-hospital-soft .metric {
  position: relative;
  overflow: hidden;
  padding: 22px;
}

body.theme-green .metric::before,
body.theme-blue .metric::before,
body.theme-premium-gray .metric::before,
body.theme-apple-light .metric::before,
body.theme-premium-light .metric::before,
body.theme-hospital-soft .metric::before {
  content: "";
  display: block;
  width: 38px;
  height: 38px;
  margin-bottom: 14px;
  border-radius: 999px;
  background: var(--info-soft);
}

body.theme-green .primary-action,
body.theme-blue .primary-action,
body.theme-premium-gray .primary-action,
body.theme-apple-light .primary-action,
body.theme-premium-light .primary-action,
body.theme-hospital-soft .primary-action,
.start-call-action {
  border-radius: var(--radius-button);
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #ffffff;
  box-shadow: 0 12px 24px rgba(15, 118, 110, 0.18);
}

body.theme-green .secondary-action,
body.theme-blue .secondary-action,
body.theme-premium-gray .secondary-action,
body.theme-apple-light .secondary-action,
body.theme-premium-light .secondary-action,
body.theme-hospital-soft .secondary-action,
body.theme-green .table-action,
body.theme-blue .table-action,
body.theme-premium-gray .table-action,
body.theme-apple-light .table-action,
body.theme-premium-light .table-action,
body.theme-hospital-soft .table-action {
  border-radius: var(--radius-button);
}

body.theme-apple-light input,
body.theme-apple-light select,
body.theme-apple-light textarea {
  border-radius: 18px;
}

body.theme-apple-light .primary-action,
body.theme-apple-light .secondary-action,
body.theme-apple-light .table-action {
  min-height: 44px;
  padding-inline: 18px;
}

.danger-action {
  border-color: rgba(220, 38, 38, 0.28);
  color: var(--danger);
}

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

.theme-modal-card {
  max-width: 620px;
}

.theme-options {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 18px;
}

.theme-option {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-card);
  background: #ffffff;
  cursor: pointer;
}

.theme-option input {
  width: auto;
}

.theme-preview {
  display: block;
  height: 74px;
  border-radius: 14px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.theme-preview-green {
  background: linear-gradient(160deg, #064e4a, #0f766e 58%, #14b8a6);
}

.theme-preview-blue {
  background: linear-gradient(160deg, #0f3a8c, #1d4ed8 58%, #2563eb);
}

.theme-preview-gray {
  background: linear-gradient(160deg, #1f2937, #374151 58%, #4b5563);
}

.theme-preview-apple {
  background: linear-gradient(160deg, #f8fafc 0%, #e0f2fe 48%, #0f766e 100%);
}

.theme-preview-premium-light {
  background: linear-gradient(160deg, #f8fafc 0%, #cbd5e1 48%, #475569 100%);
}

.theme-preview-hospital {
  background: linear-gradient(160deg, #eff6ff 0%, #bae6fd 48%, #0e7490 100%);
}

@keyframes pulseDanger {
  0% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.55);
    border-color: #dc2626;
  }
  50% {
    box-shadow: 0 0 0 10px rgba(220, 38, 38, 0.10);
    border-color: #ef4444;
  }
  100% {
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0);
    border-color: #dc2626;
  }
}

@keyframes plateBlink {
  0%,
  100% {
    background: #dc2626;
    transform: scale(1);
  }
  50% {
    background: #991b1b;
    transform: scale(1.03);
  }
}

.new-call-alert {
  border: 2px solid var(--danger) !important;
  animation: pulseDanger 1s infinite;
}

.new-call-alert .plate,
.new-call-alert .placa,
.new-call-alert .vehicle-plate {
  background: #dc2626 !important;
  color: #ffffff !important;
  animation: plateBlink 0.75s infinite;
}

.call-alert-toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 80;
  display: grid;
  gap: 4px;
  width: min(330px, calc(100vw - 32px));
  padding: 16px 18px 16px 52px;
  border: 1px solid #fca5a5;
  border-radius: 18px;
  background: #fee2e2;
  color: #991b1b;
  box-shadow: var(--shadow-medium);
}

.call-alert-toast::before {
  content: "!";
  position: absolute;
  left: 18px;
  top: 18px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: #dc2626;
  color: #ffffff;
  font-weight: 950;
}

.call-alert-toast.hidden {
  display: none;
}

.visual-action {
  border-color: var(--border-soft);
}

body.calls-only-user .nav-tabs {
  margin-top: 16px;
}

body.calls-only-user .nav-tab:not([data-view="calls"]) {
  display: none !important;
}

body.calls-only-user .nav-tab[data-view="calls"] {
  min-height: 54px;
  font-size: 1rem;
}

body.calls-only-user .topbar {
  align-items: center;
}

body.calls-only-user .topbar .eyebrow {
  color: var(--primary);
}

@media (max-width: 980px) {
  .kanban-board {
    grid-template-columns: 1fr;
  }

  .checklist-item-row,
  .inline-fields,
  .theme-options {
    grid-template-columns: 1fr;
  }
}

/* Mobile final override - must remain last */
@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .app-shell {
    display: block;
    width: 100%;
    min-width: 0;
    grid-template-columns: 1fr;
    background: var(--bg);
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 30;
    width: 100%;
    min-height: auto;
    padding: 12px;
    gap: 10px;
  }

  .brand {
    padding-bottom: 10px;
  }

  .nav-tabs {
    display: flex;
    grid-template-columns: none;
    gap: 8px;
    width: 100%;
    overflow-x: auto;
    padding: 0 2px 6px;
  }

  .nav-tab {
    flex: 0 0 auto;
    width: auto;
    min-width: 116px;
    min-height: 40px;
    justify-content: center;
    padding: 8px 10px;
    font-size: 0.86rem;
    white-space: nowrap;
  }

  .nav-tab::before {
    width: 22px;
    height: 22px;
    font-size: 0.72rem;
  }

  .content {
    width: 100%;
    min-width: 0;
    padding: 12px;
  }

  .topbar {
    position: static;
    display: grid;
    margin: 0 0 14px;
    padding: 0;
    gap: 12px;
    background: transparent;
    border: 0;
    backdrop-filter: none;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    width: 100%;
  }

  .topbar-actions > *,
  .tenant-switcher,
  .user-chip,
  .primary-action,
  .secondary-action,
  .link-action {
    width: 100%;
  }

  h1 {
    font-size: 1.28rem;
    line-height: 1.25;
  }

  h2 {
    font-size: 1.18rem;
  }

  .section-heading {
    display: grid;
    gap: 10px;
  }

  .metrics-grid,
  .dashboard-grid,
  .form-grid,
  .record-form,
  .finance-form,
  .permissions,
  .filters,
  .kanban-board {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .metric::after {
    display: none;
  }

  .metric span {
    min-height: 0;
    font-size: 0.84rem;
  }

  .metric strong {
    font-size: 1.45rem;
  }

  .form-grid,
  .filters {
    padding: 12px;
  }

  input,
  select,
  textarea {
    min-height: 44px;
    font-size: 16px;
    padding: 9px 10px;
  }

  .table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 680px;
  }

  th,
  td {
    padding: 9px;
    font-size: 0.84rem;
  }

  .call-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .app-modal-body {
    grid-template-columns: 1fr;
  }

  .app-modal-actions,
  .app-modal-head {
    align-items: stretch;
  }
}
