:root {
  --bg-a: #f4f9f7;
  --bg-b: #e6eef8;
  --card: #ffffff;
  --line: #d4deea;
  --text: #1e2b36;
  --muted: #5d6f80;
  --accent: #0f766e;
  --accent-2: #1d4ed8;
  --danger: #e11d48;
  --warn: #f59e0b;
  --ok: #10b981;
  --neutral: #64748b;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Segoe UI", "Trebuchet MS", "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(1200px 500px at -100px -100px, #c7f3ea 0%, transparent 45%),
    radial-gradient(1000px 480px at 110% 0%, #cfe0fb 0%, transparent 45%),
    linear-gradient(160deg, var(--bg-a), var(--bg-b));
  min-height: 100vh;
}

body.portal-body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-wrap {
  width: min(520px, 100%);
}

.login-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-card h1 {
  margin: 0;
  font-size: 1.7rem;
  letter-spacing: 0.01em;
}

.logo-login {
  margin-top: 10px;
  max-width: 360px;
  width: 100%;
  height: auto;
  display: block;
}

.subtext {
  margin: 8px 0 0;
  color: var(--muted);
}

.form-grid {
  margin-top: 20px;
  display: grid;
  gap: 10px;
}

label {
  font-size: 0.9rem;
  color: var(--muted);
  display: grid;
  gap: 6px;
}

input,
select {
  border: 1px solid var(--line);
  background: #fdfefe;
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
}

input:focus,
select:focus {
  outline: 2px solid rgba(29, 78, 216, 0.2);
  border-color: var(--accent-2);
}

.topbar {
  padding: 6px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

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

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.15;
}

.brand p {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.logo-main {
  width: min(150px, 100%);
  height: auto;
}

.userbox {
  display: flex;
  align-items: center;
  font-size: 0.88rem;
  text-align: left;
  min-width: 0;
}

.userline {
  display: flex;
  width: auto;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  flex-wrap: nowrap;
}

.userline span {
  white-space: nowrap;
}

.userline .btn {
  margin-left: auto;
}

.layout {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 10px;
}

.card h2 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

.toolbar-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.toolbar-item {
  min-width: 160px;
}

.label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.value {
  margin-top: 4px;
  font-weight: 600;
}

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

.tabs a {
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
}

.tabs a.active {
  color: #fff;
  border-color: var(--accent);
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
}

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

.filters label {
  width: 200px;
  max-width: 100%;
}

.filters input,
.filters select {
  width: 100%;
  min-width: 0;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fff;
}

.checkline input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: flex-end;
}

.filter-actions {
  width: 200px;
  min-height: 0;
  align-self: end;
  display: flex;
  gap: 8px;
}

.filter-actions .btn {
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 0;
}

.btn {
  display: inline-block;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--text);
  background: #eef2f7;
  cursor: pointer;
}

.btn-small {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.btn-outline {
  background: #fff;
  border-color: var(--line);
}

.split {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
  overflow: hidden;
  height: 100%;
}

.split > .card {
  min-height: 0;
}

.split-tall {
  min-height: 0;
  height: 100%;
}

.users-workspace {
  display: grid;
  grid-template-columns: 68fr 32fr;
  gap: 12px;
  min-height: 0;
  align-items: stretch;
  height: 100%;
  flex: 1 1 0;
  overflow: hidden;
}

.users-workspace > .card {
  min-height: 0;
  height: 100%;
}

.users-editor-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
}

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

.users-head h2 {
  margin: 0;
}

.users-list-card table {
  min-width: 1080px;
}

.users-list-card tr.row-selected td {
  background: #e8f1ff;
  border-bottom-color: #c2d7fb;
}

.users-list-card tr.row-selected td:first-child {
  box-shadow: inset 5px 0 0 #1d4ed8;
}

.users-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  max-width: 560px;
}

.users-form label:last-of-type {
  margin-bottom: 2px;
}

.users-form .buttons,
.users-form .hint,
.users-inline {
  grid-column: 1 / -1;
}

.users-actions {
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.users-actions .btn {
  min-width: 150px;
}

.users-actions .btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.users-inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

.scad-workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  flex: 1 1 0;
}

.scad-left-card,
.scad-detail-card {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.content-grid {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(52px, 16vh);
  gap: 12px;
  min-height: 0;
  flex: 1 1 0;
  height: 100%;
  overflow: hidden;
}

.content-grid.files-collapsed {
  grid-template-rows: minmax(0, 1fr) 46px;
}

.nc-grid {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: minmax(0, 1fr) minmax(54px, 16vh);
}

.nc-list-card {
  grid-column: 1;
  grid-row: 1;
}

.nc-detail-card {
  grid-column: 2;
  grid-row: 1 / 3;
}

.nc-files-card {
  grid-column: 1;
  grid-row: 2;
}

.nc-grid.files-collapsed {
  grid-template-rows: minmax(0, 1fr) 46px;
}

.list-card,
.attachments-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  height: 100%;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 0;
  flex: 1 1 0;
  height: 0;
}

.attachments-card table {
  min-width: 0;
}

.scad-live-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  margin: 0 0 8px;
}

.scad-live-search {
  width: min(430px, 100%);
}

.scad-live-check {
  min-height: 40px;
  margin: 0;
}

.scad-live-check span {
  font-size: 0.88rem;
  color: var(--text);
}

.tree-live-empty {
  margin: 8px 10px;
}

.tree-scroll {
  min-height: 0;
  overflow: auto;
  flex: 1 1 0;
  display: grid;
  gap: 8px;
}

.tree-group,
.tree-subgroup {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.tree-group > summary,
.tree-subgroup > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}

.tree-subgroup > summary {
  position: relative;
}

.tree-subgroup > summary::before {
  content: "+";
  width: 16px;
  height: 16px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #94a3b8;
  color: #475569;
  font-size: 0.78rem;
  font-weight: 700;
  flex: 0 0 auto;
}

.tree-subgroup[open] > summary::before {
  content: "-";
}

.tree-group > summary::-webkit-details-marker,
.tree-subgroup > summary::-webkit-details-marker {
  display: none;
}

.tree-title {
  font-weight: 600;
}

.tree-meta {
  color: var(--muted);
  font-size: 0.86rem;
}

.tree-meta-sede {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 700;
  color: #64748b;
}

.tree-inner {
  padding: 0 8px 8px;
  display: grid;
  gap: 8px;
}

.tree-link {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 9px;
  text-decoration: none;
  color: var(--text);
  background: #fff;
}

.tree-link:hover {
  border-color: #bfd2ea;
  background: #f9fcff;
}

.tree-link.active {
  border-color: #1d4ed8;
  box-shadow: inset 3px 0 0 #1d4ed8;
}

.tree-link-main {
  display: grid;
  min-width: 0;
  gap: 2px;
  flex: 1 1 auto;
}

.tree-link-main .tree-title,
.tree-link-main .tree-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-link-course {
  margin-left: 18px;
  position: relative;
}

.tree-subgroup > .tree-inner {
  position: relative;
  margin-left: 10px;
  padding-left: 14px;
}

.tree-subgroup > .tree-inner::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 0;
  bottom: 8px;
  border-left: 1px dashed #b7c5d8;
}

.tree-link-course::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 50%;
  width: 12px;
  border-top: 1px dashed #b7c5d8;
}

.tree-icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
  color: #0f766e;
}

.tree-icon-user {
  stroke: none;
  fill: currentColor;
}

.tree-icon-lg {
  width: 24px;
  height: 24px;
}

.tree-icon-status.badge-danger {
  color: var(--danger);
}

.tree-icon-status.badge-warn {
  color: var(--warn);
}

.tree-icon-status.badge-ok {
  color: var(--ok);
}

.tree-icon-status.badge-neutral {
  color: var(--neutral);
}

.tree-icon-status.badge-disabled {
  color: #9aa7b5;
}

.tree-icon-status.badge-mail {
  color: #0a66c2;
}

.compact-wrap {
  height: auto;
  max-height: 230px;
  min-height: 130px;
  flex: 0 0 auto;
  margin: 0 8px 8px;
}

.clip-ind {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: #0f172a;
  vertical-align: middle;
}

.clip-ind svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.15;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status-dot {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid rgba(15, 23, 42, 0.2);
  vertical-align: middle;
}

.status-dot.badge-danger {
  background: var(--danger);
}

.status-dot.badge-warn {
  background: var(--warn);
}

.status-dot.badge-ok {
  background: var(--ok);
}

.status-dot.badge-neutral {
  background: var(--neutral);
}

.status-dot.badge-disabled {
  background: #9aa7b5;
}

.status-dot.badge-mail {
  background: #0a66c2;
}

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

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

th {
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #f7fafc;
  position: sticky;
  top: 0;
}

tr:hover td {
  background: #f9fcff;
}

tr.click-row {
  cursor: pointer;
}

tr.row-selected td {
  background: transparent;
  border-bottom-color: var(--line);
}

tr.row-selected td:first-child {
  box-shadow: inset 4px 0 0 #1d4ed8;
}

.scad-detail-card tr.row-selected td {
  background: #e8f1ff;
  border-bottom-color: #c2d7fb;
}

.scad-detail-card tr.row-selected td:first-child {
  box-shadow: inset 5px 0 0 #1d4ed8;
}

.scad-detail-card tr.row-selected:hover td {
  background: #e8f1ff;
}

.detail-grid {
  margin: 0;
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 8px 12px;
}

.detail-grid dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.detail-grid dd {
  margin: 0;
  font-size: 0.94rem;
}

.detail-scroll {
  min-height: 0;
  overflow: auto;
  flex: 1 1 0;
}

.detail-scroll .table-wrap {
  flex: 0 0 auto;
  height: auto;
  min-height: 180px;
}

.detail-caption {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.scad-detail-scroll {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.scad-detail-scroll .table-wrap {
  min-height: 0;
  height: 0;
  flex: 1 1 0;
}

.scad-detail-card table {
  min-width: 560px;
}

.scad-detail-card th:first-child,
.scad-detail-card td:first-child {
  width: 74px;
  text-align: center;
}

.attachments-inline {
  display: flex;
  flex-direction: column;
  min-height: 180px;
  max-height: 58%;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.attachments-inline .card-head {
  border-bottom: 1px solid var(--line);
  margin: 0;
  padding: 7px 10px;
}

.attachments-inline h3 {
  margin: 0;
  font-size: 0.98rem;
}

.attachments-inline .attachments-body {
  padding: 8px;
}

.attachments-inline .table-wrap {
  min-height: 0;
  height: 0;
  flex: 1 1 0;
}

.attachments-inline table {
  min-width: 0;
}

.attachments-inline.collapsed {
  min-height: 42px;
  max-height: 42px;
}

.attachments-inline.collapsed .attachments-body {
  display: none;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}

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

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

.badge.badge-ok {
  color: #fff;
  background: var(--ok);
}

.badge.badge-neutral {
  color: #fff;
  background: var(--neutral);
}

.alert {
  border-radius: 12px;
  padding: 10px 12px;
  border: 1px solid transparent;
}

.alert-error {
  color: #7f1d1d;
  background: #fee2e2;
  border-color: #fecaca;
}

.alert-success {
  color: #065f46;
  background: #d1fae5;
  border-color: #6ee7b7;
}

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

.hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.mini-title {
  margin: 16px 0 10px;
  font-size: 0.95rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding-bottom: 6px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.card-head h2 {
  margin-bottom: 0;
}

.attachments-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 8px;
  flex: 1;
  overflow: hidden;
}

.attachments-card.collapsed {
  min-height: 46px;
}

.attachments-card.collapsed .attachments-body {
  display: none;
}

.toggle-files {
  margin-left: auto;
  min-width: 88px;
  align-self: auto;
}

.app-footer {
  padding: 4px 14px 6px;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}

.app-footer-login {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
}

.logo-footer {
  height: 36px;
  width: auto;
  opacity: 0.9;
}

@media (max-width: 1200px) {
  .content-grid {
    grid-template-rows: minmax(0, 1fr) minmax(48px, 16vh);
  }

  .scad-workspace {
    grid-template-columns: 1fr;
  }

  .scad-detail-card table {
    min-width: 0;
  }

  .nc-grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr) minmax(54px, 18vh);
  }

  .nc-list-card {
    grid-column: 1;
    grid-row: 1;
  }

  .nc-detail-card {
    grid-column: 1;
    grid-row: 2;
  }

  .nc-files-card {
    grid-column: 1;
    grid-row: 3;
  }

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

  .users-workspace {
    grid-template-columns: 1fr;
  }

  .users-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .userbox {
    text-align: left;
  }

  .userline {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .filters {
    gap: 8px;
  }

  .filters label {
    width: 100%;
  }

  .scad-live-search,
  .scad-live-check {
    width: 100%;
  }

  .checkline {
    min-width: 100%;
  }

  .buttons {
    justify-content: stretch;
  }

  .buttons .btn {
    flex: 1 1 0;
    text-align: center;
  }

  .filter-actions {
    width: 100%;
  }

  .userline .btn {
    margin-left: 0;
  }

  .content-grid {
    grid-template-rows: minmax(0, 1fr) minmax(46px, 15vh);
  }

  .attachments-inline {
    max-height: 56%;
  }

  .nc-grid {
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr) minmax(50px, 18vh);
  }

  .users-list-card table {
    min-width: 700px;
  }
}
