:root {
  --ink: #14221f;
  --muted: #5f6e69;
  --subtle: #84918d;
  --green-950: #0d2e29;
  --green-900: #123c35;
  --green-800: #1a554a;
  --green-700: #237062;
  --green-100: #dfece7;
  --green-50: #f2f7f5;
  --blue-700: #275f80;
  --blue-100: #e2eef4;
  --gold-700: #8b6718;
  --gold-100: #f7eccd;
  --red-700: #a23b3b;
  --red-100: #f8e1df;
  --surface: #ffffff;
  --canvas: #f4f6f5;
  --line: #d9e0dd;
  --line-strong: #bcc8c3;
  --shadow: 0 10px 28px rgba(13, 46, 41, 0.12);
  --sidebar-width: 248px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--canvas);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--green-800);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(39, 95, 128, 0.28);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.wordmark {
  color: var(--green-900);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
}

.wordmark.inverse {
  color: #ffffff;
}

.auth-view {
  min-height: 100vh;
  display: block;
  background:
    linear-gradient(90deg, rgba(13, 46, 41, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(13, 46, 41, 0.035) 1px, transparent 1px),
    #f4f7f6;
  background-size: 32px 32px;
}

.auth-main {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 48px 22px;
}

.sign-in-panel {
  width: min(100%, 440px);
  padding: 38px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--green-700);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.sign-in-panel h1 {
  margin: 24px 0 26px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(30px, 6vw, 42px);
  line-height: 1.05;
  letter-spacing: 0;
}

.loading-view {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
}

.loading-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--green-900);
  border-radius: 50%;
  font: 700 28px/1 Georgia, serif;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.55; transform: scale(0.96); }
}

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

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: var(--sidebar-width);
  display: grid;
  grid-template-rows: auto 1fr auto;
  color: #fff;
  background: var(--green-950);
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-brand {
  min-height: 80px;
  padding: 20px 22px;
  display: grid;
  align-content: center;
  gap: 5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-brand span {
  color: #a8c2ba;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.primary-nav {
  padding: 18px 12px;
  overflow-y: auto;
}

.nav-button {
  width: 100%;
  min-height: 42px;
  margin: 2px 0;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #c7d8d3;
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
}

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

.nav-button.active {
  color: #fff;
  background: var(--green-700);
}

.nav-count {
  min-width: 24px;
  height: 20px;
  padding: 0 6px;
  display: inline-grid;
  place-items: center;
  color: #d8e9e4;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  font-size: 11px;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.user-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.user-summary span:last-child {
  min-width: 0;
  display: grid;
}

.user-summary strong,
.user-summary small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-summary strong {
  font-size: 13px;
}

.user-summary small {
  margin-top: 2px;
  color: #a8c2ba;
  font-size: 11px;
}

.avatar {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--green-950);
  background: #cfe3dc;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.avatar.small {
  flex-basis: 30px;
  width: 30px;
  height: 30px;
}

.main-content {
  min-width: 0;
  grid-column: 2;
  padding: 0 clamp(20px, 3vw, 42px);
}

.mobile-header {
  display: none;
}

.page-header {
  min-height: 108px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
}

.page-header h1 {
  margin: 3px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--green-700);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.session-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #3d9275;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(61, 146, 117, 0.14);
}

.workspace {
  min-height: calc(100vh - 166px);
  padding: 26px 0 40px;
}

.app-footer {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--subtle);
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.metric {
  min-width: 0;
  padding: 22px;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric strong {
  display: block;
  margin-bottom: 6px;
  font: 700 28px/1 Georgia, serif;
}

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

.content-grid {
  margin-top: 22px;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr);
  gap: 22px;
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.spaced-panel {
  margin-top: 22px;
}

.panel-header {
  min-height: 60px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2,
.panel-header h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.3;
}

.panel-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.panel-body {
  padding: 18px;
}

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

.attention-item,
.activity-item,
.security-item {
  min-height: 58px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.attention-item:last-child,
.activity-item:last-child,
.security-item:last-child {
  border-bottom: 0;
}

.attention-item strong,
.activity-item strong,
.security-item strong {
  display: block;
  margin-bottom: 3px;
  font-size: 13px;
}

.attention-item span,
.activity-item span,
.security-item span {
  color: var(--muted);
  font-size: 12px;
}

.count-value {
  color: var(--ink) !important;
  font: 700 22px/1 Georgia, serif !important;
}

.toolbar {
  margin-bottom: 16px;
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar .search-field {
  width: min(100%, 340px);
}

.toolbar .filter-field {
  width: 190px;
}

.toolbar .button:last-child {
  margin-left: auto;
}

.field {
  display: grid;
  gap: 6px;
}

.field label,
.field > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.input,
.select,
.textarea {
  width: 100%;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
}

.input,
.select {
  height: 40px;
  padding: 0 11px;
}

.textarea {
  min-height: 112px;
  padding: 10px 11px;
  resize: vertical;
  line-height: 1.5;
}

.input::placeholder {
  color: #929e9a;
}

.button,
.icon-button,
.text-button {
  border: 0;
  cursor: pointer;
}

.button {
  min-height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
}

.button:hover {
  background: var(--green-50);
}

.button.primary {
  color: #fff;
  background: var(--green-800);
  border-color: var(--green-800);
}

.button.primary:hover {
  background: var(--green-900);
}

.button.danger {
  color: var(--red-700);
  border-color: #dfb8b5;
}

.button.full {
  width: 100%;
}

.button.quiet {
  background: transparent;
}

.inverse-button {
  width: 100%;
  min-height: 34px;
  margin-top: 14px;
  color: #c7d8d3;
  border-color: rgba(255, 255, 255, 0.2);
}

.inverse-button:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
}

.icon-button {
  min-height: 36px;
  padding: 0 10px;
  color: var(--muted);
  background: transparent;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
}

.icon-button:hover {
  color: var(--ink);
  background: var(--green-50);
}

.text-button {
  padding: 0;
  color: var(--green-800);
  background: transparent;
  font-weight: 750;
  text-decoration: underline;
}

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

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  height: 42px;
  padding: 0 14px;
  color: var(--muted);
  background: #f8faf9;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 800;
  text-align: left;
  white-space: nowrap;
}

.data-table td {
  min-height: 56px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr[data-record-id] {
  cursor: pointer;
}

.data-table tbody tr[data-record-id]:hover {
  background: var(--green-50);
}

.primary-cell {
  min-width: 180px;
}

.primary-cell strong,
.primary-cell span {
  display: block;
}

.primary-cell span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  color: var(--green-800);
  background: var(--green-100);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 800;
  text-transform: capitalize;
  white-space: nowrap;
}

.status-badge.warn,
.status-badge.needs-info,
.status-badge.in-review,
.status-badge.pending-confirmation,
.status-badge.pending {
  color: var(--gold-700);
  background: var(--gold-100);
}

.status-badge.rejected,
.status-badge.disabled,
.status-badge.closed {
  color: var(--red-700);
  background: var(--red-100);
}

.status-badge.submitted,
.status-badge.reviewer,
.status-badge.auditor {
  color: var(--blue-700);
  background: var(--blue-100);
}

.pagination {
  min-height: 58px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--line);
}

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

.pagination-controls {
  display: flex;
  gap: 8px;
}

.empty-state,
.loading-state,
.error-state {
  min-height: 220px;
  padding: 32px;
  display: grid;
  place-content: center;
  justify-items: center;
  color: var(--muted);
  text-align: center;
}

.empty-state h2,
.error-state h2 {
  margin: 0 0 8px;
  color: var(--ink);
  font: 700 21px/1.2 Georgia, serif;
}

.empty-state p,
.error-state p {
  margin: 0 0 16px;
}

.skeleton-lines {
  width: 100%;
  display: grid;
  gap: 10px;
}

.skeleton-line {
  height: 50px;
  background: linear-gradient(90deg, #edf1ef 25%, #f7f9f8 50%, #edf1ef 75%);
  background-size: 200% 100%;
  border-radius: 4px;
  animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer {
  to { background-position: -200% 0; }
}

.detail-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: min(88vh, 920px);
  margin: auto;
  padding: 0;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  box-shadow: 0 24px 70px rgba(13, 46, 41, 0.28);
}

.detail-dialog::backdrop {
  background: rgba(11, 28, 24, 0.58);
}

.dialog-frame {
  max-height: min(88vh, 920px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.dialog-header {
  min-height: 74px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  margin: 3px 0 0;
  font: 700 23px/1.2 Georgia, serif;
}

.dialog-content {
  overflow-y: auto;
  padding: 22px;
}

.detail-section + .detail-section {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.detail-section h3 {
  margin: 0 0 14px;
  font-size: 14px;
}

.detail-grid {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 24px;
}

.detail-grid > div {
  min-width: 0;
}

.detail-grid dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.detail-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.5;
}

.detail-grid .wide {
  grid-column: 1 / -1;
}

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

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

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

.document-row {
  padding: 13px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px auto;
  align-items: center;
  gap: 10px;
  background: #f8faf9;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.document-name {
  min-width: 0;
}

.document-name strong,
.document-name span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-notes {
  grid-column: 1 / -1;
}

.document-name span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.inline-alert {
  margin: 16px 0;
  padding: 12px 14px;
  color: var(--blue-700);
  background: var(--blue-100);
  border-left: 3px solid var(--blue-700);
  font-size: 13px;
  line-height: 1.5;
}

.inline-alert.warning {
  color: var(--gold-700);
  background: var(--gold-100);
  border-left-color: var(--gold-700);
}

.inline-alert.danger {
  color: var(--red-700);
  background: var(--red-100);
  border-left-color: var(--red-700);
}

.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  width: min(360px, calc(100vw - 40px));
  display: grid;
  gap: 10px;
}

.toast {
  padding: 13px 15px;
  color: #fff;
  background: var(--green-950);
  border-radius: 5px;
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.45;
}

.toast.error {
  background: #792c2c;
}

.split-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  align-items: end;
  gap: 12px;
}

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

.control-item {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #f8faf9;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.control-item strong {
  font-size: 13px;
}

.control-state {
  color: var(--green-700);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

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

  .metric:nth-child(2) {
    border-right: 0;
  }

  .metric:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

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

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

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    width: min(300px, 88vw);
    transform: translateX(-102%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 15;
    min-height: 58px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
  }

  .mobile-header .wordmark {
    font-size: 24px;
  }

  .main-content {
    padding: 0 16px;
  }

  .page-header {
    min-height: 92px;
  }

  .page-header h1 {
    font-size: 26px;
  }

  .session-status {
    display: none;
  }

  .workspace {
    padding-top: 18px;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar .search-field,
  .toolbar .filter-field {
    width: 100%;
  }

  .toolbar .button:last-child {
    margin-left: 0;
  }

  .detail-grid,
  .control-grid,
  .split-form {
    grid-template-columns: 1fr;
  }

  .document-row {
    grid-template-columns: 1fr;
  }

  .dialog-content {
    padding: 18px;
  }
}

@media (max-width: 520px) {
  .sign-in-panel {
    padding: 28px 22px;
  }

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

  .metric {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .metric:nth-child(2) {
    border-right: 0;
  }

  .metric:nth-child(-n + 3) {
    border-bottom: 1px solid var(--line);
  }

  .metric:last-child {
    border-bottom: 0;
  }

  .pagination {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-footer {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
