:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, Helvetica, sans-serif;
  background: #eef2f6;
  color: #172033;
  --ink: #172033;
  --muted: #667085;
  --soft: #98a2b3;
  --line: #d9e1ec;
  --panel: #ffffff;
  --panel-soft: #f7f9fc;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #e6f4f1;
  --danger: #cf3f3f;
  --warning: #c27a14;
  --shadow: 0 18px 45px rgba(29, 41, 57, .10);
  --shadow-sm: 0 8px 22px rgba(29, 41, 57, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #f8fafc 0, #eef2f6 240px, #e9eef5 100%);
}

button, textarea, input {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  width: min(1360px, 100%);
  margin: 0 auto;
  padding: 18px 28px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  color: #0f766e;
  font-weight: 800;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.brand-name {
  color: var(--ink);
  font-size: 23px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  transform: translateX(-3px);
}

.brand-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

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

.sidebar-visibility-toggle {
  min-height: 38px;
  border: 1px solid rgba(37, 99, 235, .32);
  border-radius: 999px;
  background: #eef4ff;
  color: #1d4ed8;
  box-shadow: 0 7px 16px rgba(37, 99, 235, .10);
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 800;
}

.sidebar-visibility-toggle:hover {
  border-color: rgba(37, 99, 235, .52);
  background: #dbeafe;
}

.app {
  width: min(1360px, 100%);
  margin: 0 auto;
  padding: 22px 28px 34px;
  display: grid;
  grid-template-columns: 230px 230px 210px minmax(0, 1fr);
  gap: 18px;
}

.app.scores-open {
  width: min(1560px, 100%);
  grid-template-columns: 210px 210px 190px minmax(300px, 360px) minmax(0, 1fr);
}

.app.atestadite-hidden {
  grid-template-columns: 250px 250px minmax(0, 1fr);
}

.app.scores-open.atestadite-hidden {
  grid-template-columns: 230px 230px minmax(300px, 360px) minmax(0, 1fr);
}

.hidden {
  display: none !important;
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 18px;
  max-height: calc(100vh - 36px);
  overflow: hidden;
  border: 1px solid rgba(217, 225, 236, .95);
  border-radius: 18px;
  background: rgba(255, 255, 255, .88);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(14px);
}

.sidebar-quick {
  border-left: 6px solid var(--accent);
}

.sidebar-recipes {
  border-left: 6px solid #7a8798;
}

.sidebar-atestadite {
  border-left: 6px solid #c05621;
}

.sidebar-scores {
  border-left: 6px solid #0ea5a0;
}

.sidebar-head {
  padding: 16px 16px 4px;
}

.sidebar-title {
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  white-space: nowrap;
}

textarea:focus {
  border-color: rgba(15, 118, 110, .65);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, .12);
}

.list {
  max-height: calc(100vh - 156px);
  overflow: auto;
  padding: 0 10px 14px;
}

.list::-webkit-scrollbar {
  width: 8px;
}

.list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #cbd5e1;
}

.score-sidebar-content {
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 10px;
}

.score-sidebar-content::-webkit-scrollbar {
  width: 8px;
}

.score-sidebar-content::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #cbd5e1;
}

.nav-group {
  margin: 0;
}

.nav-group > summary {
  list-style: none;
}

.nav-group > summary::-webkit-details-marker {
  display: none;
}

.group-toggle {
  width: calc(100% - 4px);
  margin: 6px 2px 4px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #667085;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 8px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-align: left;
}

.group-toggle:hover {
  background: #f3f6fa;
  color: var(--ink);
}

.chevron {
  color: #98a2b3;
  font-size: 12px;
  transition: transform .16s ease;
}

.group-toggle.collapsed .chevron {
  transform: rotate(-90deg);
}

.nav-group:not([open]) .chevron {
  transform: rotate(-90deg);
}

.rest-title {
  margin-top: 10px;
}

.nav-section.collapsed {
  display: none;
}

.nav-btn {
  display: block;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: #344054;
  text-align: left;
  padding: 6px 9px;
  margin: 1px 0;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}

.nav-btn:hover {
  background: #f3f6fa;
  color: var(--ink);
}

.nav-btn.active {
  background: var(--accent-soft);
  border-color: rgba(15, 118, 110, .22);
  color: var(--accent-strong);
  box-shadow: inset 3px 0 0 var(--accent);
}

.nav-title {
  display: block;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.15;
}

.nav-meta {
  display: none;
  margin-top: 2px;
  color: #7a8798;
  font-size: 11px;
  line-height: 1.25;
}

.nav-btn.active .nav-meta {
  display: block;
}

.content {
  min-width: 0;
}

.card {
  background: var(--panel);
  border: 1px solid rgba(217, 225, 236, .95);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.header {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  gap: 18px;
  padding: 18px 22px;
  border-bottom: 1px solid #edf1f6;
  background: linear-gradient(180deg, #ffffff 0, #fbfcfe 100%);
}

.header-left {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 2px;
}

.header h1 {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
  line-height: 1.15;
  font-weight: 850;
}

.header p {
  display: inline-flex;
  margin: 8px 0 0;
  border: 1px solid #d9e6e3;
  border-radius: 999px;
  background: #f2fbf8;
  color: var(--accent-strong);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
}

.section {
  padding: 12px 20px;
  border-bottom: 1px solid #edf1f6;
  background: #fff;
}

.body {
  padding: 18px 20px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px 10px;
  align-items: center;
}

.stack {
  display: grid;
  gap: 12px;
}

.mini-title {
  margin-bottom: 8px;
  color: #667085;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .08em;
}

.text-btn {
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: #475467;
  padding: 8px 11px;
  font-size: 13px;
  font-weight: 750;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}

.text-btn:hover {
  background: #f3f6fa;
  color: var(--ink);
}

.text-btn.active {
  background: var(--accent-soft);
  border-color: rgba(15, 118, 110, .22);
  color: var(--accent-strong);
}

.primary-btn {
  border-color: rgba(15, 118, 110, .25);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 12px 24px rgba(15, 118, 110, .22);
}

.primary-btn:hover,
.primary-btn.active {
  background: var(--accent-strong);
  color: #fff;
}

.lab-source-btn {
  border-color: rgba(15, 118, 110, .18);
  background: linear-gradient(180deg, #ffffff 0%, #f1fbf8 100%);
  color: #0f766e;
  box-shadow: 0 8px 18px rgba(15, 118, 110, .10);
}

.lab-source-btn:hover {
  border-color: rgba(15, 118, 110, .30);
  background: #e8f7f3;
  color: #0b5f59;
  transform: translateY(-1px);
}

.lab-source-btn.active {
  border-color: rgba(15, 118, 110, .34);
  background: #0f766e;
  color: #fff;
  box-shadow: 0 10px 22px rgba(15, 118, 110, .18);
}

.manual-source-hidden {
  display: none;
}

.auto-btn {
  border-color: rgba(124, 58, 237, .20);
  background: linear-gradient(180deg, #ffffff 0%, #f5f3ff 100%);
  color: #6d28d9;
  box-shadow: 0 8px 18px rgba(124, 58, 237, .10);
}

.auto-btn:hover {
  border-color: rgba(124, 58, 237, .34);
  background: #ede9fe;
  color: #5b21b6;
}

.auto-btn.active {
  border-color: rgba(109, 40, 217, .38);
  background: #6d28d9;
  color: #fff;
  box-shadow: 0 10px 22px rgba(124, 58, 237, .18);
}

.jundiai-btn {
  border-color: rgba(59, 130, 246, .20);
  background: linear-gradient(180deg, #ffffff 0%, #eff6ff 100%);
  color: #1d4ed8;
  box-shadow: 0 8px 18px rgba(59, 130, 246, .10);
}

.jundiai-btn:hover {
  border-color: rgba(59, 130, 246, .34);
  background: #dbeafe;
  color: #1e40af;
}

.jundiai-btn.active {
  border-color: rgba(29, 78, 216, .38);
  background: #1d4ed8;
  color: #fff;
  box-shadow: 0 10px 22px rgba(59, 130, 246, .18);
}

.ghost-btn {
  border-color: #d9e1ec;
  background: #fff;
}

.ghost-btn.active {
  border-color: rgba(194, 122, 20, .28);
  background: #fff7ed;
  color: #9a5a0a;
}

.dot-btn {
  border: 1px solid #d9e1ec;
  border-radius: 999px;
  background: #fff;
  color: #344054;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease, box-shadow .15s ease;
}

.dot-btn:hover {
  border-color: #b7c3d3;
  background: #f8fafc;
  color: var(--ink);
  transform: translateY(-1px);
}

.dot-btn.active {
  border-color: rgba(15, 118, 110, .28);
  background: var(--accent-soft);
  color: var(--accent-strong);
  box-shadow: 0 8px 18px rgba(15, 118, 110, .10);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #64748b;
  flex: 0 0 auto;
}

.panel {
  border: 1px solid #dce4ef;
  border-radius: 12px;
  background: var(--panel-soft);
  padding: 14px;
}

.panel .panel {
  background: #fff;
}

.panel-title {
  margin-bottom: 8px;
  color: #344054;
  font-size: 13px;
  font-weight: 850;
  letter-spacing: .01em;
}

.panel-hint {
  color: #667085;
  font-size: 12px;
  line-height: 1.45;
}

.reavaliacao-lab-panel {
  margin-bottom: 14px;
  background: linear-gradient(180deg, #fbfefd 0%, #f4faf8 100%);
}

.reavaliacao-panel-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
}

.lab-source-row {
  justify-content: flex-end;
}

.lab-input {
  min-height: 190px;
}

.lab-preview {
  border: 1px solid #dce4ef;
  border-radius: 12px;
  background: #fff;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.lab-detected-source {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 32px;
  border-radius: 999px;
  padding: 7px 11px;
  background: #f5f3ff;
  color: #6d28d9;
  font-size: 12px;
  font-weight: 900;
}

.lab-output {
  margin: 0;
  white-space: pre-wrap;
  color: #101828;
}

.template-title {
  margin: 10px 0 8px;
}

textarea.template-editor {
  min-height: 420px;
}

textarea.anamnese-editor {
  min-height: 680px;
}

.atestadite-block {
  background: #fff;
}

.atestadite-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.atestadite-block-head .panel-title {
  margin-bottom: 0;
}

textarea.atestadite-editor {
  min-height: 190px;
}

textarea.atestadite-anamnese-editor {
  min-height: 360px;
}

.safety-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border: 1px solid #d9e1ec;
  border-radius: 14px;
  background: #fff;
  padding: 12px;
}

.safety-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 6px 10px;
  background: #f2f4f7;
  color: #475467;
  font-size: 12px;
  font-weight: 800;
}

.safety-chip.warn {
  background: #fff7ed;
  color: #9a5a0a;
}

.safety-chip.danger {
  background: #fef3f2;
  color: #b42318;
}

.safety-chip.ok {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.empty-note {
  color: #98a2b3;
  font-size: 12px;
  padding: 8px 10px 12px;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
  color: #243147;
  font-size: 14px;
  line-height: 1.55;
}

textarea {
  width: 100%;
  min-height: 500px;
  resize: vertical;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #fff;
  color: #243147;
  padding: 14px;
  outline: none;
  line-height: 1.5;
  box-shadow: inset 0 1px 0 rgba(16, 24, 40, .03);
}

textarea.small {
  min-height: 160px;
  border-radius: 14px;
  padding: 14px;
}

select,
input[type="number"] {
  width: 100%;
  min-height: 36px;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  background: #fff;
  color: #243147;
  padding: 7px 9px;
  outline: none;
}

select:focus,
input[type="number"]:focus {
  border-color: rgba(15, 118, 110, .65);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, .12);
}

.score-panel {
  background: #fbfcfe;
}

.score-sidebar-content .score-panel {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 6px;
}

.score-sidebar-content .score-tabs {
  gap: 6px;
}

.score-sidebar-content .score-tabs .text-btn {
  padding: 7px 9px;
  font-size: 12px;
}

.score-sidebar-content .score-box {
  padding: 10px;
}

.score-sidebar-content .score-box-head {
  grid-template-columns: 1fr;
  gap: 6px;
  align-items: start;
}

.score-sidebar-content .score-grid {
  grid-template-columns: 1fr;
}

.score-sidebar-content .score-summary {
  max-width: none;
  width: 100%;
  white-space: normal;
  line-height: 1.25;
}

.score-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.score-box {
  display: grid;
  gap: 10px;
  border: 1px solid #e3eaf3;
  border-radius: 10px;
  background: #fff;
  padding: 12px;
}

.score-box.open {
  border-color: rgba(15, 118, 110, .32);
  box-shadow: 0 10px 22px rgba(15, 118, 110, .08);
}

.score-box-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.score-toggle {
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #172033;
  font-size: 13px;
  font-weight: 850;
  text-align: left;
  padding: 6px 8px;
  line-height: 1.25;
  white-space: normal;
}

.score-toggle:hover {
  background: #f3f6fa;
  color: var(--accent-strong);
}

.score-summary {
  max-width: 280px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-title {
  color: #172033;
  font-size: 13px;
  font-weight: 850;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.score-field {
  display: grid;
  gap: 5px;
}

.score-field label {
  color: #667085;
  font-size: 11px;
  font-weight: 800;
}

.score-result {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  padding: 9px 10px;
  font-size: 13px;
  font-weight: 800;
}

.score-conduct {
  border: 1px solid #d9e1ec;
  border-left: 3px solid #7a8798;
  border-radius: 10px;
  background: #f8fafc;
  color: #344054;
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.45;
  font-weight: 700;
}

.success {
  border: 1px solid #a7f3d0;
  background: #ecfdf5;
  color: #047857;
  border-radius: 14px;
  padding: 11px 13px;
  font-size: 14px;
  font-weight: 700;
}

.toggle-block {
  display: grid;
  gap: 9px;
  justify-items: start;
}

.free-groups {
  border: 1px solid #e3eaf3;
  border-radius: 12px;
  background: #fbfcfe;
  padding: 12px;
}

.free-topic-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.free-topic-btn {
  min-height: 34px;
  border-color: #d9e1ec;
  border-radius: 9px;
  background: #fff;
  color: #344054;
  padding: 7px 12px;
  font-size: 12px;
  box-shadow: 0 6px 14px rgba(29, 41, 57, .06);
}

.free-topic-btn:hover {
  border-color: rgba(15, 118, 110, .24);
  background: #f1fbf8;
  color: var(--accent-strong);
  transform: translateY(-1px);
}

.free-topic-btn.active {
  border-color: rgba(15, 118, 110, .28);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 22px rgba(15, 118, 110, .18);
}

.free-topic-content {
  padding-top: 4px;
}

.free-groups .row {
  justify-content: flex-start;
}

.free-groups .text-btn {
  align-self: start;
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    padding: 16px 16px 0;
  }

  .topbar-actions {
    align-self: stretch;
    flex-wrap: wrap;
  }

  .sidebar-visibility-toggle {
    flex: 1 1 auto;
  }

  .app {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .app.scores-open,
  .app.atestadite-hidden,
  .app.scores-open.atestadite-hidden {
    width: min(1360px, 100%);
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
  }

  .list {
    max-height: 360px;
  }

  .score-sidebar-content {
    max-height: 460px;
  }

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

  .header .text-btn,
  .header-actions {
    align-self: flex-start;
  }

  .free-topic-row {
    gap: 7px;
  }

  .reavaliacao-panel-head {
    grid-template-columns: 1fr;
  }

  .lab-source-row {
    justify-content: flex-start;
  }

  .score-box-head {
    grid-template-columns: 1fr;
  }

  .score-summary {
    max-width: none;
    width: fit-content;
  }
}

@media (max-width: 620px) {
  .topbar {
    flex-direction: column;
  }

  .header,
  .section,
  .body {
    padding-left: 18px;
    padding-right: 18px;
  }

  .free-topic-row {
    gap: 7px;
  }

  .free-topic-btn {
    min-height: 32px;
    padding: 6px 10px;
  }
}
