:root {
  --bg: #090d12;
  --bg-raised: #0e141b;
  --panel: #131b24;
  --panel-strong: #18232e;
  --line: #2b3947;
  --line-strong: #465667;
  --text: #edf2f5;
  --muted: #a6b2bd;
  --muted-dark: #7e8d9a;
  --blue: #74a2c7;
  --copper: #d68a5b;
  --copper-light: #efb083;
  --green: #83aa9b;
  --red: #d88b82;
  --yellow: #d7bd79;
  --sans: "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  --shell: 1180px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
}

body::before {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: 3px;
  background: var(--copper);
  content: "";
  pointer-events: none;
}

a {
  color: inherit;
}

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

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

:focus-visible {
  outline: 3px solid var(--copper-light);
  outline-offset: 3px;
}

::selection {
  background: var(--copper);
  color: #11161c;
}

.portal-shell {
  width: min(calc(100% - 3rem), var(--shell));
  margin-inline: auto;
}

.skip-link {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 100;
  padding: 0.75rem 1rem;
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  transform: translateY(-180%);
}

.skip-link:focus {
  transform: translateY(0);
}

.portal-header {
  position: sticky;
  top: 0;
  z-index: 30;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 13, 18, 0.97);
}

.header-row {
  display: flex;
  min-height: 4.75rem;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
}

.portal-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.85rem;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 2.6rem;
  height: 2.6rem;
  place-items: center;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--copper-light);
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: -0.08em;
}

.brand-words {
  display: grid;
  line-height: 1.2;
}

.brand-words strong {
  font-size: 0.98rem;
  letter-spacing: -0.015em;
}

.brand-words span {
  margin-top: 0.22rem;
  color: var(--muted-dark);
  font-family: var(--mono);
  font-size: 0.68rem;
  text-transform: uppercase;
}

.portal-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.portal-nav a,
.nav-button,
.back-link {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 650;
  text-decoration: none;
}

.portal-nav a:hover,
.nav-button:hover,
.back-link:hover {
  color: var(--text);
}

.portal-nav form {
  margin: 0;
}

.nav-button {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line-strong);
  color: var(--blue);
  font-family: var(--mono);
  font-size: 0.7rem;
  text-transform: uppercase;
}

.portal-main {
  min-height: calc(100vh - 10rem);
  padding: clamp(2.5rem, 6vw, 5rem) 0 5rem;
}

.portal-footer {
  padding: 1.5rem 0;
  border-top: 1px solid var(--line);
  color: var(--muted-dark);
  font-family: var(--mono);
  font-size: 0.67rem;
  text-transform: uppercase;
}

.portal-footer .portal-shell {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

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

h1,
h2,
h3 {
  line-height: 1.08;
}

h1 {
  margin-bottom: 1.15rem;
  font-size: clamp(2.4rem, 7vw, 5.25rem);
  font-weight: 760;
  letter-spacing: -0.065em;
}

h2 {
  margin-bottom: 0.8rem;
  font-size: clamp(1.45rem, 3vw, 2.15rem);
  letter-spacing: -0.035em;
}

h3 {
  font-size: 1.12rem;
}

.kicker,
.panel-label {
  margin-bottom: 0.85rem;
  color: var(--copper-light);
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel-label {
  color: var(--blue);
}

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 3rem;
  margin-bottom: clamp(2.5rem, 5vw, 4rem);
}

.page-heading > div:first-child {
  max-width: 51rem;
}

.page-heading > div:first-child > p:last-child {
  max-width: 45rem;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.08rem;
}

.page-heading h1 {
  overflow-wrap: anywhere;
}

.account-stamp {
  display: grid;
  min-width: 14rem;
  padding: 1rem 1.15rem;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--copper);
  background: var(--bg-raised);
}

.account-stamp span,
.account-stamp small {
  color: var(--muted-dark);
  font-family: var(--mono);
  font-size: 0.65rem;
  text-transform: uppercase;
}

.account-stamp strong {
  margin: 0.3rem 0 0.1rem;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.95rem;
}

.heading-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.75rem;
}

.button {
  display: inline-flex;
  min-height: 3rem;
  align-items: center;
  justify-content: center;
  padding: 0.76rem 1rem;
  border: 1px solid transparent;
  border-radius: 1px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.015em;
  line-height: 1.3;
  text-align: center;
  text-decoration: none;
}

.button-primary {
  border-color: var(--copper);
  background: var(--copper);
  color: #11161c;
}

.button-primary:hover {
  border-color: var(--copper-light);
  background: var(--copper-light);
}

.button-secondary {
  border-color: var(--line-strong);
  background: var(--panel);
  color: var(--text);
}

.button-secondary:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.button-small {
  min-height: 2.5rem;
  padding: 0.55rem 0.75rem;
  font-size: 0.66rem;
}

.text-action {
  color: var(--blue);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  text-decoration: none;
  text-transform: uppercase;
}

.text-action:hover {
  color: var(--text);
}

.notice {
  margin-bottom: 1.5rem;
  padding: 0.95rem 1rem;
  border: 1px solid var(--line-strong);
  border-left-width: 3px;
  background: var(--bg-raised);
  color: var(--muted);
}

.notice strong {
  color: var(--text);
}

.notice ul {
  margin: 0.5rem 0 0;
  padding-left: 1.2rem;
}

.notice-error {
  border-left-color: var(--red);
}

.notice-success {
  border-left-color: var(--green);
}

.notice-warning {
  border-left-color: var(--yellow);
}

.auth-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(20rem, 0.62fr);
  align-items: start;
  gap: clamp(3rem, 8vw, 7rem);
}

.auth-intro {
  padding-top: clamp(1rem, 5vw, 4rem);
}

.auth-intro h1 {
  max-width: 12ch;
}

.auth-intro > p:not(.kicker) {
  max-width: 39rem;
  color: var(--muted);
  font-size: 1.08rem;
}

.privacy-note {
  max-width: 36rem;
  margin-top: 3rem;
  padding: 1rem 0 0 1.2rem;
  border-top: 1px solid var(--line);
  border-left: 2px solid var(--green);
}

.privacy-note strong {
  display: block;
  margin-bottom: 0.25rem;
}

.privacy-note p {
  margin-bottom: 0;
  color: var(--muted-dark);
  font-size: 0.88rem;
}

.form-panel,
.content-panel,
.ledger-panel,
.form-section,
.message-card {
  border: 1px solid var(--line);
  background: var(--panel);
}

.form-panel {
  padding: clamp(1.4rem, 4vw, 2.3rem);
  box-shadow: 0.7rem 0.7rem 0 var(--bg-raised);
}

.form-panel h2 {
  margin-bottom: 1.5rem;
}

.form-panel code {
  color: var(--copper-light);
  font-family: var(--mono);
}

.field {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 1.15rem;
}

.field label {
  color: var(--text);
  font-size: 0.83rem;
  font-weight: 700;
}

.field label span {
  color: var(--muted-dark);
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 1px;
  background: var(--bg-raised);
  color: var(--text);
}

.field input,
.field select {
  min-height: 3rem;
  padding: 0.68rem 0.78rem;
}

.field textarea {
  min-height: 8rem;
  padding: 0.75rem 0.78rem;
  line-height: 1.55;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--copper-light);
  outline: 0;
  box-shadow: 0 0 0 2px rgba(239, 176, 131, 0.18);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--muted-dark);
  opacity: 1;
}

.field-help,
.form-footnote,
.panel-note,
.table-note {
  margin-bottom: 0;
  color: var(--muted-dark);
  font-size: 0.78rem;
}

.form-footnote {
  margin-top: 1.3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

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

.check-field {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.86rem;
}

.check-field input {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--copper);
}

.docket {
  display: grid;
  grid-template-columns: minmax(11rem, 0.28fr) minmax(0, 1fr);
  margin-bottom: 2rem;
  border: 1px solid var(--line-strong);
  background: var(--panel);
}

.docket-rail {
  display: flex;
  min-height: 18rem;
  flex-direction: column;
  justify-content: space-between;
  padding: 1.4rem;
  border-right: 1px solid var(--line-strong);
  background: var(--bg-raised);
}

.docket-rail span {
  color: var(--copper-light);
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  writing-mode: vertical-rl;
}

.docket-rail strong {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.docket-body {
  padding: clamp(1.4rem, 4vw, 2.2rem);
}

.section-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 2rem;
  margin-bottom: 1.5rem;
}

.section-heading h2 {
  margin-bottom: 0;
}

.status-tag {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--line-strong);
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-active {
  border-color: rgba(131, 170, 155, 0.55);
  color: var(--green);
}

.status-open {
  border-color: rgba(239, 176, 131, 0.55);
  color: var(--copper-light);
}

.status-inactive {
  color: var(--muted-dark);
}

.account-ledger,
.compact-ledger {
  margin: 0;
}

.account-ledger {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.account-ledger > div {
  min-height: 7rem;
  padding: 1rem;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.account-ledger dt,
.compact-ledger dt,
.message-title dt {
  margin-bottom: 0.4rem;
  color: var(--muted-dark);
  font-family: var(--mono);
  font-size: 0.65rem;
  text-transform: uppercase;
}

.account-ledger dd,
.compact-ledger dd,
.message-title dd {
  margin: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

.account-ledger dd {
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: 650;
}

.portal-grid {
  display: grid;
  grid-template-columns: minmax(16rem, 0.68fr) minmax(0, 1fr);
  gap: 2rem;
}

.content-panel {
  padding: clamp(1.35rem, 4vw, 2rem);
}

.content-panel > p:not(.panel-label):not(.panel-note) {
  color: var(--muted);
}

.compact-ledger > div {
  display: grid;
  grid-template-columns: 8rem minmax(0, 1fr);
  gap: 1rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
}

.compact-ledger dt {
  margin: 0;
}

.panel-note {
  margin-top: 1.2rem;
}

.contact-panel {
  border-top-color: var(--copper);
}

.ledger-panel {
  padding: clamp(1.25rem, 3vw, 2rem);
}

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

.client-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.client-table th {
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--line-strong);
  color: var(--muted-dark);
  font-family: var(--mono);
  font-size: 0.61rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.client-table td {
  padding: 1rem 0.8rem;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.84rem;
  vertical-align: top;
}

.client-table tbody tr:hover {
  background: var(--bg-raised);
}

.client-table td strong,
.client-table td small {
  display: block;
}

.client-table td strong {
  color: var(--text);
}

.client-table td small {
  margin-top: 0.2rem;
  color: var(--muted-dark);
}

.client-table .message-count {
  color: var(--copper-light);
}

.action-cell {
  text-align: right;
}

.empty-state {
  padding: clamp(2rem, 6vw, 4rem);
  border: 1px dashed var(--line-strong);
  text-align: center;
}

.empty-state p {
  color: var(--muted);
}

.admin-client-form {
  display: grid;
  gap: 1.5rem;
}

.form-section {
  display: grid;
  grid-template-columns: minmax(13rem, 0.42fr) minmax(0, 1fr);
  gap: clamp(2rem, 6vw, 5rem);
  padding: clamp(1.4rem, 4vw, 2.2rem);
}

.form-section-intro p:not(.panel-label) {
  max-width: 26rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.sticky-actions {
  position: sticky;
  bottom: 1rem;
  z-index: 10;
  display: flex;
  width: fit-content;
  gap: 0.75rem;
  padding: 0.7rem;
  border: 1px solid var(--line-strong);
  background: rgba(9, 13, 18, 0.96);
}

.message-list {
  display: grid;
  gap: 1.25rem;
}

.message-card {
  padding: clamp(1.25rem, 4vw, 2rem);
  border-left: 3px solid var(--copper);
}

.message-card.message-handled {
  border-left-color: var(--line-strong);
  opacity: 0.82;
}

.message-card > header,
.message-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 2rem;
}

.message-meta {
  display: inline;
  margin: 0 0 0 0.55rem;
  color: var(--muted-dark);
  font-family: var(--mono);
  font-size: 0.65rem;
}

.message-title {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.message-title dl {
  min-width: 16rem;
  margin: 0;
}

.message-title dl > div + div {
  margin-top: 0.65rem;
}

.message-body {
  max-width: 52rem;
  margin: 1.5rem 0;
  padding: 1rem 1.2rem;
  border-left: 2px solid var(--blue);
  background: var(--bg-raised);
  color: var(--muted);
  white-space: normal;
}

.narrow-page {
  max-width: 47rem;
  margin-inline: auto;
}

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

@media (max-width: 920px) {
  .header-row {
    align-items: flex-start;
    padding-block: 1rem;
  }

  .portal-nav {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.7rem 1rem;
  }

  .auth-layout,
  .portal-grid,
  .form-section {
    grid-template-columns: 1fr;
  }

  .auth-intro {
    padding-top: 0;
  }

  .auth-intro h1 {
    max-width: 15ch;
  }

  .docket {
    grid-template-columns: 8rem minmax(0, 1fr);
  }

  .form-section {
    gap: 1rem;
  }

  .form-section-intro p:not(.panel-label) {
    max-width: 42rem;
  }

  .client-table {
    min-width: 870px;
  }
}

@media (max-width: 680px) {
  .portal-shell {
    width: min(calc(100% - 1.5rem), var(--shell));
  }

  .portal-header {
    position: static;
  }

  .header-row {
    display: grid;
  }

  .portal-nav {
    justify-content: flex-start;
  }

  .portal-nav a,
  .nav-button {
    min-height: 2.65rem;
    display: inline-flex;
    align-items: center;
  }

  .portal-main {
    padding: 2.5rem 0 4rem;
  }

  .page-heading {
    display: grid;
    align-items: start;
    gap: 1.5rem;
  }

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

  .account-stamp {
    min-width: 0;
  }

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

  .docket-rail {
    min-height: 0;
    gap: 0.8rem;
    border-right: 0;
    border-bottom: 1px solid var(--line-strong);
  }

  .docket-rail span {
    writing-mode: horizontal-tb;
  }

  .account-ledger,
  .field-row {
    grid-template-columns: 1fr;
  }

  .account-ledger > div {
    min-height: 0;
  }

  .compact-ledger > div {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }

  .section-heading,
  .message-card > header,
  .message-title {
    display: grid;
    gap: 1rem;
  }

  .table-wrap {
    overflow: visible;
  }

  .client-table,
  .client-table tbody,
  .client-table tr,
  .client-table td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .client-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    clip: rect(0 0 0 0);
    overflow: hidden;
  }

  .client-table tr {
    padding: 0.5rem 0;
    border-top: 1px solid var(--line-strong);
  }

  .client-table tr:last-child {
    border-bottom: 1px solid var(--line-strong);
  }

  .client-table td {
    display: grid;
    grid-template-columns: 7rem minmax(0, 1fr);
    gap: 0.8rem;
    padding: 0.65rem 0;
    border: 0;
  }

  .client-table td::before {
    color: var(--muted-dark);
    content: attr(data-label);
    font-family: var(--mono);
    font-size: 0.61rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  .client-table .action-cell {
    display: block;
    padding: 0.85rem 0;
    text-align: left;
  }

  .client-table .action-cell::before {
    display: none;
  }

  .message-title dl {
    min-width: 0;
  }

  .sticky-actions {
    position: static;
    width: 100%;
    flex-direction: column;
  }

  .sticky-actions .button {
    width: 100%;
  }

  .portal-footer .portal-shell {
    display: grid;
  }
}

@media (max-width: 460px) {
  h1 {
    font-size: clamp(2.25rem, 14vw, 3.4rem);
  }

  .brand-words span {
    display: none;
  }

  .portal-nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .portal-nav a,
  .portal-nav form,
  .nav-button {
    width: 100%;
  }

  .portal-nav a,
  .nav-button {
    justify-content: center;
    padding-inline: 0.45rem;
    border: 1px solid var(--line);
    font-size: 0.7rem;
  }

  .form-panel,
  .content-panel,
  .ledger-panel,
  .form-section,
  .message-card,
  .docket-body {
    padding: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
