.admin-page {
  min-width: 320px;
}

/* Statistics */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg-container);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius);
}

.stat-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
}

.stat-icon .icon {
  width: 20px;
  height: 20px;
}

.stat-icon--review {
  background: var(--info-bg);
  color: var(--info);
}

.stat-icon--fix {
  background: var(--error-bg);
  color: var(--error);
}

.stat-icon--done {
  background: var(--success-bg);
  color: var(--success);
}

.stat-icon--draft {
  background: var(--fill-secondary);
  color: var(--text-secondary);
}

.stat-label {
  color: var(--text-secondary);
  font-size: 14px;
}

.stat-value {
  display: block;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.3;
}

/* Main grid */

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
}

.side-stack {
  display: grid;
  gap: 16px;
}

/* Tabs */

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

.tabs {
  display: flex;
  gap: 0;
  padding: 0 16px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border-secondary);
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  height: 46px;
  padding: 0 12px;
  border: 0;
  background: none;
  color: var(--text-secondary);
  font-size: 14px;
  white-space: nowrap;
}

.tab:hover {
  color: var(--primary);
}

.tab.is-active {
  color: var(--primary);
}

.tab.is-active::after {
  content: "";
  position: absolute;
  right: 12px;
  bottom: -1px;
  left: 12px;
  height: 2px;
  background: var(--primary);
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--fill-secondary);
  color: var(--text-secondary);
  font-size: 12px;
}

.tab.is-active .tab-count {
  background: var(--primary-bg);
  color: var(--primary);
}

/* Table toolbar */

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-secondary);
}

.table-toolbar .input-affix {
  flex: 1 1 220px;
  max-width: 280px;
}

.toolbar-select {
  width: 190px;
}

.table-toolbar > .btn {
  flex: none;
}

.toolbar-count {
  margin-left: auto;
  color: var(--text-tertiary);
  font-size: 14px;
  white-space: nowrap;
}

/* Table */

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

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

th {
  padding: 12px;
  border-bottom: 1px solid var(--border-secondary);
  background: var(--fill-alter);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

td {
  padding: 12px;
  border-bottom: 1px solid var(--border-secondary);
  vertical-align: middle;
}

td:nth-child(4),
td:nth-child(6),
td:last-child {
  white-space: nowrap;
}

th:last-child,
td:last-child {
  text-align: right;
}

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

tbody tr:hover {
  background: var(--fill-alter);
}

.person strong {
  display: block;
  font-size: 14px;
  font-weight: 500;
}

.person span {
  display: block;
  color: var(--text-tertiary);
  font-size: 12px;
}

.row-action {
  color: var(--primary);
  font-size: 14px;
  white-space: nowrap;
}

.row-action:hover {
  color: var(--primary-hover);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.empty-row td {
  padding: 0;
}

.empty-row .empty {
  padding: 48px 16px;
}

/* Side cards */

.client-list,
.activity-list {
  padding: 0;
  margin: 0;
  list-style: none;
}

.card-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.client-list li,
.activity-list li {
  border-bottom: 1px solid var(--border-secondary);
}

.client-list li {
  display: flex;
  align-items: center;
}

.client-list li:last-child,
.activity-list li:last-child {
  border-bottom: 0;
}

.client-row {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 10px 4px 10px 20px;
  border: 0;
  background: none;
  color: var(--text);
  font-size: 14px;
  text-align: left;
}

.client-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.client-row:hover {
  background: var(--fill-alter);
}

.client-row.is-active {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 500;
}

.client-row .count {
  color: var(--text-tertiary);
  font-weight: 400;
}

.client-row.is-active .count {
  color: var(--primary);
}

.client-edit {
  display: grid;
  flex: none;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-right: 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-tertiary);
}

.client-edit:hover {
  background: var(--fill-secondary);
  color: var(--primary);
}

.client-edit .icon {
  width: 14px;
  height: 14px;
}

.activity-button {
  display: block;
  width: 100%;
  padding: 10px 20px;
  border: 0;
  background: none;
  text-align: left;
}

.activity-button:hover {
  background: var(--fill-alter);
}

.activity-name {
  display: block;
  font-size: 14px;
  font-weight: 500;
}

.activity-state {
  margin-top: 4px;
}

.activity-list time {
  display: block;
  margin-top: 4px;
  color: var(--text-tertiary);
  font-size: 12px;
}

.side-empty {
  padding: 16px 20px;
  color: var(--text-tertiary);
  font-size: 14px;
}

/* Modals */

.modal {
  width: min(520px, calc(100% - 32px));
  max-height: calc(100% - 48px);
  padding: 0;
  margin: auto;
  border: 0;
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal[open] {
  display: flex;
  flex-direction: column;
  animation: modal-in 0.15s ease-out;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.modal-head {
  display: flex;
  flex: none;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 0;
}

.modal-title-wrap {
  min-width: 0;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.modal-sub {
  margin-top: 2px;
  color: var(--text-tertiary);
  font-size: 14px;
}

.modal-head-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

.modal-foot {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 24px;
  border-top: 1px solid var(--border-secondary);
}

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

/* Large case modal */

.modal-lg {
  width: min(1040px, calc(100% - 48px));
  height: min(90vh, 860px);
  max-height: calc(100% - 48px);
}

.modal-lg .modal-head {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-secondary);
}

.modal-lg .modal-body {
  flex: 1;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

.modal-body--split {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.9fr);
}

.case-main {
  min-width: 0;
  padding: 24px;
  overflow-y: auto;
}

.case-side {
  min-width: 0;
  padding: 20px;
  overflow-y: auto;
  border-left: 1px solid var(--border-secondary);
  background: var(--fill-alter);
}

.case-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.case-side-head h3 {
  font-size: 14px;
  font-weight: 600;
}

.case-side-head span {
  color: var(--text-tertiary);
  font-size: 12px;
}

.modal-foot--split {
  justify-content: space-between;
}

.case-reviewer {
  color: var(--text-tertiary);
  font-size: 13px;
}

.case-reviewer strong {
  color: var(--text-secondary);
  font-weight: 500;
}

.modal.modal-lg.is-pending {
  width: min(620px, calc(100% - 32px));
  height: fit-content;
}

.modal.is-pending .modal-body {
  flex: none;
}

.modal.is-pending .modal-body--split {
  display: block;
  overflow: visible;
}

.modal.is-pending .case-main {
  overflow: visible;
}

/* Case descriptions */

.case-meta {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 96px minmax(0, 1fr);
  margin: 0 0 20px;
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.case-meta > div {
  display: contents;
}

.case-meta dt {
  padding: 8px 12px;
  border-right: 1px solid var(--border-secondary);
  border-bottom: 1px solid var(--border-secondary);
  background: var(--fill-alter);
  color: var(--text-secondary);
  font-size: 13px;
}

.case-meta dd {
  padding: 8px 12px;
  margin: 0;
  border-right: 1px solid var(--border-secondary);
  border-bottom: 1px solid var(--border-secondary);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.case-meta > div:nth-child(2) dd,
.case-meta > div:nth-child(4) dd {
  border-right: 0;
}

.case-meta > div:nth-child(3) dt,
.case-meta > div:nth-child(3) dd,
.case-meta > div:nth-child(4) dt,
.case-meta > div:nth-child(4) dd {
  border-bottom: 0;
}

.profile-group {
  margin-top: 20px;
}

.profile-group h2 {
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
}

.profile-grid {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  padding: 0;
  margin: 0;
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.profile-item {
  display: contents;
}

.profile-item dt {
  padding: 8px 12px;
  border-right: 1px solid var(--border-secondary);
  border-bottom: 1px solid var(--border-secondary);
  background: var(--fill-alter);
  color: var(--text-secondary);
  font-size: 13px;
}

.profile-item dd {
  padding: 8px 12px;
  margin: 0;
  border-bottom: 1px solid var(--border-secondary);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.profile-item:last-child dt,
.profile-item:last-child dd {
  border-bottom: 0;
}

.case-pending {
  margin-top: 20px;
  padding: 12px 16px;
  border: 1px solid var(--warning-border);
  border-radius: var(--radius);
  background: var(--warning-bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* Documents */

.doc-list {
  padding: 0;
  margin: 0;
  list-style: none;
}

.doc-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-secondary);
}

.doc-list li:last-child {
  border-bottom: 0;
}

.doc-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius-sm);
  background: var(--bg-container);
  color: var(--text-tertiary);
}

.doc-icon .icon {
  width: 15px;
  height: 15px;
}

.doc-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.4;
}

.doc-open {
  flex: none;
  color: var(--primary);
  font-size: 14px;
}

.doc-open:hover {
  color: var(--primary-hover);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Link result */

.input-group {
  display: flex;
  gap: 8px;
}

.input-group .input {
  flex: 1;
  min-width: 0;
}

.copy-state {
  margin-top: 8px;
  color: var(--success-text);
  font-size: 14px;
}

#linkForm .modal-body {
  display: grid;
  gap: 16px;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Responsive */

@media (max-width: 1200px) {
  th:nth-child(3),
  td:nth-child(3),
  th:nth-child(6),
  td:nth-child(6) {
    display: none;
  }
}

@media (max-width: 1100px) {
  .content-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 900px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .modal-lg {
    width: calc(100% - 32px);
    height: 92vh;
    max-height: calc(100% - 24px);
  }

  .modal-body--split {
    display: block;
  }

  .modal-lg .modal-body {
    overflow-y: auto;
  }

  .case-main,
  .case-side {
    overflow: visible;
  }

  .case-side {
    border-top: 1px solid var(--border-secondary);
    border-left: 0;
  }
}

@media (max-width: 720px) {
  .table-toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .table-toolbar .input-affix,
  .toolbar-select {
    width: 100%;
    max-width: none;
  }

  .toolbar-count {
    margin-left: 0;
  }

  .table-toolbar > .btn {
    justify-self: start;
  }

  .side-stack {
    grid-template-columns: 1fr;
  }

  th:nth-child(2),
  td:nth-child(2),
  th:nth-child(4),
  td:nth-child(4) {
    display: none;
  }

  .page-head .btn {
    width: 100%;
  }

  .modal-head {
    padding: 16px 16px 0;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-foot {
    padding: 12px 16px;
  }

  .modal-lg .modal-head {
    padding-bottom: 12px;
  }

  .case-main {
    padding: 16px;
  }

  .case-side {
    padding: 16px;
  }

  .case-meta {
    grid-template-columns: 96px minmax(0, 1fr);
  }

  .case-meta dd {
    border-right: 0;
  }

  .case-meta > div:nth-child(3) dt,
  .case-meta > div:nth-child(3) dd {
    border-bottom: 1px solid var(--border-secondary);
  }

  .profile-grid {
    grid-template-columns: 120px minmax(0, 1fr);
  }

  .modal-foot--split {
    flex-wrap: wrap;
  }

  .modal-actions {
    width: 100%;
  }

  .modal-actions .btn {
    flex: 1;
    min-width: 0;
  }

  .case-reviewer {
    width: 100%;
  }

  .modal-lg {
    width: calc(100% - 16px);
    height: 94vh;
    max-height: calc(100% - 16px);
  }

  .modal.modal-lg.is-pending {
    width: calc(100% - 16px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .modal[open] {
    animation: none;
  }
}
