/* Structural stylesheet only. Its legacy aliases are defined in theme.css so
 * feature rules can consume a different theme without changing this file. */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100svh;
  min-height: 100vh;
  overflow: hidden;
  font-family: "Manrope", "Trebuchet MS", sans-serif;
  color: var(--text-900);
  background: var(--surface-50);
  font-size: 14px;
}

.shell-bg {
  display: none;
}

.diagnostic-download-panel {
  max-width: 860px;
}

.diagnostic-download-panel > .panel-heading > i {
  width: 42px;
  height: 42px;
  color: var(--accent);
}

.diagnostic-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 24px 0 18px;
}

.diagnostic-steps {
  margin: 0;
  padding: 18px 18px 18px 38px;
  border-left: 3px solid var(--accent);
  background: var(--theme-surface-subtle);
}

.diagnostic-steps li + li { margin-top: 8px; }

.app-shell {
  --admin-sidebar-width: 256px;
  --admin-sidebar-collapsed-width: 72px;
  --admin-rail-item-size: 41px;
  display: flex;
  height: 100svh;
  min-height: 100vh;
  overflow: hidden;
  background: var(--surface-50);
}

.side-nav {
  width: var(--admin-sidebar-width);
  flex: 0 0 var(--admin-sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--primary-900);
  color: #fff;
  border-right: 1px solid var(--nav-border);
  position: sticky;
  top: 0;
  z-index: 20;
  transition: width 180ms ease, flex-basis 180ms ease;
}

body.admin-sidebar-collapsed .side-nav {
  width: var(--admin-sidebar-collapsed-width);
  flex-basis: var(--admin-sidebar-collapsed-width);
}

.admin-brand-row {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 12px;
  border-bottom: 1px solid var(--nav-border);
}

body.admin-sidebar-collapsed .admin-brand-row {
  min-height: 96px;
  flex-direction: column;
  justify-content: center;
  padding: 10px 0;
}

.brand {
  min-width: 0;
  display: flex;
  gap: 12px;
  align-items: center;
  color: #fff;
  text-decoration: none;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(185, 167, 121, 0.18);
  border: 1px solid rgba(185, 167, 121, 0.34);
  color: #fff;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  flex: 0 0 auto;
}

.brand-icon img {
  display: block;
  width: 100%;
  height: 100%;
  padding: 3px;
  border-radius: inherit;
  background: #fff;
  object-fit: contain;
}

body.admin-sidebar-collapsed .brand {
  width: var(--admin-rail-item-size);
  height: var(--admin-rail-item-size);
  justify-content: center;
}

body.admin-sidebar-collapsed .brand-icon {
  width: var(--admin-rail-item-size);
  height: var(--admin-rail-item-size);
}

body.admin-sidebar-collapsed .brand-copy {
  display: none;
}

.brand h1 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.92rem;
  letter-spacing: 0.7px;
  text-transform: uppercase;
}

.brand p {
  margin: 4px 0 0;
  color: rgba(255, 255, 255, 0.74);
  font-size: 0.78rem;
}

.sidebar-rail-toggle {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 0;
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--nav-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.sidebar-rail-toggle:hover,
.sidebar-rail-toggle:focus {
  color: var(--primary-900);
  background: var(--accent-500);
  border-color: var(--accent-500);
}

.sidebar-rail-toggle svg {
  width: 17px;
  height: 17px;
  transition: transform 180ms ease;
}

body.admin-sidebar-collapsed .sidebar-rail-toggle {
  width: var(--admin-rail-item-size);
  height: var(--admin-rail-item-size);
}

body.admin-sidebar-collapsed .sidebar-rail-toggle svg {
  transform: rotate(180deg);
}

.side-nav .nav-menu {
  flex: 1;
  display: grid;
  gap: 4px;
  align-content: start;
  padding: 11px 8px;
  overflow-y: auto;
  overflow-x: hidden;
}

body.admin-sidebar-collapsed .side-nav .nav-menu {
  justify-items: center;
  gap: 5px;
  padding-inline: 8px;
}

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: rgba(255, 255, 255, 0.82);
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.88rem;
  transition: 140ms ease;
  border-left: 2px solid transparent;
}

body.admin-sidebar-collapsed .nav-link,
body.admin-sidebar-collapsed .logout {
  justify-content: center;
  width: var(--admin-rail-item-size);
  min-height: var(--admin-rail-item-size);
  padding: 0;
  gap: 0;
  font-size: 0;
  border-left: 0;
}

body.admin-sidebar-collapsed .nav-link::after,
body.admin-sidebar-collapsed .logout::after {
  content: attr(data-nav-label);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  z-index: 50;
  min-width: max-content;
  max-width: 224px;
  padding: 7px 9px;
  color: #fff;
  background: var(--primary-900);
  border: 1px solid var(--nav-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-strong);
  font-size: 0.78rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(4px, -50%);
  transition: opacity 120ms ease, transform 120ms ease;
}

body.admin-sidebar-collapsed .nav-link:hover::after,
body.admin-sidebar-collapsed .nav-link:focus::after,
body.admin-sidebar-collapsed .logout:hover::after,
body.admin-sidebar-collapsed .logout:focus::after {
  opacity: 1;
  transform: translate(0, -50%);
}

.nav-link svg,
.logout svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.9;
  flex: 0 0 auto;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.nav-link.active {
  background: rgba(185, 167, 121, 0.16);
  border-left-color: var(--accent-500);
  color: #fff;
}

.admin-user-panel {
  display: grid;
  gap: 7px;
  margin: 0 8px 12px;
  padding: 12px 8px 0;
  border-top: 1px solid var(--nav-border);
}

.user-name,
.user-email {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-name {
  color: #fff;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 0.82rem;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}

.user-profile-trigger:hover,
.user-profile-trigger:focus {
  color: var(--accent-500);
  outline: none;
}

.user-email {
  color: rgba(255, 255, 255, 0.64);
  font-size: 0.72rem;
}

body.admin-sidebar-collapsed .admin-user-panel {
  justify-items: center;
  margin-inline: 0;
  padding-inline: 0;
}

body.admin-sidebar-collapsed .user-name,
body.admin-sidebar-collapsed .user-email {
  display: none;
}

.logout {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  font-weight: 600;
}

.content {
  flex: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  height: 100%;
  padding: 20px 22px 0;
  min-width: 0;
  overflow: hidden;
}

.content-scroll {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0 0 28px;
  scrollbar-gutter: stable;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  color: var(--text-900);
  border: 1px solid var(--surface-200);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.topbar h2 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.18rem;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--text-700);
  font-size: 0.86rem;
}

.pill {
  background: rgba(0, 38, 35, 0.06);
  color: var(--primary-900);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  border: 1px solid var(--surface-200);
  font-weight: 700;
}

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

.metric-card,
.panel {
  background: #fff;
  border: 1px solid var(--surface-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.metric-card {
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--accent-500);
}

.metric-card span {
  color: var(--text-700);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.metric-head,
.panel h3,
.login-form label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.metric-head svg {
  width: 18px;
  height: 18px;
  color: var(--accent-500);
  stroke-width: 2;
}

.metric-card h3 {
  margin: 8px 0 0;
  color: var(--primary-900);
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.7rem;
}

.panel h3 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--primary-900);
  font-size: 1rem;
}

.panel h3 svg {
  width: 18px;
  height: 18px;
  color: var(--accent-500);
}

.panel p {
  margin: 9px 0 0;
  color: var(--text-700);
}

.module-hero,
.workspace-grid,
.document-workspace,
.knowledge-workspace {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}

.module-hero {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  background: #fff;
  border: 1px solid var(--surface-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.module-hero h3 {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  color: var(--primary-900);
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.08rem;
}

.module-hero h3 svg {
  width: 20px;
  height: 20px;
  color: var(--accent-500);
}

.module-hero p {
  margin: 5px 0 0;
  color: var(--text-700);
  font-size: 0.84rem;
}

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

.btn-secondary {
  background: #fff;
  color: var(--primary-900);
  border: 1px solid var(--surface-200);
}

.btn-secondary:hover {
  background: var(--surface-100);
  color: var(--primary-900);
}

.workspace-grid {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.62fr);
}

.document-workspace,
.knowledge-workspace {
  grid-template-columns: 260px minmax(0, 1fr);
}

.mini-tabs,
.module-tabs,
.status-row,
.state-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.mini-tabs button,
.module-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--surface-200);
  background: var(--surface-50);
  color: var(--text-700);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-weight: 800;
}

.module-tabs button:first-child,
.mini-tabs button:first-child {
  background: var(--primary-900);
  color: #fff;
  border-color: var(--primary-900);
}

.module-tabs svg,
.state-grid svg {
  width: 16px;
  height: 16px;
}

.page-tab-shell {
  display: grid;
  gap: 14px;
}

.page-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px;
  margin-bottom: 0;
  background: #fff;
  border: 1px solid var(--surface-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.page-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-700);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}

.page-tabs a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-700);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.page-tabs a:hover,
.page-tabs a:focus-visible {
  color: var(--primary-900);
  background: var(--surface-100);
}

.page-tabs a.active,
.page-tabs a[aria-current="page"] {
  color: #fff;
  background: var(--primary-900);
  border-color: var(--primary-900);
}

.page-tabs button:hover,
.page-tabs button:focus {
  color: var(--primary-900);
  background: var(--surface-100);
}

.page-tabs button.active {
  color: #fff;
  background: var(--primary-900);
  border-color: var(--primary-900);
}

.page-tabs svg {
  width: 16px;
  height: 16px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.detail-list,
.timeline {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.detail-list {
  grid-template-columns: 130px minmax(0, 1fr);
}

.detail-list span,
.timeline span {
  color: var(--text-700);
  font-size: 0.82rem;
}

.detail-list strong,
.timeline strong {
  color: var(--text-900);
}

mark {
  background: rgba(21, 128, 61, 0.1);
  color: var(--success-600);
  border-radius: 6px;
  padding: 2px 7px;
  font-weight: 800;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 0.75rem;
  font-weight: 800;
}

.status-chip.open { background: var(--theme-status-info-bg); color: var(--theme-info); }
.status-chip.progress { background: var(--theme-status-warning-bg); color: var(--theme-warning); }
.status-chip.wait { background: var(--theme-accent-soft); color: var(--theme-primary-muted); }
.status-chip.done { background: var(--theme-status-success-bg); color: var(--success-600); }
.status-chip.danger { background: var(--theme-status-danger-bg); color: var(--danger-600); }
.status-chip.queued { background: var(--surface-100); color: var(--text-700); }

.code-panel,
.editor-shell {
  margin-top: 12px;
  border-radius: 8px;
  background: var(--surface-900);
  color: #fff;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.83rem;
}

.editor-shell {
  background: var(--surface-50);
  color: var(--text-900);
  border: 1px solid var(--surface-200);
  font-family: inherit;
}

.service-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  border: 1px solid var(--surface-200);
  border-radius: 8px;
  padding: 10px 12px;
}

.service-card strong {
  color: var(--primary-800);
}

.folder-tree,
.article-list {
  background: #fff;
  border: 1px solid var(--surface-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.folder-tree h3,
.article-list h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  color: var(--primary-900);
  font-size: 0.96rem;
}

.folder-tree span,
.article-list span {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 8px;
  padding: 8px 9px;
  color: var(--text-700);
  font-size: 0.85rem;
}

.folder-tree span:first-of-type,
.article-list span:first-of-type {
  background: rgba(185, 167, 121, 0.15);
  color: var(--primary-900);
  font-weight: 800;
}

.permission-grid {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) repeat(4, 70px);
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  overflow-x: auto;
}

.permission-grid span {
  color: var(--text-700);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.permission-grid input {
  accent-color: var(--primary-900);
}

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

.record-actions,
.table-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.table-menu-cell {
  width: 58px;
  min-width: 58px;
  text-align: right;
  vertical-align: middle;
}

.row-action-menu {
  position: relative;
  display: inline-flex;
  justify-content: flex-end;
}

.row-action-trigger {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--surface-200);
  background: #fff;
  color: var(--text-900);
}

.row-action-popover {
  position: fixed;
  top: var(--action-menu-top, 0);
  left: var(--action-menu-left, 0);
  z-index: 40;
  display: grid;
  min-width: 172px;
  padding: 6px;
  border: 1px solid var(--surface-200);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--modal-shadow);
}

.row-action-popover[hidden] {
  display: none;
}

.row-action-popover button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-900);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}

.row-action-popover button:hover {
  background: var(--surface-100);
}

.row-action-popover button.danger {
  color: var(--danger-700);
}

.row-action-popover svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.panel-tools button,
.quick-form button,
.query-controls button,
.login-form button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  background: var(--primary-800);
  color: #fff;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 800;
  cursor: pointer;
  transition: 140ms ease;
}

.panel-tools button svg,
.quick-form button svg,
.query-controls button svg,
.login-form button svg,
.btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
}

.panel-tools button:hover,
.quick-form button:hover,
.query-controls button:hover,
.login-form button:hover,
.btn:hover {
  background: var(--primary-900);
}

.table-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 30px;
  border: 1px solid var(--surface-200);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--primary-900);
  padding: 6px 9px;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 800;
  cursor: pointer;
}

.table-action:hover {
  background: var(--surface-100);
}

.table-action.danger {
  color: var(--danger-600);
}

.table-action svg {
  width: 14px;
  height: 14px;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--surface-200);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--primary-900);
  cursor: pointer;
}

.icon-button svg {
  width: 17px;
  height: 17px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: clamp(12px, 2vw, 28px);
  overflow-y: auto;
  background: rgba(6, 20, 19, 0.64);
  backdrop-filter: blur(8px);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  width: min(760px, 100%);
  max-height: calc(100svh - clamp(24px, 4vw, 56px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #fff;
  border: 1px solid var(--surface-200);
  border-radius: 10px;
  box-shadow: 0 32px 96px rgba(8, 25, 23, 0.3);
  overflow: hidden;
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--surface-200);
  background: #fff;
}

.modal-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--surface-200);
  border-bottom: 0;
  background: #f8faf9;
}

.modal-header h3 {
  margin: 0;
  color: var(--primary-900);
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.08rem;
}

.modal-header p {
  margin: 4px 0 0;
  color: var(--text-700);
  font-size: 0.82rem;
}

.modal-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  padding: 20px 22px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #f8faf9;
}

.modal-form label {
  display: grid;
  gap: 6px;
  color: var(--text-700);
  font-size: 0.82rem;
  font-weight: 700;
}

.modal-form input,
.modal-form textarea,
.modal-form select,
.query-controls select {
  border-radius: 8px;
  border: 1px solid var(--surface-200);
  background: #fff;
  padding: 10px 11px;
  color: var(--text-900);
  font: inherit;
}

.modal-form textarea {
  min-height: 120px;
  resize: vertical;
}

.modal-form input,
.modal-form textarea,
.modal-form select {
  width: 100%;
  min-width: 0;
  min-height: 42px;
}

.modal-form select[multiple] {
  min-height: 150px;
}

.modal-form .form-help {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--surface-200);
  border-radius: 8px;
  background: var(--surface-100);
  color: var(--text-700);
  font-size: 0.82rem;
  line-height: 1.5;
}

.modal-form .form-section {
  min-width: 0;
}

.form-grid > label,
.form-grid > .form-help,
.form-grid > .check-field,
.form-grid > .ticket-requester-match {
  min-width: 0;
}

.form-grid > .wide-field {
  grid-column: 1 / -1;
}

.compact-modal-form,
.record-editor-form {
  grid-template-columns: minmax(0, 1fr);
}

.record-modal-card {
  width: min(840px, calc(100vw - 32px));
}

.modal-form input:focus,
.modal-form textarea:focus,
.modal-form select:focus,
.query-controls select:focus {
  outline: none;
  border-color: var(--accent-500);
  box-shadow: 0 0 0 3px rgba(185, 167, 121, 0.2);
}

.clients-toolbar,
.contacts-toolbar,
.tickets-toolbar,
.inventory-toolbar,
.kb-toolbar {
  margin-bottom: 14px;
}

.clients-table td,
.contacts-table td,
.tickets-table td,
.inventory-table td,
.kb-table td {
  vertical-align: top;
  white-space: normal;
}

.clients-table td:first-child {
  min-width: 180px;
}

.clients-table td:nth-child(2) {
  min-width: 180px;
}

.contacts-table td:first-child,
.contacts-table td:nth-child(5) {
  min-width: 180px;
}

.muted-line {
  display: block;
  margin-top: 3px;
  color: var(--text-700);
  font-size: 0.76rem;
}

.client-modal-card {
  width: min(1180px, calc(100vw - 32px));
  max-height: min(900px, calc(100vh - 32px));
}

.contact-modal-card {
  width: min(1180px, calc(100vw - 32px));
  max-height: min(900px, calc(100vh - 32px));
}

.contact-editor-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 18px;
  background: #f8faf9;
}

.contact-editor-form .wide-field {
  grid-column: 1 / -1;
}

.contact-editor-form .form-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--surface-200);
  border-radius: 10px;
  background: #fff;
}

.contact-editor-form select[multiple] {
  min-height: 174px;
  padding: 8px;
}

.contact-editor-form select[multiple] option {
  padding: 8px;
  border-radius: 6px;
}

.contact-source-layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(420px, 1.2fr);
  gap: 16px;
  padding: 18px;
  background: #f8faf9;
}

.contact-source-layout .contact-editor-form {
  padding: 0;
}

.ticket-editor-card,
.ticket-detail-card {
  width: min(1240px, calc(100vw - 32px));
  max-height: min(920px, calc(100vh - 32px));
}

.tickets-table td:first-child {
  min-width: 260px;
}

.tickets-table td:nth-child(2),
.tickets-table td:nth-child(6) {
  min-width: 170px;
}

.ticket-detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 16px;
  padding: 16px;
  background: #f8faf9;
  overflow-y: auto;
}

.ticket-requester-match {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--surface-200);
  border-radius: 10px;
  background: var(--surface-100);
  color: var(--text-800);
  font-size: 0.82rem;
  font-weight: 700;
}

.ticket-requester-match[hidden] {
  display: none;
}

.ticket-requester-match .btn {
  min-height: 34px;
  padding: 7px 11px;
  font-size: 0.76rem;
}

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

.ticket-thread-panel,
.ticket-reply-panel {
  border: 1px solid var(--surface-200);
  border-radius: 10px;
  background: #fff;
}

.ticket-thread {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.ticket-reply {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--surface-200);
  border-radius: 10px;
  background: #fff;
}

.ticket-reply.pending-task {
  border-color: rgba(185, 167, 121, 0.75);
  background: rgba(185, 167, 121, 0.08);
}

.ticket-reply header,
.ticket-reply footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-700);
  font-size: 0.78rem;
}

.ticket-reply p {
  margin: 0;
  color: var(--text-900);
  white-space: pre-wrap;
}

.ticket-reply-panel {
  padding: 14px;
}

.password-control-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px 42px;
  gap: 8px;
  align-items: end;
}

.password-control-field > span {
  grid-column: 1 / -1;
}

.password-control-field input {
  min-width: 0;
}

.password-control-field .icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--surface-200);
  background: #fff;
}

/* Shared modal system: all create/edit dialogs use the same spacing and field rhythm. */
.client-editor-form,
.contact-editor-form,
.structure-form,
.kb-form,
.purchase-form,
.agent-form,
.inventory-form,
.document-form {
  gap: 14px;
  padding: 20px 22px;
  background: #f8faf9;
}

.client-editor-form .form-section,
.contact-editor-form .form-section,
.structure-form .form-section,
.kb-form .form-section,
.purchase-form .form-section,
.agent-form .form-section,
.inventory-form .form-section,
.document-form .form-section,
.compact-modal-form .form-section,
.record-editor-form .form-section {
  gap: 14px;
  padding: 18px;
  border-radius: 8px;
  background: #fff;
}

.form-grid {
  align-items: end;
}

.form-grid > label > span,
.modal-form > label > span {
  color: var(--text-700);
  font-size: 0.76rem;
  font-weight: 800;
}

.form-grid > label,
.modal-form > label {
  gap: 7px;
}

.form-grid input,
.form-grid textarea,
.form-grid select {
  box-sizing: border-box;
}

.form-grid .check-field {
  min-height: 42px;
  padding: 0 0 0 2px;
}

.form-grid .check-field span {
  font-size: 0.8rem;
}

.form-grid .password-control-field {
  align-self: end;
}

.portal-users-layout {
  gap: 18px;
  padding: 20px 22px;
  background: #f8faf9;
}

.portal-users-layout .compact-modal-form {
  padding: 0;
  background: transparent;
}

.permission-row {
  align-items: end;
  padding: 12px;
  background: #fff;
}

.permission-row select,
.permission-row input {
  min-width: 0;
}

.ticket-reply-panel .modal-form {
  padding: 0;
  background: transparent;
}

.ticket-reply-panel .modal-form label:not(.check-field) {
  grid-column: 1 / -1;
}

.ticket-reply-panel .modal-actions-row,
.ticket-reply-panel .ticket-requester-match {
  grid-column: 1 / -1;
}

@media (max-width: 760px) {
  .modal-overlay {
    place-items: end center;
    padding: 0;
  }

  .modal-card,
  .client-modal-card,
  .contact-modal-card,
  .client-editor-card,
  .ticket-editor-card,
  .ticket-detail-card,
  .inventory-modal-card,
  .purchase-modal-card,
  .kb-modal-card,
  .structure-modal-card,
  .agent-modal-card,
  .document-modal-card,
  .record-modal-card {
    width: 100%;
    max-height: min(92svh, 920px);
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 10px 10px 0 0;
  }

  .modal-header,
  .modal-footer,
  .modal-form,
  .client-editor-form,
  .contact-editor-form,
  .structure-form,
  .kb-form,
  .purchase-form,
  .agent-form,
  .inventory-form,
  .document-form,
  .portal-users-layout {
    padding-right: 16px;
    padding-left: 16px;
  }

  .form-grid-4,
  .form-grid-3,
  .form-grid-2,
  .agent-form .form-grid,
  .structure-manual-permissions {
    grid-template-columns: minmax(0, 1fr);
  }

  .field-span-2,
  .form-grid > .wide-field {
    grid-column: auto;
  }

  .modal-footer {
    align-items: stretch;
  }

  .modal-footer .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
}

@media (max-width: 920px) {
  .ticket-detail-layout {
    grid-template-columns: 1fr;
  }
}

.client-editor-card {
  width: min(1220px, calc(100vw - 32px));
  max-height: min(900px, calc(100vh - 32px));
}

.client-editor-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  padding: 18px;
  background: #f8faf9;
}

.form-section {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--surface-200);
  border-radius: 10px;
  background: #fff;
}

.form-section-main {
  border-top: 3px solid var(--primary-800);
}

.form-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--surface-200);
}

.form-section-head h4 {
  margin: 0;
  color: var(--primary-900);
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.96rem;
}

.form-section-head p {
  margin: 4px 0 0;
  color: var(--text-700);
  font-size: 0.78rem;
}

.form-grid {
  display: grid;
  gap: 12px;
  align-items: start;
}

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

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

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

.field-span-2 {
  grid-column: span 2;
}

.field-span-4 {
  grid-column: 1 / -1;
}

.client-form .wide-field,
.structure-form .wide-field,
.kb-form .wide-field,
.purchase-form .wide-field,
.agent-form .wide-field {
  grid-column: 1 / -1;
}

.client-form select[multiple] {
  min-height: 144px;
  padding: 8px;
}

.client-form select[multiple] option {
  padding: 7px 8px;
  border-radius: 6px;
}

.structure-form,
.kb-form,
.purchase-form,
.agent-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 18px;
  background: #f8faf9;
}

.structure-form .form-section,
.kb-form .form-section,
.purchase-form .form-section,
.agent-form .form-section {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--surface-200);
  border-radius: 10px;
  background: #fff;
}

.location-picker-field {
  gap: 6px;
}

.location-picker-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
  align-items: center;
}

.location-picker-control input {
  width: 100%;
}

.location-picker-control .icon-button {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  border: 1px solid var(--surface-200);
  background: #fff;
  color: var(--primary-900);
}

.repeatable-section {
  display: grid;
  gap: 10px;
}

.repeatable-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-700);
  font-size: 0.82rem;
  font-weight: 800;
}

.repeatable-head .btn {
  min-height: 34px;
  padding: 7px 11px;
  font-size: 0.76rem;
}

.repeatable-rows {
  display: grid;
  gap: 8px;
}

.repeatable-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) 38px;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--surface-200);
  border-radius: 10px;
  background: #fbfcfb;
}

.company-number-row {
  grid-template-columns: minmax(220px, 1fr) 38px;
}

.repeatable-row label {
  min-width: 0;
}

@media (max-width: 760px) {
  .client-editor-card {
    width: calc(100vw - 18px);
    max-height: calc(100vh - 18px);
  }

  .form-grid-4,
  .form-grid-3 {
    grid-template-columns: 1fr;
  }

  .field-span-2 {
    grid-column: auto;
  }

  .repeatable-row,
  .company-number-row {
    grid-template-columns: 1fr;
  }
}

.client-filters {
  margin-bottom: 14px;
}

.payroll-summary-panel {
  margin-bottom: 14px;
}

.payroll-tabs-shell {
  margin-bottom: 14px;
}

.payroll-tabs a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-700);
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
}

.payroll-tabs a.active {
  border-color: var(--surface-200);
  background: #fff;
  color: var(--primary-900);
}

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

.summary-grid div {
  display: grid;
  gap: 4px;
  border: 1px solid var(--surface-200);
  border-radius: 8px;
  background: var(--surface-100);
  padding: 12px;
}

.summary-grid span {
  color: var(--text-700);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-grid strong {
  color: var(--primary-900);
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.1rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--surface-100);
  color: var(--text-700);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.status-approved {
  background: rgba(22, 101, 52, 0.1);
  color: #166534;
}

.status-pending {
  background: rgba(180, 83, 9, 0.12);
  color: #92400e;
}

.status-rejected {
  background: rgba(185, 28, 28, 0.1);
  color: #991b1b;
}

.inventory-filter-panel {
  margin-bottom: 14px;
}

.kb-filters {
  margin-bottom: 14px;
}

.inventory-grid,
.inventory-tabs-shell {
  display: grid;
  gap: 14px;
}

.inventory-tabs {
  margin-bottom: 0;
}

.inventory-panel {
  min-width: 0;
}

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

.inventory-panel-head h3 {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.inventory-panel-head svg {
  width: 18px;
  height: 18px;
  color: var(--primary-800);
}

.inventory-modal-card {
  width: min(1180px, calc(100vw - 32px));
  max-height: min(900px, calc(100vh - 32px));
}

.purchase-modal-card {
  width: min(1040px, calc(100vw - 32px));
  max-height: min(880px, calc(100vh - 32px));
}

.purchase-form {
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 18px;
  background: #f8faf9;
}

.purchase-form .wide-field {
  grid-column: 1 / -1;
}

.purchase-form select[multiple] {
  min-height: 172px;
  padding: 8px;
}

.purchases-toolbar,
.purchase-filter-panel {
  margin-bottom: 14px;
}

.inventory-form .wide-field {
  grid-column: 1 / -1;
}

.inventory-form {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: #f8faf9;
}

.inventory-permission-field[hidden] {
  display: none;
}

.kb-modal-card {
  width: min(1180px, calc(100vw - 32px));
  max-height: min(900px, calc(100vh - 32px));
}

.structure-modal-card {
  width: min(1120px, calc(100vw - 32px));
  max-height: min(900px, calc(100vh - 32px));
}

.kb-form .wide-field {
  grid-column: 1 / -1;
}

.structure-form {
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 18px;
  background: #f8faf9;
}

.structure-form .wide-field,
.structure-form .field-span-4 {
  grid-column: 1 / -1;
}

.structure-form .form-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--surface-200);
  border-radius: 10px;
  background: #fff;
}

.form-section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  color: var(--primary-900);
  font-size: 0.84rem;
  font-weight: 900;
}

.form-section-title p {
  max-width: 520px;
  margin: 0;
  color: var(--text-700);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.45;
}

.switch-field {
  display: inline-flex !important;
  grid-auto-flow: column;
  align-items: center;
  gap: 8px !important;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--surface-200);
  border-radius: 999px;
  background: var(--surface-50);
  color: var(--text-800) !important;
  white-space: nowrap;
}

.permission-mode-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 6px;
  width: min(420px, 100%);
  padding: 5px;
  border: 1px solid var(--surface-200);
  border-radius: 10px;
  background: var(--surface-100);
}

.permission-mode-switch button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-700);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 800;
  cursor: pointer;
}

.permission-mode-switch button.active {
  background: #fff;
  color: var(--primary-900);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.permission-mode-switch svg {
  width: 16px;
  height: 16px;
}

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

.structure-manual-permissions[hidden] {
  display: none;
}

.structure-manual-permissions select[multiple] {
  min-height: 172px;
  padding: 8px;
}

.structure-manual-permissions select[multiple] option {
  padding: 8px;
  border-radius: 6px;
}

.rich-editor-shell {
  display: grid;
  gap: 8px;
  color: var(--text-700);
  font-size: 0.82rem;
  font-weight: 700;
}

.rich-editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.rich-editor-toolbar button {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--surface-200);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--primary-900);
  cursor: pointer;
}

.rich-editor-toolbar svg {
  width: 16px;
  height: 16px;
}

.rich-editor {
  min-height: 260px;
  max-height: 420px;
  overflow-y: auto;
  border: 1px solid var(--surface-200);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  color: var(--text-900);
  line-height: 1.55;
}

.rich-editor:focus {
  outline: none;
  border-color: var(--accent-500);
  box-shadow: 0 0 0 3px rgba(185, 167, 121, 0.2);
}

.kb-table td:first-child {
  min-width: 220px;
}

.kb-table td:nth-child(4) {
  min-width: 220px;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--primary-900);
  background: var(--surface-100);
  border: 1px solid var(--surface-200);
  font-size: 0.74rem;
  font-weight: 800;
}

.source-badge svg {
  width: 14px;
  height: 14px;
}

.client-shell {
  display: flex;
  min-height: 100vh;
  background: var(--surface-50);
}

.client-side-nav {
  width: 248px;
  flex: 0 0 248px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 10px;
  background: var(--primary-900);
  color: #fff;
}

.client-side-nav .brand {
  padding: 0 8px 14px;
  border-bottom: 1px solid var(--nav-border);
}

.client-side-nav .nav-menu {
  flex: 1;
  display: grid;
  align-content: start;
  gap: 5px;
}

.client-content {
  min-width: 0;
}

.client-portal-toolbar {
  margin-bottom: 14px;
}

.client-portal-table td {
  vertical-align: top;
  white-space: normal;
}

.launcher-library { display: grid; gap: 1.5rem; }
.launcher-field-builder { border-top: 1px solid var(--line); padding-top: 1.25rem; }
.launcher-field-builder > header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.launcher-field-builder h4, .launcher-field-builder p { margin: 0; }
.launcher-field-builder p { color: var(--muted); font-size: .88rem; }
.launcher-field-row { display: grid; grid-template-columns: 2rem minmax(120px,1fr) minmax(150px,1.35fr) minmax(110px,.75fr) minmax(150px,1fr) auto auto; align-items: end; gap: .75rem; padding: .9rem 0; border-bottom: 1px solid var(--line); }
.launcher-field-order { align-self: center; color: var(--muted); font-weight: 800; }
.launcher-required { display: flex; align-items: center; gap: .45rem; min-height: 2.7rem; }
.launcher-source-review { display: grid; gap: .8rem; border-top: 1px solid var(--line); padding-top: 1.25rem; }
.launcher-source-review pre { max-height: 28rem; overflow: auto; white-space: pre-wrap; }
@media (max-width: 1000px) { .launcher-field-row { grid-template-columns: 2rem 1fr 1fr; } .launcher-field-row > :nth-child(5), .launcher-field-row > :nth-child(6), .launcher-field-row > :nth-child(7) { grid-column: auto; } }

.launcher-public-body { min-height: 100vh; margin: 0; background: var(--workspace, #f3f6f5); color: var(--text, #102522); display: grid; place-items: center; padding: 2rem; }
.launcher-public-shell { width: min(100%, 760px); }
.launcher-public-brand { display: flex; align-items: center; gap: .85rem; margin-bottom: 2rem; }
.launcher-public-logo { width: 3.25rem; height: 3.25rem; border-radius: 1rem; display: grid; place-items: center; overflow: hidden; background: var(--primary-900, #003b35); color: #fff; font: 800 1.3rem/1 "Space Grotesk", sans-serif; }
.launcher-public-logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.launcher-public-brand > div:last-child { display: grid; }
.launcher-public-brand strong { font: 800 1.15rem/1.2 "Space Grotesk", sans-serif; letter-spacing: .06em; }
.launcher-public-brand span { color: var(--text-muted, #657773); font-size: .82rem; }
.launcher-public-workspace { background: #fff; border-top: 4px solid var(--accent-500, #08715d); padding: clamp(2rem,6vw,4rem); box-shadow: 0 24px 70px rgba(0,43,38,.1); }
.launcher-public-kicker { margin: 0 0 .8rem; color: var(--accent-500, #08715d); font-weight: 800; font-size: .76rem; letter-spacing: .12em; text-transform: uppercase; }
.launcher-public-workspace h1 { max-width: 14ch; margin: 0 0 1rem; font: 700 clamp(2.1rem,6vw,4rem)/1 "Space Grotesk", sans-serif; letter-spacing: -.04em; }
.launcher-public-workspace > p:not(.launcher-public-kicker):not(.launcher-code-error) { max-width: 56ch; color: var(--text-muted, #657773); line-height: 1.65; }
.launcher-public-state { display: flex; align-items: center; gap: .55rem; margin-bottom: 2.5rem; color: var(--text-muted, #657773); font-size: .8rem; }
.launcher-public-state span { width: .55rem; height: .55rem; border-radius: 50%; background: #1da879; box-shadow: 0 0 0 .3rem rgba(29,168,121,.12); }
.launcher-code-form { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: .75rem; margin-top: 2rem; }
.launcher-code-form label { display: grid; gap: .45rem; font-weight: 700; }
.launcher-code-form input { min-height: 3.2rem; font: 700 1.05rem/1 monospace; letter-spacing: .08em; text-transform: uppercase; }
.launcher-code-form .btn { min-height: 3.2rem; }
.launcher-code-error { color: #a42b27; font-weight: 700; margin: .8rem 0 0; }
.launcher-public-trust { display: grid; gap: .35rem; margin-top: 2rem; padding-top: 1.4rem; border-top: 1px solid var(--border, #dfe7e5); }
.launcher-public-trust span { color: var(--text-muted, #657773); font-size: .86rem; line-height: 1.55; }
.launcher-public-footer { display: flex; justify-content: space-between; gap: 1rem; margin-top: 1rem; color: var(--text-muted, #657773); font-size: .75rem; }
@media (max-width: 640px) { .launcher-public-body { padding: 1rem; place-items: start center; } .launcher-public-brand { margin-top: 1rem; } .launcher-public-workspace { padding: 2rem 1.35rem; } .launcher-code-form { grid-template-columns: 1fr; } .launcher-public-footer { display: grid; } }

.checkbox-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 8px 0;
}

.checkbox-list label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .9rem;
}

.portal-users-layout {
  display: grid;
  gap: 14px;
  padding: 16px;
  overflow-y: auto;
}

.portal-users-layout .modal-form {
  padding: 0;
}

.portal-permission-builder {
  display: grid;
  gap: 10px;
}

.permission-builder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-700);
  font-size: 0.82rem;
  font-weight: 800;
}

.permission-rows {
  display: grid;
  gap: 8px;
}

.permission-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.3fr) minmax(130px, 0.8fr) minmax(110px, 0.7fr) minmax(90px, 0.5fr) minmax(160px, 0.8fr) 38px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--surface-200);
  border-radius: 8px;
  background: var(--surface-50);
}

.permission-row label {
  min-width: 0;
}

.permission-row .icon-button {
  width: 38px;
  height: 38px;
}

@media (max-width: 980px) {
  .permission-row {
    grid-template-columns: 1fr;
  }
}

.documents-toolbar,
.document-filter-panel {
  margin-bottom: 14px;
}

.agents-toolbar,
.agent-filter-panel {
  margin-bottom: 14px;
}

.agents-tab-shell {
  margin-top: 0;
}

.agents-table td {
  vertical-align: top;
  white-space: normal;
}

.agent-modal-card {
  width: min(1040px, 100%);
}

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

.agent-form .form-section {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--surface-200);
  border-radius: 8px;
  background: #fff;
}

.agent-form .form-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--surface-200);
}

.agent-form .form-section-head h4 {
  margin: 0;
  color: var(--primary-900);
  font-size: 0.98rem;
}

.agent-form .form-section-head p {
  margin: 3px 0 0;
  color: var(--text-700);
  font-size: 0.8rem;
}

.agent-form .form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.agent-form .check-field {
  min-height: 42px;
  align-self: end;
}

.document-library-shell {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.document-tree-panel,
.document-files-panel {
  min-width: 0;
}

.document-tree-panel h3 {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
}

.document-tree {
  display: grid;
  gap: 6px;
}

.tree-cabinet {
  display: grid;
  gap: 2px;
}

.tree-folder-list {
  display: grid;
  gap: 2px;
  margin: 2px 0 4px 13px;
  padding-left: 10px;
  border-left: 1px solid var(--surface-200);
}

.tree-branch,
.tree-children {
  display: grid;
  gap: 2px;
}

.tree-children {
  margin-left: 13px;
  padding-left: 10px;
  border-left: 1px solid var(--surface-200);
}

.tree-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
}

.tree-toggle,
.tree-toggle-spacer {
  width: 26px;
  height: 30px;
  display: grid;
  place-items: center;
}

.tree-toggle {
  border: 0;
  border-radius: 4px;
  color: var(--text-700);
  background: transparent;
  cursor: pointer;
}

.tree-toggle:hover {
  color: var(--primary-700);
  background: var(--surface-100);
}

.tree-toggle svg {
  width: 16px;
  height: 16px;
  stroke-width: 2.25;
}

.tree-node {
  width: 100%;
  min-height: 34px;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-900);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.tree-node:hover,
.tree-node.active {
  background: var(--surface-100);
  border-color: var(--surface-200);
}

.tree-node span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-node small {
  color: var(--text-700);
  font-size: 0.72rem;
}

.tree-folder {
  min-height: 30px;
  font-size: 0.82rem;
}

.documents-table td {
  vertical-align: top;
  white-space: normal;
}

.document-modal-card {
  width: min(900px, 100%);
}

.document-form .wide-field {
  grid-column: 1 / -1;
}

@media (max-width: 900px) {
  .document-library-shell {
    grid-template-columns: 1fr;
  }
}

.credential-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin: 2px 4px 2px 0;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--primary-900);
  background: var(--surface-100);
  border: 1px solid var(--surface-200);
  font-size: 0.74rem;
  font-weight: 700;
}

.check-field {
  display: flex !important;
  align-items: center;
  grid-template-columns: none !important;
  gap: 8px;
  min-height: 42px;
  padding-top: 20px;
}

.check-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary-800);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--surface-200);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  border: none;
  border-radius: 0;
  overflow: hidden;
}

thead th {
  text-align: left;
  background: var(--surface-100);
  color: var(--primary-900);
  padding: 10px 12px;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--surface-200);
  color: var(--text-900);
  font-size: 0.84rem;
  white-space: nowrap;
}

tbody tr:hover {
  background: rgba(0, 38, 35, 0.025);
}

.query-controls,
.quick-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
  align-items: end;
}

.query-controls > .btn,
.query-controls > button {
  min-height: 42px;
  align-self: end;
  justify-self: start;
  white-space: nowrap;
}

.query-controls label {
  min-width: 0;
}

.query-controls label,
.quick-form label,
.login-form label {
  display: grid;
  gap: 6px;
  color: var(--text-700);
  font-size: 0.82rem;
  font-weight: 600;
}

.query-controls input,
.quick-form input,
.quick-form select,
.login-form input,
.form input,
.form select,
.form textarea {
  border-radius: 8px;
  border: 1px solid var(--surface-200);
  background: #fff;
  padding: 10px 11px;
  color: var(--text-900);
  font: inherit;
}

.form textarea {
  min-height: 130px;
  resize: vertical;
}

.form-block {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.form-block h4 {
  margin: 14px 0 0;
  color: var(--primary-900);
}

.form-block p {
  margin: 0;
  color: var(--text-500);
  font-size: 0.82rem;
}

.form-block label {
  display: grid;
  gap: 6px;
  color: var(--text-700);
  font-size: 0.82rem;
  font-weight: 700;
}

.check-row {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary-900);
}

.query-controls input:focus,
.quick-form input:focus,
.login-form input:focus,
.form input:focus,
.form select:focus,
.form textarea:focus {
  outline: none;
  border-color: var(--accent-500);
  box-shadow: 0 0 0 3px rgba(185, 167, 121, 0.2);
}

.api-tag {
  margin-top: 10px;
  color: var(--primary-800);
  font-weight: 600;
}

code {
  background: var(--surface-900);
  color: #fff;
  border-radius: 6px;
  padding: 2px 6px;
}

.login-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: stretch;
  justify-items: stretch;
  padding: 20px;
  background: var(--bg);
  overflow: auto;
}

.login-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(2, 38, 35, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(2, 38, 35, 0.035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.85), transparent 78%);
}

.login-panel {
  position: relative;
  z-index: 1;
  align-self: center;
  justify-self: center;
  width: min(1040px, 100%);
  min-height: min(620px, calc(100dvh - 112px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 420px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--modal-shadow);
  overflow: hidden;
}

.login-brand-pane {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
  padding: 24px;
  color: var(--nav-text-strong);
  background:
    radial-gradient(circle at 80% 12%, rgba(185, 167, 121, 0.22), transparent 26%),
    linear-gradient(135deg, var(--nav), var(--nav-2));
}

.login-brand-pane::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(135deg, rgba(0, 0, 0, 0.7), transparent 76%);
  pointer-events: none;
}

.login-logo-row,
.login-copy,
.login-signal-list {
  position: relative;
  z-index: 1;
}

.login-logo-row,
.login-mobile-brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.login-mobile-brand {
  display: none;
}

.login-logo {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--nav);
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.05rem;
  font-weight: 800;
}

.login-logo-title {
  color: var(--nav-text-strong);
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.1;
}

.login-logo-subtitle {
  margin-top: 2px;
  color: var(--muted-2);
  font-size: 0.72rem;
  font-weight: 600;
}

.login-copy {
  max-width: 384px;
}

.login-eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.login-copy h1 {
  margin: 0;
  color: var(--nav-text-strong);
  font-size: clamp(1.75rem, 3vw, 2.35rem);
  font-weight: 800;
  line-height: 1.08;
}

.login-copy p:not(.login-eyebrow) {
  margin: 16px 0 0;
  color: var(--nav-text);
  font-size: 0.92rem;
  line-height: 1.6;
}

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

.login-signal-list span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 6px 9px;
  color: var(--nav-text-strong);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--nav-border);
  border-radius: var(--radius-sm);
  font-size: 0.74rem;
  font-weight: 700;
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  align-self: center;
  padding: 32px;
  background: var(--surface);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.login-form-header {
  margin-bottom: 20px;
}

.login-card .brand {
  display: block;
  margin: 0;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1.1;
}

.login-card .subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.login-form {
  margin-top: 18px;
  display: grid;
  gap: 9px;
}

.login-form label svg {
  width: 15px;
  height: 15px;
  color: var(--accent-500);
}

.login-form .form-control,
.login-code-input {
  min-height: 42px;
}

.login-main-action {
  height: 45px;
  min-height: 45px;
  margin-top: 4px;
  border-radius: 10px;
  font-size: 0.88rem;
  line-height: 1;
}

.button-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
}

.login-secondary-link {
  display: inline-flex;
  justify-self: center;
  margin-top: 6px;
  color: var(--primary-900);
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
}

.login-secondary-link:hover {
  color: var(--accent-500);
}

.error-box,
.notice {
  margin-top: 12px;
  border-radius: 10px;
  border: 1px solid var(--accent-500);
  background: rgba(185, 167, 121, 0.15);
  color: var(--primary-900);
  padding: 10px;
}

.hint {
  margin-top: 14px;
  color: var(--text-700);
  font-size: 0.8rem;
}

.footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--primary-900);
  color: #fff;
  margin-inline: -22px;
  padding: 14px 22px max(14px, env(safe-area-inset-bottom));
  margin-top: 0;
  font-size: 0.84rem;
}

.footer a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--accent-500);
  text-decoration: none;
  font-weight: 600;
}

.footer a svg {
  width: 14px;
  height: 14px;
}

.footer-links a {
  margin-left: 12px;
}

.footer-guest {
  position: relative;
  z-index: 1;
  width: min(1040px, calc(100% - 40px));
  justify-self: center;
  margin-top: 16px;
  background: transparent;
  color: var(--muted);
  padding: 0;
}

.footer-guest a {
  color: var(--primary-800);
}

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

  .side-nav {
    position: sticky;
    top: 0;
    height: auto;
    z-index: 15;
    border-radius: 0 0 14px 14px;
  }

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

  .logout {
    position: static;
    display: inline-flex;
    margin-top: 12px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .module-hero,
  .workspace-grid,
  .document-workspace,
  .knowledge-workspace {
    grid-template-columns: 1fr;
  }

  .hero-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  .content {
    padding: 14px 14px 0;
  }

  .content-scroll {
    padding-bottom: 18px;
  }

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

  .footer {
    margin-inline: -14px;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .module-hero {
    align-items: stretch;
  }

  .hero-actions,
  .module-tabs,
  .mini-tabs {
    flex-direction: column;
  }

  .detail-list {
    grid-template-columns: 1fr;
  }

  .login-shell {
    padding: 0;
    place-items: center;
    min-height: 100svh;
    overflow-y: auto;
    background:
      radial-gradient(circle at 50% -10%, rgba(185, 167, 121, 0.24), transparent 36%),
      linear-gradient(180deg, #002623, #0c1f1d 58%, #061411);
  }

  .login-grid,
  .login-brand-pane,
  .login-shell .footer-guest {
    display: none;
  }

  .login-panel {
    width: 100%;
    max-width: 432px;
    min-height: 100svh;
    grid-template-columns: 1fr;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
  }

  .login-card {
    align-self: center;
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: max(32px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
    color: #f5f2ec;
    background: transparent;
  }

  .login-mobile-brand {
    display: flex;
    margin-bottom: 26px;
  }

  .login-mobile-brand .login-logo {
    width: 38px;
    height: 38px;
    border-radius: 10px;
  }

  .login-card .brand {
    color: #f5f2ec;
    font-size: 1.22rem;
  }

  .login-card .subtitle,
  .login-card .hint,
  .login-card .check-row {
    color: #a09280;
  }

  .login-card .login-form label {
    color: #d6cfc2;
    font-size: 0.72rem;
    font-weight: 700;
  }

  .login-card .form-control,
  .login-card .login-form input[type="text"],
  .login-card .login-form input[type="email"],
  .login-card .login-form input[type="password"] {
    min-height: 42px;
    padding: 10px 13px;
    color: #f5f2ec;
    background: rgba(12, 31, 29, 0.92);
    border-color: rgba(185, 167, 121, 0.2);
    border-radius: 10px;
  }

  .login-card .form-control::placeholder {
    color: #7a6e5e;
  }

  .login-card .form-control:focus,
  .login-card .login-form input:focus {
    color: #f5f2ec;
    background: rgba(12, 31, 29, 0.96);
    border-color: #b9a779;
    box-shadow: 0 0 0 3px rgba(185, 167, 121, 0.18);
  }

  .login-card .login-main-action {
    color: #002623;
    background: #b9a779;
  }

  .login-card .login-main-action:hover {
    background: #c8b98d;
  }

  .login-card .check-row input {
    accent-color: #b9a779;
  }

.login-card code {
    background: rgba(245, 242, 236, 0.1);
    color: #f5f2ec;
  }
}

/* Final modal overrides keep legacy page rules on the shared form system. */
.agent-form .form-section,
.structure-form .form-section,
.kb-form .form-section,
.purchase-form .form-section,
.contact-editor-form .form-section {
  gap: 14px;
  padding: 18px;
  border-radius: 8px;
}

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

.agent-modal-card,
.document-modal-card {
  width: min(1040px, calc(100vw - 32px));
  max-height: min(900px, calc(100svh - 32px));
}

@media (max-width: 760px) {
  .agent-form .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
