:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --line: #d8dee8;
  --text: #18202a;
  --muted: #647084;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #a43d3d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

[hidden] { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef2f6;
}

.login-panel {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 14px;
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 50px rgb(15 23 42 / 10%);
}

.login-panel p { margin: 4px 0 0; color: var(--muted); }
.login-panel form, #externalProviders, .login-panel > .auth-links, #tenantGate, #authMessage { grid-column: 1 / -1; min-width: 0; }
.login-panel > div:nth-child(2) { min-width: 0; }
.login-panel h1 { font-size: 24px; overflow-wrap: anywhere; }
.default-logo, .brand-logo {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 16px 12px; background: #17212b; color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 4px 8px 18px; border-bottom: 1px solid rgb(255 255 255 / 12%); }
.brand img { width: 44px; height: 44px; object-fit: contain; border-radius: 6px; background: #fff; }
.brand strong, .brand span { display: block; }
.brand span { color: #aeb9c7; font-size: 12px; }
.sidebar nav { display: grid; gap: 4px; padding-top: 16px; }
.nav-item { width: 100%; text-align: left; background: transparent; color: #d7dee8; }
.nav-item:hover, .nav-item.active { background: rgb(255 255 255 / 10%); color: #fff; }
.nav-item.active { box-shadow: inset 3px 0 var(--accent); }
.sidebar-footer { margin-top: auto; border-top: 1px solid rgb(255 255 255 / 12%); padding-top: 12px; }
.app-content { min-width: 0; }
.app-header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 22px; border-bottom: 1px solid var(--line); background: #fff; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.current-user { max-width: 240px; padding-left: 10px; border-left: 1px solid var(--line); }
.current-user strong, .current-user span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.current-user span { color: var(--muted); font-size: 11px; }
.tenant-picker { min-width: 190px; }
.tenant-picker select { min-height: 32px; padding-block: 5px; }
.page-content { padding: 20px; }
.page-view { max-width: 1400px; margin: 0 auto; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metrics article { padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.metrics span, .metrics strong { display: block; }
.metrics span { color: var(--muted); font-size: 12px; }
.metrics strong { margin-top: 6px; font-size: 22px; }
.two-columns { display: grid; grid-template-columns: repeat(2, minmax(280px, 1fr)); gap: 16px; }
.form-panel { max-width: 1080px; }
.settings-panel { max-width: 620px; }
.brand-preview { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--line); background: #f8fafc; }
.brand-preview strong, .brand-preview span { display: block; }
.brand-preview span { color: var(--muted); font-size: 12px; }
.recent-list { display: grid; }
.recent-item { min-height: 58px; display: flex; justify-content: space-between; align-items: center; gap: 20px; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; color: var(--text); text-align: left; }
.recent-item:hover { background: #f7f9fb; }
.recent-item span:last-child { text-align: right; }
.recent-item strong, .recent-item small { display: block; }
.recent-item small, .empty-state { color: var(--muted); }
.help-content { min-height: 150px; padding: 24px; font-size: 15px; line-height: 1.6; }
.users-layout { display: grid; grid-template-columns: minmax(280px, 380px) minmax(420px, 1fr); gap: 16px; }
.inventory-layout { display: grid; grid-template-columns: repeat(2, minmax(300px, 1fr)); gap: 16px; }
.finance-layout { display: grid; grid-template-columns: minmax(260px, 340px) minmax(500px, 1fr); gap: 16px; }
.three-columns { display: grid; grid-template-columns: repeat(3, minmax(260px, 1fr)); gap: 16px; }
.coverage-search { margin-bottom: 16px; }
.search-form { display: grid; grid-template-columns: minmax(240px, 1fr) auto; align-items: end; gap: 10px; }
.coverage-results { display: grid; margin-top: 12px; }
.coverage-item { display: flex; justify-content: space-between; gap: 20px; padding: 12px 0; border-top: 1px solid var(--line); }
.coverage-item strong, .coverage-item span { display: block; }
.coverage-item span { color: var(--muted); font-size: 12px; }
.module-tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.module-tabs button { min-height: 40px; border-radius: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); }
.module-tabs button:hover { background: #edf1f5; color: var(--text); }
.module-tabs button.active { border-bottom-color: var(--accent); color: var(--text); }
.module-heading { margin-bottom: 12px; }
.module-heading h2 { color: var(--text); font-size: 17px; }
.module-heading p { margin: 4px 0 0; color: var(--muted); }
.module-view > .panel { max-width: none; }
.module-view > .focused-form { max-width: 680px; }
.module-view[data-plan-view="clientes"] > .panel,
.module-view[data-plan-view="produtos"] > .panel { max-width: 620px; }
.module-view[data-plan-view="contratos"] > .panel:first-of-type { max-width: 760px; }
.check-label { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.check-label input { width: 16px; min-height: 16px; }
.inventory-results { margin-top: 16px; }
.inline-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.users-list { display: grid; }
.user-item { display: grid; grid-template-columns: minmax(180px, 1fr) 2fr; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.user-item > div > strong, .user-item > div > span { display: block; }
.user-item > div > span { color: var(--muted); font-size: 12px; }
.access-list { display: flex; flex-wrap: wrap; gap: 6px; }
.access-tag { padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; background: #f7f9fb; font-size: 11px; }
.access-tag strong { margin-right: 6px; color: var(--text); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 72px;
  padding: 14px 24px;
  background: #15202b;
  color: #fff;
}

.topbar strong {
  display: block;
  font-size: 18px;
}

.topbar span {
  color: #cad2df;
}

.userbox {
  display: flex;
  align-items: end;
  gap: 10px;
}

.shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(420px, 1fr);
  gap: 16px;
  padding: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.panel.full {
  grid-column: 1 / -1;
}

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

h1, h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 14px;
  color: var(--muted);
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input, select, textarea, button {
  min-height: 36px;
  border-radius: 6px;
  font: inherit;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

button {
  border: 0;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  background: #e9eef5;
  color: var(--text);
}

button[data-action="remove"] {
  background: #f1e6e6;
  color: var(--danger);
}

.stack {
  display: grid;
  gap: 10px;
  padding-top: 12px;
}

.stack + .stack {
  margin-top: 18px;
  border-top: 1px solid var(--line);
}

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

.wide, fieldset, .primary {
  grid-column: 1 / -1;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
}

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

legend {
  padding: 0 6px;
  color: var(--muted);
  font-weight: 700;
}

.recebimento-row, .item-row {
  display: grid;
  grid-template-columns: 1fr 120px 150px 90px;
  gap: 8px;
  margin-bottom: 8px;
}

.item-row {
  grid-template-columns: minmax(180px, 2fr) 120px 140px minmax(150px, 1fr) 90px;
}

.fieldset-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.status {
  display: inline-block;
  padding: 3px 7px;
  border-radius: 4px;
  background: #eef1f5;
  font-size: 12px;
  font-weight: 700;
}

.status-fechado {
  background: #e7f6ef;
  color: #176c4f;
}

button.compact {
  min-height: 30px;
  padding: 5px 9px;
}

button:disabled {
  cursor: wait;
  opacity: .6;
}

.actions-cell {
  display: flex;
  gap: 6px;
}

dialog {
  width: min(940px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
}

dialog::backdrop {
  background: rgb(15 23 42 / 55%);
}

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

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

.dialog-header h2 {
  color: var(--text);
  font-size: 18px;
}

.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.icon-button {
  width: 36px;
  padding: 0;
  background: transparent;
  color: var(--text);
  font-size: 17px;
}

.document-preview {
  overflow: auto;
  padding: 24px;
}

.document-title {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--text);
}

.document-title div:last-child {
  text-align: right;
}

.document-title strong, .document-title span {
  display: block;
}

.document-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.document-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
}

.document-section p {
  white-space: pre-wrap;
}

.document-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px 24px;
}

.document-field span, .document-field strong {
  display: block;
}

.document-field span {
  color: var(--muted);
  font-size: 11px;
}

.document-total {
  display: flex;
  justify-content: flex-end;
  gap: 24px;
  padding: 12px 10px 0;
}

.document-footer {
  padding-top: 16px;
  color: var(--muted);
  font-size: 11px;
}

.print-body {
  background: #fff;
}

.print-document {
  width: 190mm;
  margin: 10mm auto;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
}

#statusBadge {
  padding: 4px 8px;
  border-radius: 999px;
  background: #e7f6ef;
  color: #176c4f;
  font-size: 12px;
  font-weight: 700;
}

#toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #15202b;
  color: #fff;
  opacity: 0;
  transform: translateY(8px);
  transition: 160ms ease;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 860px) {
  .topbar, .userbox, .shell, .grid-form, .details-grid, .recebimento-row, .item-row, .document-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .panel.full {
    grid-column: auto;
  }

  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sidebar-footer { margin-top: 8px; }
  .app-header, .header-actions { align-items: stretch; flex-direction: column; }
  .metrics, .two-columns { grid-template-columns: 1fr; }
  .users-layout, .user-item, .inventory-layout, .inline-fields, .finance-layout, .three-columns, .search-form { grid-template-columns: 1fr; }
  .module-tabs { overflow-x: auto; }
  .module-tabs button { flex: 0 0 auto; }
}

@media print {
  @page { size: A4; margin: 12mm; }
  .print-document { width: auto; margin: 0; }
  .document-section { break-inside: avoid; }
}

.auth-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.login-panel h2 { font-size: 20px; }
#authMessage, #accountMessage { overflow-wrap: anywhere; }
#accountDialog { width: min(480px, calc(100% - 32px)); max-height: 90dvh; overflow: auto; }
