:root {
  --bg: #f5f7f4;
  --surface: #fff;
  --surface-strong: #ecf3ef;
  --text: #17231e;
  --muted: #657269;
  --line: #d9e2dc;
  --accent: #1e7561;
  --accent-dark: #155447;
  --warn: #a96912;
  --danger: #b33d55;
  --shadow: 0 16px 38px rgba(21, 84, 71, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

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

.hidden {
  display: none !important;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #155447, #1e7561);
}

.login-card {
  width: min(440px, 100%);
  display: grid;
  gap: 14px;
  background: var(--surface);
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.24);
}

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

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

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

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

.brand span,
.hint,
.form-message {
  color: var(--muted);
  line-height: 1.45;
}

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

.sidebar {
  background: #17231e;
  color: #eef5f1;
  padding: 22px 16px;
}

.sidebar .brand span {
  color: #bac8c0;
}

nav {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

.nav-item {
  width: 100%;
  border: 0;
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 9px;
  align-items: center;
  text-align: left;
  min-height: 44px;
  border-radius: 8px;
  padding: 8px 10px;
  background: transparent;
  color: #dce7e1;
  cursor: pointer;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.nav-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.1);
}

.main {
  padding: 24px;
  min-width: 0;
}

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

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

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

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

h1 {
  margin-bottom: 0;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  min-height: 42px;
  min-width: min(420px, 70vw);
}

.search input {
  border: 0;
  outline: 0;
}

.primary-button,
.ghost-button,
.icon-button,
.small-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  min-height: 42px;
  padding: 0 15px;
  color: #fff;
  background: var(--accent);
}

.ghost-button,
.small-button {
  min-height: 34px;
  padding: 0 12px;
  background: var(--surface-strong);
  color: var(--text);
}

.icon-button {
  width: 36px;
  height: 36px;
  background: var(--surface-strong);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

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

.metric {
  padding: 14px;
}

.metric strong {
  display: block;
  font-size: 1.6rem;
  margin-top: 6px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
}

.panel {
  padding: 18px;
}

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

.record-list {
  display: grid;
  gap: 10px;
}

.record-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.record-row p {
  color: var(--muted);
  margin-bottom: 0;
}

.relations {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.relations span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--surface-strong);
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 700;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-weight: 800;
  font-size: 0.82rem;
  background: #e7f4ee;
  color: var(--accent-dark);
}

.badge.warn {
  background: #fff0d6;
  color: var(--warn);
}

.badge.danger {
  background: #f8e2e8;
  color: var(--danger);
}

.alerts {
  display: grid;
  gap: 10px;
}

.alert {
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.alert p {
  color: var(--muted);
  margin: 3px 0 0;
}

dialog {
  width: min(560px, calc(100vw - 32px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.25);
}

dialog::backdrop {
  background: rgba(23, 35, 30, 0.45);
}

.modal {
  display: grid;
  gap: 12px;
  padding: 18px;
}

label,
.dynamic-fields {
  display: grid;
  gap: 6px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

textarea {
  min-height: 100px;
  resize: vertical;
}

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

.quick-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.subtabs {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.subtab-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.subtab {
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.subtab.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #ffffff;
}

.risk-map-builder {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfa;
  margin-bottom: 14px;
}

.risk-map-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.risk-map-stage {
  position: relative;
  width: 100%;
  min-height: 320px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
  cursor: crosshair;
}

.risk-map-stage img {
  display: block;
  width: 100%;
  height: auto;
}

.risk-map-empty {
  display: grid;
  min-height: 320px;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.risk-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  border: 2px solid #111827;
  border-radius: 999px;
  color: #111827;
  font-weight: 900;
  cursor: default;
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.18);
  opacity: 0.86;
}

.risk-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 12px 0;
  color: var(--muted);
  font-weight: 700;
}

.risk-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.risk-legend i {
  width: 14px;
  height: 14px;
  border: 1px solid #111827;
  border-radius: 999px;
}

.certificate-note {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfa;
  margin-bottom: 14px;
}

.certificate-note p {
  color: var(--muted);
  margin: 8px 0 0;
}

.esocial-config-form,
.doctor-form,
.settings-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfa;
  margin-bottom: 14px;
}

.esocial-config-form .panel-header,
.esocial-config-form .quick-actions,
.esocial-config-form .form-message,
.doctor-form .panel-header,
.doctor-form .quick-actions,
.doctor-form .form-message,
.doctor-form .full-line,
.settings-form .panel-header,
.settings-form .quick-actions,
.settings-form .form-message,
.settings-form .full-line {
  grid-column: 1 / -1;
}

.logo-preview {
  display: grid;
  min-height: 112px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  padding: 12px;
}

.logo-preview img {
  max-width: 220px;
  max-height: 86px;
  object-fit: contain;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-line input {
  width: auto;
}

.inline-panel {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.exam-row,
.s2240-row,
.s2240-subrow {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr)) auto;
  gap: 8px;
  align-items: center;
}

.s2240-agent {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
}

.s2240-subrow {
  grid-template-columns: minmax(180px, 1fr) auto;
  margin-top: 8px;
}

.document-grid {
  display: grid;
  gap: 8px;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
  }

  nav {
    grid-auto-flow: column;
    overflow-x: auto;
  }

  .nav-item {
    width: 220px;
  }

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

@media (max-width: 720px) {
  .topbar,
  .record-row {
    display: grid;
  }

  .search,
  .topbar-actions,
  .primary-button {
    width: 100%;
    min-width: 0;
  }

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

  .esocial-config-form,
  .doctor-form,
  .settings-form,
  .exam-row,
  .s2240-row,
  .s2240-subrow,
  .risk-map-controls {
    grid-template-columns: 1fr;
  }
}
