:root {
  --bg: #f6f4ee;
  --surface: #fffefa;
  --surface-strong: #ffffff;
  --ink: #1d241f;
  --muted: #66736b;
  --line: #d8d4c8;
  --primary: #0f6b5f;
  --primary-dark: #094a42;
  --accent: #b97721;
  --danger: #b42318;
  --success: #1f7a4d;
  --warning: #a16207;
  --shadow: 0 16px 40px rgba(28, 34, 29, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(15, 107, 95, 0.06), transparent 32rem),
    var(--bg);
  font-family: Aptos, "Segoe UI", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

a {
  color: var(--primary-dark);
  text-decoration: none;
}

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

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 17rem 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 1.25rem;
  background: #17231f;
  color: #f5f1e7;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: inherit;
}

.brand-mark {
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid rgba(255, 255, 255, 0.35);
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #f5e6bf;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.08);
}

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

.brand small {
  color: rgba(245, 241, 231, 0.68);
  font-size: 0.78rem;
}

.nav {
  display: grid;
  gap: 0.2rem;
}

.nav a {
  color: rgba(245, 241, 231, 0.78);
  padding: 0.68rem 0.75rem;
  border-radius: 8px;
}

.nav a:hover,
.nav a:focus-visible {
  color: #fffefa;
  background: rgba(255, 255, 255, 0.09);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 0.8rem;
}

.sidebar-footer strong,
.sidebar-footer small {
  display: block;
}

.sidebar-footer small {
  color: rgba(245, 241, 231, 0.68);
}

.content {
  padding: 2rem;
  width: min(100%, 1280px);
}

.content-auth {
  min-height: 100vh;
  width: 100%;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

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

h1 {
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 0.98;
  margin-bottom: 0;
}

h2 {
  font-size: 1rem;
  margin-bottom: 0;
}

.eyebrow {
  display: block;
  text-transform: uppercase;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  margin-bottom: 0.45rem;
}

.auth-panel,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel {
  width: min(100%, 28rem);
  padding: 2rem;
}

.auth-panel.wide {
  width: min(100%, 34rem);
}

.auth-heading {
  margin-bottom: 1.5rem;
}

.auth-heading h1 {
  font-size: 2.3rem;
}

.auth-heading p {
  color: var(--muted);
  margin: 0.5rem 0 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.metric {
  min-height: 7rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.metric span {
  color: var(--muted);
}

.metric strong {
  font-size: 2.2rem;
  line-height: 1;
}

.section-grid {
  display: grid;
  grid-template-columns: minmax(18rem, 0.8fr) minmax(0, 1.8fr);
  gap: 1rem;
  align-items: start;
}

.section-grid.reverse {
  grid-template-columns: minmax(0, 1.8fr) minmax(18rem, 0.8fr);
}

.section-grid.reverse > .panel:first-child {
  order: 2;
}

.panel {
  padding: 1rem;
}

.panel.narrow {
  max-width: 44rem;
}

.table-panel {
  overflow: hidden;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.form-grid {
  display: grid;
  gap: 1rem;
}

.form-grid.compact {
  gap: 0.85rem;
}

.two-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 2.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf7;
  color: var(--ink);
  padding: 0.65rem 0.75rem;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(15, 107, 95, 0.18);
  border-color: var(--primary);
}

.checkbox-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--ink);
}

.checkbox-row input {
  min-height: 0;
  width: 1rem;
  height: 1rem;
}

.button {
  min-height: 2.5rem;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.58rem 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-weight: 800;
  cursor: pointer;
}

.button.primary {
  background: var(--primary);
  color: white;
}

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

.button.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  border-color: rgba(255, 255, 255, 0.2);
}

.content .button.secondary {
  background: var(--surface-strong);
  color: var(--ink);
  border-color: var(--line);
}

.button.danger,
.button.tiny.danger {
  background: #fff2f0;
  color: var(--danger);
  border-color: #f1b9b3;
}

.button.tiny {
  min-height: 2rem;
  padding: 0.35rem 0.55rem;
  font-size: 0.82rem;
}

.button.full {
  width: 100%;
}

.text-link {
  font-weight: 800;
  color: var(--primary-dark);
}

.flash-stack {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.flash {
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
  font-weight: 700;
}

.flash.success {
  color: var(--success);
  border-color: rgba(31, 122, 77, 0.28);
}

.flash.error {
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.28);
}

.flash.warning {
  color: var(--warning);
  border-color: rgba(161, 98, 7, 0.28);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 44rem;
}

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

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

td small {
  display: block;
  color: var(--muted);
  margin-top: 0.2rem;
}

td.row-actions,
th.row-actions {
  text-align: right;
  white-space: nowrap;
}

td.row-actions > * {
  margin-left: 0.4rem;
}

td.row-actions form {
  display: inline-flex;
}

td.row-actions input[type="hidden"] {
  display: none;
}

.table-form {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.table-form select {
  min-height: 2rem;
  padding: 0.25rem 0.5rem;
}

.badge {
  min-width: 5.8rem;
  min-height: 1.75rem;
  padding: 0.28rem 0.48rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 800;
  background: #ece8dc;
  color: var(--ink);
}

.badge.completed,
.badge.active,
.badge.accepted,
.badge.superadmin {
  color: var(--success);
  background: #e7f5ed;
}

.badge.failed,
.badge.disabled,
.badge.revoked {
  color: var(--danger);
  background: #fff0ee;
}

.badge.processing,
.badge.queued,
.badge.invited,
.badge.pending,
.badge.admin {
  color: var(--warning);
  background: #fff6dd;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(18rem, 0.9fr);
  gap: 1rem;
  align-items: start;
}

.detail-list {
  display: grid;
  gap: 0.7rem;
  margin: 0;
}

.detail-list div {
  display: grid;
  grid-template-columns: 8rem 1fr;
  gap: 1rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--line);
}

.detail-list dt {
  color: var(--muted);
  font-weight: 800;
}

.detail-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.inline-form {
  margin-top: 1rem;
}

.error-box {
  border: 1px solid rgba(180, 35, 24, 0.24);
  background: #fff7f5;
  color: var(--danger);
  border-radius: 8px;
  padding: 0.85rem;
  margin-bottom: 1rem;
}

.error-box p {
  margin: 0.35rem 0 0;
  color: #64251d;
}

.error-cell {
  max-width: 28rem;
  overflow-wrap: anywhere;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 2rem;
}

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

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

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

  .content {
    padding: 1rem;
  }

  .metric-grid,
  .section-grid,
  .section-grid.reverse,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .section-grid.reverse > .panel:first-child {
    order: 0;
  }
}

@media (max-width: 560px) {
  .page-header,
  .header-actions,
  .two-columns,
  .detail-list div {
    grid-template-columns: 1fr;
  }

  .page-header {
    display: grid;
  }

  h1 {
    font-size: 2rem;
  }
}
