:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-muted: #f1f0fb;
  --text: #17182f;
  --muted: #66677e;
  --line: #dfdfeb;
  --brand: #2f3187;
  --brand-strong: #23256c;
  --accent: #ff8316;
  --accent-soft: #fff0e2;
  --danger: #b42334;
  --success: #27835c;
  --warning: #a96500;
  --shadow: 0 18px 45px rgba(35, 37, 108, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  background: linear-gradient(135deg, rgba(255, 131, 22, 0.1), transparent 28rem), var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

body:not(.is-authenticated) .app-shell {
  display: none;
}

body.is-authenticated .login-screen {
  display: none;
}

.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  display: grid;
  gap: 1rem;
  width: min(100%, 26rem);
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  padding: 1.4rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card img {
  border-radius: 0.6rem;
  object-fit: contain;
}

.login-card p {
  color: var(--muted);
  margin-bottom: 0;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-height: 100vh;
  padding: 1.25rem;
  background: var(--brand);
  color: #ffffff;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand img {
  border-radius: 0.55rem;
  background: #ffffff;
  object-fit: contain;
}

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

.brand strong {
  font-size: 1.1rem;
}

.brand span {
  color: #e7e6ff;
  font-size: 0.9rem;
}

.app-nav {
  display: grid;
  gap: 0.4rem;
}

.nav-button {
  border: 0;
  border-radius: 0.5rem;
  padding: 0.82rem 0.9rem;
  background: transparent;
  color: #ffffff;
  font-weight: 800;
  text-align: left;
}

.nav-button:hover,
.nav-button.is-active {
  background: rgba(255, 255, 255, 0.14);
}

.status-panel {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.5rem;
  padding: 0.9rem;
  background: rgba(255, 255, 255, 0.1);
}

.status-panel strong,
.status-panel span {
  display: block;
}

.status-panel span {
  color: #eeedff;
  font-size: 0.88rem;
  line-height: 1.35;
}

.status-dot {
  width: 0.72rem;
  height: 0.72rem;
  margin-top: 0.28rem;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 131, 22, 0.2);
  flex: 0 0 auto;
}

body.is-online .status-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(39, 131, 92, 0.18);
}

body.is-offline .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(180, 35, 52, 0.18);
}

.content {
  width: min(100%, 68rem);
  margin: 0 auto;
  padding: 1.25rem 1.25rem 4rem;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0 1.15rem;
  background: linear-gradient(180deg, var(--bg) 76%, rgba(247, 246, 242, 0));
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.session-line {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.topbar > div,
.panel-heading > div {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 0.18rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 5vw, 2.65rem);
  line-height: 1.05;
  overflow-wrap: anywhere;
}

h2 {
  margin-bottom: 0.25rem;
  font-size: 1.35rem;
}

h3 {
  margin-bottom: 1rem;
  color: var(--brand);
  font-size: 1.04rem;
}

.panel {
  display: none;
}

.panel.is-active {
  display: block;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

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

.number-preview,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  background: var(--accent-soft);
  color: #8b4300;
  font-size: 0.86rem;
  font-weight: 900;
  white-space: nowrap;
}

.os-form,
.cards-grid {
  display: grid;
  gap: 1rem;
}

.form-section,
.help-box,
.os-card,
.table-wrap {
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.form-section,
.help-box,
.os-card {
  padding: 1.15rem;
}

label,
fieldset {
  display: grid;
  gap: 0.45rem;
  margin: 0 0 1rem;
  color: #28294d;
  font-size: 0.94rem;
  font-weight: 800;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.9rem;
}

legend {
  padding: 0 0.35rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfcfe1;
  border-radius: 0.45rem;
  padding: 0.78rem 0.82rem;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(47, 49, 135, 0.13);
}

.field-grid,
.lookup-bar,
.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.lookup-bar {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  margin-bottom: 1rem;
}

.metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 1rem;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.9rem;
  background: #ffffff;
}

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

.metric span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.radio-row,
.check-row {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin-bottom: 0.65rem;
  font-weight: 650;
}

.radio-row input,
.check-row input {
  width: 1.1rem;
  height: 1.1rem;
  margin-top: 0.15rem;
  flex: 0 0 auto;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1rem;
}

.actions.left {
  justify-content: flex-start;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.install-button {
  border: 0;
  border-radius: 0.45rem;
  font-weight: 900;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 2.75rem;
  padding: 0 1rem;
}

.primary-button {
  background: var(--brand);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--brand-strong);
}

.secondary-button {
  background: var(--surface-muted);
  color: var(--brand-strong);
}

.compact {
  min-height: 2.4rem;
  padding: 0 0.75rem;
}

.admin-users {
  margin-top: 1rem;
}

.user-form {
  display: grid;
  gap: 0.8rem;
}

.compact-list {
  margin-top: 1rem;
}

.danger-button {
  background: #ffe7ea;
  color: var(--danger);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  background: var(--brand);
  color: #ffffff;
}

.install-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.75rem;
  padding: 0 0.85rem;
  background: var(--accent);
  color: #ffffff;
  white-space: nowrap;
}

.install-button:hover {
  background: #e56f08;
}

.icon-button svg,
.install-button svg {
  width: 1.35rem;
  height: 1.35rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.install-button svg {
  width: 1.1rem;
  height: 1.1rem;
}

.os-card {
  display: grid;
  gap: 0.7rem;
}

.os-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.7rem;
}

.os-card h3 {
  margin: 0;
}

.os-card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin: 0;
}

.os-card dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.os-card dd {
  margin: 0.1rem 0 0;
  overflow-wrap: anywhere;
}

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

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

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

th {
  background: #f5f4fc;
  color: var(--brand);
  font-size: 0.8rem;
  text-transform: uppercase;
}

td .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.small-button {
  border: 1px solid var(--line);
  border-radius: 0.42rem;
  padding: 0.45rem 0.6rem;
  background: #ffffff;
  color: var(--brand);
  font-weight: 900;
}

.status-aberta,
.status-pendente,
.status-em-andamento,
.status-finalizada,
.status-reprovada,
.status-vencida {
  display: inline-flex;
  border-radius: 999px;
  padding: 0.24rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 900;
}

.status-aberta,
.status-pendente {
  background: var(--accent-soft);
  color: #8b4300;
}

.status-em-andamento {
  background: #e9e9ff;
  color: var(--brand);
}

.status-finalizada {
  background: #e5f6ee;
  color: var(--success);
}

.status-reprovada,
.status-vencida {
  background: #ffe7ea;
  color: var(--danger);
}

.help-box p {
  margin-bottom: 0;
  color: var(--muted);
}

code {
  border-radius: 0.35rem;
  padding: 0.1rem 0.28rem;
  background: #f1f0fb;
}

dialog {
  width: min(43rem, calc(100vw - 2rem));
  border: 0;
  border-radius: 0.55rem;
  padding: 0;
  box-shadow: 0 25px 70px rgba(23, 24, 47, 0.28);
}

dialog::backdrop {
  background: rgba(23, 24, 47, 0.45);
}

dialog article {
  position: relative;
  padding: 1.25rem;
}

.details-list {
  display: grid;
  grid-template-columns: 10rem minmax(0, 1fr);
  gap: 0.55rem 0.9rem;
  margin: 0;
}

.details-list dt {
  color: var(--brand);
  font-weight: 900;
}

.details-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.install-help {
  display: grid;
  gap: 1rem;
}

.install-help section {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.9rem;
  background: #fff;
}

.install-help h3 {
  margin-bottom: 0.35rem;
}

.install-help p {
  margin-bottom: 0;
  color: var(--muted);
}

.dialog-close {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 999px;
  background: #f1f0fb;
  color: var(--brand);
  font-size: 1.25rem;
  font-weight: 900;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: min(24rem, calc(100vw - 2rem));
  border-radius: 0.5rem;
  padding: 0.9rem 1rem;
  background: var(--brand);
  color: #ffffff;
  box-shadow: var(--shadow);
  z-index: 30;
}

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

  .sidebar {
    position: static;
    min-height: auto;
  }

  .app-nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 0.2rem;
  }

  .app-nav .nav-button {
    flex: 0 0 auto;
  }

  .status-panel {
    margin-top: 0;
  }

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

@media (max-width: 650px) {
  .content {
    width: 100vw;
    max-width: 100vw;
    padding: 0.75rem 0.75rem 2rem;
    overflow: hidden;
  }

  h1 {
    font-size: 2rem;
    max-width: calc(100vw - 5.25rem);
  }

  .install-button span {
    display: none;
  }

  .panel-heading,
  .field-grid,
  .lookup-bar,
  .os-card dl,
  .details-list {
    grid-template-columns: 1fr;
  }

  .panel-heading,
  .lookup-bar {
    display: grid;
  }

  .actions {
    display: grid;
    justify-content: stretch;
  }
}
