:root {
  --bg: #f5f3f8;
  --surface: #ffffff;
  --surface-strong: #f0eaf8;
  --ink: #231b30;
  --muted: #6d627a;
  --line: #ded5e8;
  --brand: #43246f;
  --brand-dark: #2b174b;
  --accent: #f5a400;
  --accent-dark: #b96b00;
  --danger: #b42318;
  --warning: #b56a00;
  --ok: #087443;
  --shadow: 0 12px 28px rgba(43, 23, 75, 0.09);
  color-scheme: light;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
}

.hidden {
  display: none !important;
}

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

button {
  cursor: pointer;
}

.choice-group {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px 12px;
}

.choice-group legend {
  padding: 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.checkbox-option {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.checkbox-option input {
  width: 16px;
  height: 16px;
  min-height: 16px;
  margin: 0;
  padding: 0;
}

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

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(145deg, rgba(67, 36, 111, 0.95), rgba(43, 23, 75, 0.92)),
    var(--bg);
}

.auth-panel {
  width: min(100%, 430px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: #fff;
  padding: 28px;
  box-shadow: 0 28px 70px rgba(20, 11, 35, 0.32);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.auth-logo {
  width: 62px;
  height: 62px;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 12px 24px rgba(43, 23, 75, 0.2);
}

.auth-brand h1 {
  font-size: 28px;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-copy {
  margin-bottom: 0;
  color: var(--muted);
}

.auth-alert {
  min-height: 22px;
  margin-top: 14px;
  color: var(--danger);
  font-weight: 700;
}

.account-dialog {
  width: min(calc(100% - 32px), 480px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 24px;
  box-shadow: 0 28px 70px rgba(20, 11, 35, 0.32);
}

.account-dialog::backdrop {
  background: rgba(35, 27, 48, 0.62);
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-header h2,
.dialog-header p {
  margin: 0;
}

.dialog-close {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--brand-dark);
  font-weight: 800;
}

.dialog-close:hover {
  background: var(--surface-strong);
}

.dialog-actions {
  justify-content: flex-end;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 28px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #fbfaff;
}

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

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 8px 18px rgba(43, 23, 75, 0.18);
}

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

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

.nav {
  display: grid;
  flex: 1;
  min-height: 0;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 3px;
  overflow-y: auto;
  padding-right: 4px;
}

.nav-section {
  margin: 6px 0 0;
  padding: 6px 14px 2px;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.nav-item {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 10px 14px;
  text-align: left;
}

.nav-subitem {
  padding-left: 28px;
}

.nav-item:hover,
.nav-item.active {
  background: var(--surface-strong);
  color: var(--brand-dark);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar-footer {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
}

.session-box {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.session-box strong {
  overflow: hidden;
  max-width: 140px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-link {
  width: fit-content;
  border: 0;
  background: transparent;
  color: var(--brand);
  padding: 0;
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}

.session-link:hover {
  color: var(--accent-dark);
  text-decoration: underline;
}

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

.status-pill,
.count-badge,
.tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 28px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
}

.status-muted,
.tag-muted {
  background: #e8eeeb;
  color: var(--muted);
}

.status-ok,
.tag-ok {
  background: #e4f6ec;
  color: var(--ok);
}

.status-danger,
.tag-danger {
  background: #fee4e2;
  color: var(--danger);
}

.tag-warning {
  background: #fff1cc;
  color: var(--warning);
}

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

.operational-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(150px, 190px) minmax(150px, 190px) auto;
  gap: 10px;
  margin-bottom: 16px;
}

.segmented-control {
  display: flex;
  gap: 2px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.segmented-control button {
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 10px;
}

.segmented-control button.active {
  border-bottom-color: var(--accent);
  color: var(--brand-dark);
  font-weight: 800;
}

.search-results {
  display: grid;
  gap: 0;
}

.search-result {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.search-result:last-child {
  border-bottom: 0;
}

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

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

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 36px;
  line-height: 1.05;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

.filters,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.master-filter {
  margin: 16px 0 12px;
}

.master-filter input {
  flex: 1 1 220px;
}

.master-filter select {
  flex: 0 1 210px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  min-height: 40px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

textarea {
  resize: vertical;
}

select[multiple] {
  min-height: 112px;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(245, 164, 0, 0.28);
  outline-offset: 2px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric {
  min-height: 116px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
  box-shadow: var(--shadow);
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 12px;
  font-size: 34px;
  line-height: 1;
}

.metric small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
}

.content-grid {
  display: grid;
  gap: 16px;
}

.two-columns {
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.85fr);
}

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

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

.lower-grid {
  margin-top: 16px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
  box-shadow: var(--shadow);
}

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

.count-badge {
  background: #fff2cc;
  color: var(--brand-dark);
}

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

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

.dashboard-table {
  min-width: 0;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td strong {
  display: block;
}

td span {
  color: var(--muted);
  font-size: 13px;
}

.stack-list,
.entity-list,
.mini-list {
  display: grid;
  gap: 10px;
}

.entity-card,
.stack-item,
.mini-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 13px;
}

.entity-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.entity-card h3,
.stack-item h3 {
  margin-bottom: 5px;
  font-size: 15px;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #e7ece9;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--accent);
}

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

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

.full-span,
.primary-button {
  grid-column: 1 / -1;
}

.primary-button,
.icon-button,
.secondary-button {
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button,
.icon-button {
  background: var(--brand);
  color: #fff;
}

.primary-button {
  min-height: 42px;
  padding: 10px 14px;
}

.secondary-button {
  min-height: 42px;
  background: var(--surface-strong);
  color: var(--brand-dark);
  padding: 10px 14px;
}

.icon-button {
  display: grid;
  min-width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  font-size: 18px;
  padding: 0 10px;
}

.primary-button:hover,
.icon-button:hover {
  background: var(--brand-dark);
}

.icon-button.secondary {
  width: auto;
  background: var(--surface-strong);
  color: var(--brand-dark);
  font-size: 12px;
}

.icon-button.secondary:hover {
  background: #e5d8f2;
}

.secondary-button:hover {
  background: #e5d8f2;
}

.edit-button,
.delete-button {
  min-height: 30px;
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.edit-button {
  border: 1px solid #d9c7ee;
  background: var(--surface-strong);
  color: var(--brand-dark);
  margin-right: 6px;
}

.edit-button:hover {
  border-color: var(--brand);
  background: #e5d8f2;
}

.delete-button {
  border: 1px solid #f1b8b4;
  background: #fff5f4;
  color: var(--danger);
}

.delete-button:hover {
  border-color: var(--danger);
  background: #fee4e2;
}

.delete-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.temporary-password {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  border: 1px solid #ffd98a;
  border-radius: 8px;
  background: #fff8e6;
  padding: 12px;
}

.temporary-password code {
  width: fit-content;
  border-radius: 6px;
  background: #fff;
  color: var(--brand-dark);
  padding: 6px 8px;
  font-weight: 800;
}

.item-title-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.compact-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
  margin-bottom: 12px;
}

.contract-responsibles-panel {
  margin-top: 16px;
}

.alert-area {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.alert {
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: 8px;
  background: #fff;
  padding: 11px 13px;
}

.alert.error {
  border-left-color: var(--danger);
}

.empty-state {
  display: grid;
  gap: 6px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
}

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

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

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

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

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

@media (max-width: 680px) {
  .main,
  .sidebar {
    padding: 16px;
  }

  h1 {
    font-size: 30px;
  }

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

  .filters,
  .toolbar,
  .operational-toolbar,
  .form-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .entity-card {
    grid-template-columns: 1fr;
  }

  .choice-grid,
  .search-result {
    grid-template-columns: 1fr;
  }
}
