:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --sidebar: #1f2a2e;
  --sidebar-muted: #aeb9ba;
  --surface: #ffffff;
  --ink: #20292d;
  --muted: #657174;
  --line: #dce3df;
  --active: #2d765a;
  --active-soft: #e7f1eb;
  --focus: #245e89;
  --danger: #9f352f;
}

* {
  box-sizing: border-box;
}

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

button,
table {
  font: inherit;
}

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

.app-shell.sidebar-collapsed {
  grid-template-columns: 74px minmax(0, 1fr);
}

.sidebar {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  gap: 14px;
  border-right: 1px solid #162024;
  background: var(--sidebar);
  color: #ffffff;
  padding: 22px 16px;
}

.collapse-button {
  display: grid;
  width: 42px;
  min-height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.09);
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
}

.collapse-button:hover,
.collapse-button:focus-visible {
  border-color: #ffffff;
}

.brand {
  display: grid;
  gap: 4px;
  padding: 2px 4px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand span {
  color: var(--sidebar-muted);
  font-size: 12px;
  text-transform: uppercase;
}

.brand strong {
  font-size: 19px;
  letter-spacing: 0;
}

.navigation,
.submenu {
  display: grid;
  gap: 6px;
}

.nav-icon {
  display: inline-grid;
  width: 28px;
  min-width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.nav-toggle,
.base-button,
.analysis-button {
  width: 100%;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}

.nav-toggle {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.09);
  color: #ffffff;
  padding: 10px 12px;
  font-weight: 700;
}

.nav-toggle:focus-visible,
.base-button:focus-visible,
.analysis-button:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.submenu[hidden] {
  display: none;
}

.base-button {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  background: transparent;
  color: var(--sidebar-muted);
  padding: 7px 12px 7px 22px;
}

.base-button.child {
  min-height: 34px;
  margin-left: 16px;
  width: calc(100% - 16px);
  border-left: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 0 6px 6px 0;
  padding-left: 18px;
}

.base-button:hover,
.base-button.active {
  background: var(--active-soft);
  color: var(--sidebar);
}

.analysis-button {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  margin-top: 8px;
  background: transparent;
  color: var(--sidebar-muted);
  padding: 10px 12px;
  font-weight: 700;
}

.analysis-button:hover,
.analysis-button.active {
  background: var(--active-soft);
  color: var(--sidebar);
}

.base-button:hover .nav-icon,
.base-button.active .nav-icon,
.analysis-button:hover .nav-icon,
.analysis-button.active .nav-icon {
  background: var(--sidebar);
  color: #ffffff;
}

.nav-toggle #database-toggle-icon {
  margin-left: auto;
}

.sidebar-collapsed .sidebar {
  align-items: center;
  padding: 18px 10px;
}

.sidebar-collapsed .brand {
  width: 100%;
  min-height: 1px;
  padding: 0 0 10px;
}

.sidebar-collapsed .nav-label,
.sidebar-collapsed #database-toggle-icon {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.sidebar-collapsed .navigation,
.sidebar-collapsed .submenu {
  width: 100%;
  justify-items: center;
}

.sidebar-collapsed .nav-toggle,
.sidebar-collapsed .base-button,
.sidebar-collapsed .analysis-button {
  width: 42px;
  justify-content: center;
  padding: 7px;
}

.sidebar-collapsed .base-button.child {
  margin-left: 0;
  width: 42px;
  border-left: 0;
  border-radius: 6px;
  padding-left: 7px;
}

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

.content-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.section-label {
  margin: 0 0 6px;
  color: var(--active);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.12;
}

.origin-line {
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  padding: 7px 10px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.origin-line strong {
  color: var(--focus);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  padding: 12px;
}

.auth-form {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.auth-form input,
.field-row input,
.field-row select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 7px 9px;
}

.auth-form input {
  width: 190px;
}

.app-message {
  color: var(--focus);
  font-weight: 700;
}

.base-meta {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
  color: var(--muted);
  line-height: 1.42;
}

.records-area {
  min-width: 0;
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

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

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

.actions-cell {
  min-width: 210px;
  white-space: nowrap;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.row-action,
.icon-action,
.plain-button,
.primary-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 6px 10px;
}

.icon-action {
  display: inline-grid;
  width: 34px;
  min-width: 34px;
  padding: 0;
  place-items: center;
  line-height: 1;
}

.pdf-action {
  border-color: #c8d7e1;
  color: var(--focus);
  font-size: 10px;
  font-weight: 800;
}

.row-action:hover,
.icon-action:hover,
.plain-button:hover {
  border-color: var(--focus);
  color: var(--focus);
}

.pdf-action:hover {
  border-color: var(--focus);
  background: var(--focus);
  color: #ffffff;
}

.danger-action {
  border-color: #e8cbc8;
  color: var(--danger);
}

.danger-action:hover {
  border-color: var(--danger);
  background: var(--danger);
  color: #ffffff;
}

.primary-button {
  border-color: var(--active);
  background: var(--active);
  color: #ffffff;
  font-weight: 700;
}

.primary-button:hover {
  border-color: #235f49;
  background: #235f49;
}

.primary-button[hidden],
.plain-button[hidden],
.auth-form input[hidden] {
  display: none;
}

.read-only-badge {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f3f6f4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  white-space: nowrap;
}

.tree-cell {
  display: flex;
  min-width: 220px;
  align-items: flex-start;
  gap: 8px;
  padding-left: calc(var(--depth, 0) * 28px);
}

.tree-cell-root,
.tree-cell-item {
  padding-left: 0;
}

.tree-cell-subitem {
  color: #40545a;
}

.tree-node {
  display: flex;
  min-width: 260px;
  align-items: flex-start;
  gap: 8px;
  color: inherit;
  font: inherit;
  text-align: left;
}

.tree-node-toggle {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.tree-node-toggle:hover .tree-label {
  color: var(--focus);
}

.tree-node-toggle:focus-visible {
  border-radius: 6px;
  outline: 2px solid rgba(36, 94, 137, 0.22);
  outline-offset: 3px;
}

.tree-node-static {
  cursor: default;
}

.tree-chevron {
  position: relative;
  width: 20px;
  min-width: 20px;
  height: 20px;
  margin-top: 0;
  border: 1px solid #d8e4de;
  border-radius: 5px;
  background: #ffffff;
}

.tree-chevron::before {
  position: absolute;
  top: 5px;
  left: 6px;
  width: 6px;
  height: 6px;
  border-right: 2px solid #4f645e;
  border-bottom: 2px solid #4f645e;
  content: "";
  transform: rotate(-45deg);
}

.tree-node-toggle[aria-expanded="true"] .tree-chevron::before {
  top: 4px;
  transform: rotate(45deg);
}

.tree-chevron-empty {
  border-color: transparent;
  background: transparent;
}

.tree-chevron-empty::before {
  display: none;
}

.cronograma-tree-row-cronograma {
  background: #f7faf8;
}

.cronograma-tree-row-cronograma td {
  border-bottom-color: #dbe8e1;
}

.cronograma-tree-row-item {
  background: #ffffff;
}

.cronograma-tree-row-subitem {
  background: #fbfcfb;
}

.cronograma-tree-row .tree-cell-item {
  padding-left: calc(var(--depth, 0) * 28px);
}

.cronograma-tree-row .tree-cell-item .tree-arrow,
.cronograma-tree-row .tree-cell-subitem .tree-arrow {
  display: inline-block;
}

.tree-content {
  display: grid;
  min-width: 220px;
  gap: 3px;
}

.tree-type-badge {
  width: max-content;
  border: 1px solid #d8e4de;
  border-radius: 5px;
  background: #f4f8f5;
  color: #4a625b;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  padding: 3px 6px;
  text-transform: uppercase;
}

.cronograma-tree-row-cronograma .tree-type-badge {
  border-color: #b9d3c7;
  background: #eaf4ee;
  color: var(--active);
}

.tree-arrow {
  position: relative;
  display: none;
  width: 18px;
  min-width: 18px;
  height: 18px;
  margin-top: 1px;
}

.tree-cell-subitem .tree-arrow {
  display: inline-block;
}

.tree-arrow::before {
  position: absolute;
  top: 1px;
  left: 3px;
  width: 8px;
  height: 10px;
  border-bottom: 2px solid #6e827c;
  border-left: 2px solid #6e827c;
  content: "";
}

.tree-arrow::after {
  position: absolute;
  top: 8px;
  left: 9px;
  width: 6px;
  height: 6px;
  border-right: 2px solid #6e827c;
  border-bottom: 2px solid #6e827c;
  content: "";
  transform: rotate(-45deg);
}

.tree-label {
  min-width: 220px;
}

.muted-cell {
  color: var(--muted);
}

.etapa-inline-cell {
  display: inline-flex;
  min-width: 120px;
  align-items: center;
  gap: 8px;
}

.item-add-button,
.subitem-add-button {
  width: 28px;
  min-width: 28px;
  min-height: 28px;
  border-color: #c9d8d0;
  background: #f4f8f5;
  color: var(--active);
  font-size: 18px;
  font-weight: 800;
}

.item-add-button:hover,
.subitem-add-button:hover {
  border-color: var(--active);
  background: var(--active);
  color: #ffffff;
}

.status-inline-select {
  min-width: 132px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 6px 28px 6px 8px;
  font: inherit;
}

.status-inline-select:focus {
  border-color: var(--focus);
  outline: 2px solid rgba(44, 93, 112, 0.18);
}

.status-inline-select:disabled {
  color: var(--muted);
  cursor: wait;
  opacity: 0.72;
}

.progress-cell {
  display: grid;
  min-width: 130px;
  grid-template-columns: minmax(78px, 1fr) 42px;
  align-items: center;
  gap: 8px;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e1e7e3;
}

.progress-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--active);
}

.progress-cell strong {
  color: var(--ink);
  font-size: 12px;
  text-align: right;
}

th {
  position: relative;
  background: #edf2ee;
  color: #334044;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.actions-header {
  min-width: 300px;
  padding-right: 58px;
}

.actions-header-content {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.table-search-input {
  width: min(220px, 100%);
  min-height: 40px;
  min-width: 120px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 9px 10px;
  font: inherit;
  font-size: 16px;
  text-transform: none;
}

.table-search-input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.table-add-button {
  position: absolute;
  top: 50%;
  right: 14px;
  display: grid;
  width: 34px;
  height: 34px;
  min-height: 34px;
  place-items: center;
  transform: translateY(-50%);
  border: 1px solid var(--active);
  border-radius: 50%;
  background: var(--active);
  color: #ffffff;
  cursor: pointer;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.table-add-button:hover,
.table-add-button:focus-visible {
  border-color: #235f49;
  background: #235f49;
}

.table-add-button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

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

tbody tr:hover {
  background: #f9fbf8;
}

.empty-state {
  margin-top: 12px;
  color: var(--muted);
}

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

.analysis-status {
  min-height: 118px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  padding: 14px;
}

.analysis-status span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.analysis-status strong {
  display: block;
  margin-bottom: 8px;
  color: var(--ink);
}

.analysis-status p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.side-panel {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 10;
  width: min(420px, 92vw);
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -18px 0 36px rgba(31, 42, 46, 0.16);
  transform: translateX(100%);
  transition: transform 180ms ease;
}

.side-panel.open {
  transform: translateX(0);
}

.side-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 18px;
}

.side-panel-header h2 {
  margin: 0;
  font-size: 21px;
}

.side-panel-body {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.client-form {
  display: grid;
  gap: 12px;
}

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

.field-row input,
.field-row select,
.field-row textarea {
  width: 100%;
}

.field-row textarea {
  min-height: 92px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 9px;
  font: inherit;
}

.checkbox-group {
  display: grid;
  gap: 8px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.checkbox-group legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 14px;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
}

.form-actions {
  flex-wrap: wrap;
  display: flex;
  gap: 8px;
}

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

.detail-row {
  display: grid;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.detail-row span,
.field-row label,
.mock-note {
  color: var(--muted);
  font-size: 12px;
}

.detail-row strong {
  font-weight: 400;
}

.attachment-list {
  display: grid;
  gap: 8px;
}

.attachment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.attachment-item div:first-child {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.attachment-item strong {
  overflow-wrap: anywhere;
  font-size: 13px;
}

.attachment-item span {
  color: var(--muted);
  font-size: 12px;
}

.attachment-preview {
  display: grid;
  gap: 8px;
}

.attachment-preview img,
.attachment-preview video,
.attachment-preview iframe {
  width: 100%;
  min-height: 280px;
  max-height: 58vh;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f6f8f6;
  object-fit: contain;
}

.attachment-preview iframe {
  height: 420px;
}

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

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }

  .sidebar-collapsed .sidebar {
    align-items: stretch;
  }

  .sidebar-collapsed .nav-label,
  .sidebar-collapsed #database-toggle-icon {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }

  .sidebar-collapsed .navigation,
  .sidebar-collapsed .submenu {
    justify-items: stretch;
  }

  .sidebar-collapsed .nav-toggle,
  .sidebar-collapsed .base-button,
  .sidebar-collapsed .analysis-button {
    width: 100%;
    justify-content: flex-start;
  }

  .sidebar-collapsed .base-button.child {
    width: calc(100% - 16px);
    margin-left: 16px;
    border-left: 2px solid rgba(255, 255, 255, 0.18);
    border-radius: 0 6px 6px 0;
    padding-left: 18px;
  }

  .content {
    padding: 20px;
  }

  .content-header {
    flex-direction: column;
  }

  .header-actions,
  .auth-panel,
  .auth-form {
    align-items: stretch;
    flex-direction: column;
  }

  .auth-form {
    justify-content: stretch;
  }

  .auth-form input,
  .auth-form button {
    width: 100%;
  }

  .origin-line {
    white-space: normal;
  }

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

  .row-actions {
    flex-wrap: wrap;
  }

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