:root {
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-soft: #f9faf7;
  --ink: #1e2428;
  --muted: #687276;
  --border: #dfe4df;
  --primary: #255f63;
  --primary-dark: #17464a;
  --accent: #c47f2c;
  --green: #2f7d57;
  --red: #b5413c;
  --amber: #a9681d;
  --blue: #406a94;
  --shadow: 0 12px 28px rgba(35, 45, 50, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: #1f2b2e;
  color: #ffffff;
  padding: 22px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand strong {
  display: block;
  font-size: 1rem;
}

.brand small {
  display: block;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.74rem;
  margin-top: 2px;
}

.side-nav {
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.side-nav-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.side-nav-section-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.55);
  padding: 6px 12px 4px;
  font-weight: 700;
}

.side-nav a {
  text-decoration: none;
  color: rgba(255, 255, 255, 0.82);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.92rem;
  display: block;
}

.side-nav a.active,
.side-nav a:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.main-shell {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 {
  margin: 4px 0 0;
  font-size: clamp(1.45rem, 3vw, 2.05rem);
  line-height: 1.12;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 700;
}

.user-area {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.user-area small {
  display: block;
  color: var(--primary-dark);
  font-weight: 700;
  margin-top: 2px;
}

.content {
  padding: 28px 32px 48px;
}

.stats-grid,
.work-grid {
  display: grid;
  gap: 24px;
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 24px;
}

.stats-grid.compact {
  margin: 24px 0 0;
}

.work-grid {
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 0.65fr);
  align-items: start;
  margin-bottom: 24px;
  width: 100%;
  display: grid;
}

.work-grid.single {
  grid-template-columns: minmax(0, 1fr);
  margin-top: 4px;
}

.work-grid.gap-5 {
  margin-top: 120px;
}

.work-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.work-grid.two-two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel,
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.panel {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.panel.wide {
  min-width: 0;
}

.panel.full-width {
  grid-column: 1 / -1;
}

.stat-card {
  min-height: 118px;
  padding: 18px;
  display: grid;
  align-content: space-between;
}

.stat-card span {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.stat-card strong {
  margin-top: 8px;
  display: block;
  font-size: clamp(1.55rem, 3vw, 2.15rem);
  color: var(--primary-dark);
  line-height: 1;
}

.stat-card small {
  color: var(--muted);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.panel-heading-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.panel-heading.compact {
  align-items: flex-start;
  margin-bottom: 12px;
}

.panel-heading h2,
.panel-heading h3 {
  margin: 0;
  color: var(--ink);
  font-size: 1.05rem;
  line-height: 1.2;
}

.panel-heading p,
.knowledge-item p {
  margin: 4px 0 0;
  color: var(--muted);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  padding: 9px 14px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
}

.button.ghost {
  background: transparent;
  color: var(--primary-dark);
  border-color: var(--border);
}

.button.small {
  min-height: 30px;
  padding: 5px 12px;
  font-size: 0.8rem;
  border-radius: 999px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.button.small:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}

.hidden {
  display: none !important;
}

.gap-top-lg {
  margin-top: 40px;
}

.topbar .button.ghost {
  background: var(--surface);
}

.text-link {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}

.count-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 0.92rem;
}

th {
  color: var(--muted);
  background: var(--surface-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.72rem;
}

tr:last-child td {
  border-bottom: 0;
}

.subtext {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
  margin-top: 3px;
}

.muted {
  color: var(--muted);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-good {
  color: var(--green);
  background: #e8f3ed;
}

.status-warn {
  color: var(--amber);
  background: #fff4df;
}

.status-danger {
  color: var(--red);
  background: #fcecea;
}

.status-neutral {
  color: var(--blue);
  background: #edf3f8;
}

.form-stack {
  display: grid;
  gap: 13px;
}

.field-group {
  display: grid;
  gap: 6px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 95, 99, 0.14);
}

.lifecycle {
  display: grid;
  grid-template-columns: repeat(8, minmax(90px, 1fr));
  gap: 8px;
  overflow-x: auto;
}

.lifecycle a {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  border-radius: 8px;
  padding: 12px 10px;
  text-align: center;
  color: var(--primary-dark);
  font-weight: 800;
  font-size: 0.82rem;
  text-decoration: none;
}

.metric-list {
  margin: 0;
  display: grid;
  gap: 12px;
}

.metric-list div,
.bar-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.metric-list dt,
.bar-list span {
  color: var(--muted);
}

.metric-list dd {
  margin: 0;
  font-weight: 800;
  color: var(--primary-dark);
}

.stack-list {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.stack-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  text-decoration: none;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow-wrap: break-word;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.stack-item:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.stack-item span {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.knowledge-list {
  display: grid;
  gap: 14px;
}

.knowledge-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface-soft);
}

.problem-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.problem-grid div {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
}

.problem-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.support-grid {
  margin-top: 16px;
}

.content-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
}

.content-block h3 {
  margin: 0 0 8px;
  font-size: 0.96rem;
}

.content-block p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.workflow {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  gap: 8px;
  overflow-x: auto;
}

.workflow-step {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 10px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 800;
}

.workflow-step.done {
  color: var(--green);
  background: #e8f3ed;
  border-color: #c9e2d5;
}

.workflow-step.active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.message-list {
  display: grid;
  gap: 12px;
}

.message-item {
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
}

.message-item.internal {
  border-left-color: var(--accent);
}

.message-item > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.message-item p {
  margin: 10px 0;
  color: var(--muted);
  line-height: 1.5;
}

.message-item > span,
.article-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.article-meta {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.article-meta p {
  margin: 0;
}

.attachment-form {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.check-row input[type="checkbox"] {
  width: auto;
}

.filters-row {
  margin-bottom: 16px;
}

.search-row,
.inline-form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}

.button-row,
.table-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.table-actions {
  gap: 8px;
}

.form-grid.two,
.detail-grid,
.portal-invoice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.detail-grid {
  margin-bottom: 16px;
}

.detail-grid div,
.portal-invoice-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}

.detail-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 5px;
}

.detail-grid strong {
  color: var(--primary-dark);
}

.line-items {
  display: grid;
  gap: 10px;
}

.line-item-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.line-item-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.6fr) minmax(70px, 0.5fr) minmax(90px, 0.7fr) minmax(70px, 0.5fr) 36px;
  gap: 8px;
  align-items: end;
}

.icon-button {
  width: 36px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible {
  color: var(--red);
  border-color: #efc3bf;
  background: #fff8f7;
}

.search-row input {
  flex: 1;
}

.search-results {
  margin-top: 16px;
}

.bar-list {
  display: grid;
  gap: 12px;
}

.bar-list strong {
  color: var(--primary-dark);
}

.alert {
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-weight: 700;
}

.alert.success {
  background: #e8f3ed;
  color: var(--green);
}

.alert.error {
  background: #fcecea;
  color: var(--red);
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 27, 29, 0.55);
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 24px;
  scrollbar-width: none;
}

.modal::-webkit-scrollbar {
  display: none;
}

.modal-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.modal-heading h2 {
  margin: 0 0 4px;
}

.modal-close {
  border: none;
  background: var(--surface-soft);
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.modal-close:hover,
.modal-close:focus-visible {
  color: var(--red);
  background: #fff8f7;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: var(--surface-soft);
}

.login-page {
  background:
    linear-gradient(105deg, rgba(31, 43, 46, 0.98) 0%, rgba(31, 43, 46, 0.94) 48%, rgba(245, 246, 243, 0.98) 48%, rgba(245, 246, 243, 0.98) 100%),
    #1f2b2e;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 540px) minmax(360px, 460px);
  align-items: center;
  justify-content: center;
  gap: clamp(32px, 7vw, 92px);
  padding: clamp(28px, 6vw, 72px);
}

.login-intro {
  display: grid;
  gap: clamp(34px, 6vw, 70px);
  color: #fff;
}

.login-intro .brand-mark {
  width: 46px;
  height: 46px;
}

.login-intro .brand small {
  color: rgba(255, 255, 255, 0.72);
}

.login-copy {
  max-width: 500px;
}

.login-copy h1 {
  margin: 12px 0 14px;
  max-width: 10ch;
  color: #fff;
  font-size: 4rem;
  line-height: 0.98;
}

.login-copy p:last-child {
  margin: 0;
  max-width: 430px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 1rem;
  line-height: 1.6;
}

.login-panel {
  width: 100%;
  background: var(--surface);
  border-radius: 8px;
  padding: clamp(26px, 4vw, 38px);
  border: 1px solid rgba(223, 228, 223, 0.92);
  border-top: 4px solid var(--accent);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.18);
}

.login-brand {
  color: #fff;
}

.login-panel-header {
  margin-bottom: 22px;
}

.login-panel h2 {
  margin: 6px 0 0;
  font-size: 1.85rem;
  line-height: 1.1;
}

.login-panel .button {
  min-height: 48px;
  margin-top: 2px;
}

.login-panel .alert {
  margin-bottom: 0;
}

.login-panel input {
  min-height: 48px;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 52px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 7px;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.password-toggle:hover,
.password-toggle:focus-visible {
  color: var(--primary-dark);
  background: var(--surface-soft);
}

.password-toggle:focus-visible {
  outline: 2px solid rgba(37, 95, 99, 0.35);
  outline-offset: 2px;
}

.password-eye {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.password-eye-closed,
.password-toggle[aria-pressed="true"] .password-eye-open {
  display: none;
}

.password-toggle[aria-pressed="true"] .password-eye-closed {
  display: block;
}

.portal-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.portal-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: #1f2b2e;
  color: #ffffff;
  padding: 22px 16px;
}

.portal-sidebar .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.portal-sidebar .brand-mark {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.portal-sidebar .brand strong {
  display: block;
  font-size: 1rem;
}

.portal-sidebar .brand small {
  display: block;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.74rem;
  margin-top: 2px;
}

.portal-nav {
  margin-top: 26px;
  display: grid;
  gap: 4px;
}

.portal-nav a {
  text-decoration: none;
  color: rgba(255, 255, 255, 0.82);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.92rem;
}

.portal-nav a.active,
.portal-nav a:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.portal-client {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.82rem;
}

.portal-client strong {
  display: block;
  color: #fff;
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.portal-main {
  min-width: 0;
}

.portal-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.portal-topbar h1 {
  margin: 4px 0 0;
  font-size: clamp(1.45rem, 3vw, 2.05rem);
  line-height: 1.12;
}

.portal-content {
  padding: 28px 32px 48px;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .side-nav {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  }

  .stats-grid,
  .work-grid,
  .work-grid.three,
  .work-grid.two-two,
  .problem-grid,
  .portal-invoice-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .topbar,
  .panel-heading,
  .search-row,
  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

  .content,
  .topbar {
    padding-left: 18px;
    padding-right: 18px;
  }

  .stats-grid,
  .work-grid,
  .work-grid.three,
  .work-grid.two-two,
  .problem-grid,
  .form-grid.two,
  .detail-grid,
  .portal-invoice-grid,
  .line-item-row {
    grid-template-columns: 1fr;
  }

  .user-area {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 900px) {
  .login-page {
    background:
      linear-gradient(180deg, rgba(31, 43, 46, 0.98) 0%, rgba(31, 43, 46, 0.98) 42%, rgba(245, 246, 243, 0.98) 42%, rgba(245, 246, 243, 0.98) 100%),
      #1f2b2e;
  }

  .login-shell {
    grid-template-columns: minmax(0, 460px);
    align-content: center;
    justify-content: center;
    gap: 28px;
  }

  .login-intro {
    gap: 28px;
  }

  .login-copy h1 {
    max-width: 12ch;
    font-size: 2.35rem;
  }
}

@media (max-width: 520px) {
  .login-shell {
    padding: 20px;
  }

  .login-copy p:last-child {
    font-size: 0.94rem;
  }
}

.timeline {
  display: grid;
  gap: 14px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 14px;
  align-items: start;
}

.timeline-marker {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 8px;
  border: 3px solid var(--surface);
  outline: 2px solid currentColor;
  color: inherit;
}

.timeline-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.timeline-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.timeline-card-body strong {
  font-size: 0.96rem;
}

.timeline-card-body p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.92rem;
}

.timeline-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.82rem;
}

.text-link {
  color: var(--primary);
  text-decoration: none;
}

.text-link:hover {
  text-decoration: underline;
}

@media (max-width: 1120px) {
  .portal-shell {
    grid-template-columns: 1fr;
  }

  .portal-sidebar {
    position: static;
    height: auto;
  }

  .portal-nav {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  }
}

@media (max-width: 720px) {
  .portal-topbar,
  .panel-heading,
  .search-row,
  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

  .portal-content,
  .portal-topbar {
    padding-left: 18px;
    padding-right: 18px;
  }
}

/* Toast feedback + button loading state (HCI feedback for async actions) */
.toast-stack {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px 16px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  opacity: 0;
  transform: translateX(12px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.info { border-left-color: var(--blue); }

.button[disabled],
.button.is-loading {
  opacity: 0.75;
  cursor: progress;
  pointer-events: none;
}

.button.is-loading {
  position: relative;
  color: transparent !important;
}

.button.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-top-color: #fff;
  border-radius: 50%;
  animation: button-spin 0.6s linear infinite;
}

.button.ghost.is-loading::after,
.button.small.is-loading::after {
  border-color: rgba(37, 95, 99, 0.35);
  border-top-color: var(--primary);
}

@keyframes button-spin {
  to { transform: rotate(360deg); }
}

/* Responsive hardening for small tablets, phones, and narrow embedded browsers. */
html {
  -webkit-text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
}

img,
svg,
video,
canvas {
  max-width: 100%;
  height: auto;
}

.portal-main,
.main-shell,
.content,
.portal-content,
.panel,
.stack-item,
.stat-card,
.table-wrap,
.panel-heading > *,
.portal-topbar > *,
.topbar > * {
  min-width: 0;
}

.panel-heading h2,
.panel-heading h3,
.portal-topbar h1,
.topbar h1,
.stack-item strong,
.stack-item span,
td,
th {
  overflow-wrap: anywhere;
}

.table-wrap {
  width: 100%;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.table-wrap table {
  min-width: 720px;
}

.compact-table table {
  min-width: 560px;
}

.search-row > *,
.inline-form > * {
  min-width: min(100%, 160px);
}

@media (max-width: 1180px) {
  .app-shell,
  .portal-shell {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .portal-sidebar {
    position: static;
    height: auto;
    max-height: none;
  }

  .side-nav,
  .portal-nav {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
  }

  .side-nav-section,
  .portal-nav-section {
    min-width: 0;
  }

  .portal-nav a,
  .side-nav a {
    overflow-wrap: anywhere;
  }
}

@media (max-width: 860px) {
  .stats-grid,
  .work-grid,
  .work-grid.three,
  .work-grid.two-two,
  .problem-grid,
  .portal-invoice-grid {
    grid-template-columns: 1fr;
  }

  .work-grid.gap-5 {
    margin-top: 24px;
  }

  .lifecycle,
  .workflow {
    grid-template-columns: repeat(4, minmax(110px, 1fr));
  }

  .line-item-heading {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 720px) {
  .content,
  .portal-content {
    padding: 18px;
  }

  .topbar,
  .portal-topbar {
    padding: 16px 18px;
  }

  .panel {
    padding: 16px;
    gap: 14px;
  }

  .panel-heading-actions,
  .portal-actions,
  .button-row,
  .table-actions {
    width: 100%;
  }

  .portal-actions {
    justify-content: flex-end;
  }

  .search-row > *,
  .inline-form > *,
  .button-row > .button {
    width: 100%;
  }

  .form-stack {
    gap: 12px;
  }

  .modal-overlay {
    align-items: flex-start;
    overflow-y: auto;
    padding: 12px;
  }

  .modal {
    max-width: 100%;
    max-height: none;
    padding: 18px;
  }

  .toast-stack {
    top: 12px;
    right: 12px;
    left: 12px;
    max-width: none;
  }
}

@media (max-width: 560px) {
  .portal-sidebar,
  .sidebar {
    padding: 16px 12px;
  }

  .portal-nav,
  .side-nav {
    grid-template-columns: 1fr;
    margin-top: 18px;
  }

  .portal-topbar,
  .topbar {
    position: static;
    gap: 12px;
  }

  .portal-content,
  .content {
    padding: 16px 12px 32px;
  }

  .stats-grid {
    gap: 12px;
  }

  .stat-card {
    min-height: 96px;
    padding: 14px;
  }

  .stat-card strong {
    font-size: 1.45rem;
  }

  .panel-heading {
    gap: 10px;
    margin-bottom: 10px;
  }

  .count-pill,
  .status-badge {
    max-width: 100%;
  }

  .table-wrap table {
    min-width: 620px;
  }

  th,
  td {
    padding: 10px 8px;
    font-size: 0.86rem;
  }

  .timeline-item {
    grid-template-columns: 1fr;
  }

  .timeline-marker {
    display: none;
  }

  .login-shell {
    min-height: 100svh;
  }
}

@media (max-width: 380px) {
  .portal-content,
  .content,
  .topbar,
  .portal-topbar {
    padding-left: 10px;
    padding-right: 10px;
  }

  .panel,
  .modal,
  .stack-item,
  .knowledge-item,
  .timeline-card {
    padding: 12px;
  }

  .button {
    padding-left: 10px;
    padding-right: 10px;
  }

  .table-wrap table {
    min-width: 560px;
  }
}

/* Mobile application shell: show content first and move navigation into a drawer. */
.nav-drawer-check {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.mobile-menu-toggle,
.mobile-nav-close,
.mobile-nav-backdrop {
  display: none;
}

.portal-topbar-title {
  min-width: 0;
}

@media (max-width: 1024px) {
  .app-shell,
  .portal-shell {
    display: block;
    min-height: 100vh;
  }

  .sidebar,
  .portal-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(84vw, 310px);
    height: 100dvh;
    max-height: none;
    overflow-y: auto;
    padding: 18px 14px;
    box-shadow: 24px 0 44px rgba(0, 0, 0, 0.28);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }

  .nav-drawer-check:checked ~ .sidebar,
  .nav-drawer-check:checked ~ .portal-sidebar {
    transform: translateX(0);
  }

  .mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(16, 24, 28, 0.46);
  }

  .nav-drawer-check:checked ~ .mobile-nav-backdrop {
    display: block;
  }

  .mobile-menu-toggle,
  .mobile-nav-close {
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
  }

  .mobile-menu-toggle {
    display: inline-flex;
    flex: 0 0 auto;
    border: 1px solid var(--border);
    color: var(--ink);
    background: var(--surface);
  }

  .mobile-nav-close {
    display: inline-flex;
    position: absolute;
    top: 18px;
    right: 14px;
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
  }

  .mobile-menu-toggle svg,
  .mobile-nav-close svg {
    width: 21px;
    height: 21px;
  }

  .side-nav,
  .portal-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 24px;
  }

  .portal-topbar,
  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    align-items: center;
    flex-direction: row;
    gap: 12px;
    padding: 14px 16px;
  }

  .portal-topbar-title {
    flex: 1 1 auto;
    min-width: 0;
  }

  .portal-topbar h1,
  .topbar h1 {
    font-size: clamp(1.28rem, 7vw, 1.65rem);
  }

  .portal-actions,
  .user-area {
    flex: 0 0 auto;
    width: auto;
    justify-content: flex-end;
  }
}

@media (max-width: 720px) {
  .portal-topbar,
  .topbar {
    align-items: center;
    flex-direction: row;
  }

  .portal-actions,
  .user-area {
    width: auto;
  }
}

/* Mobile data tables: convert wide tables into readable labeled rows. */
@media (max-width: 640px) {
  .table-wrap {
    overflow-x: visible;
  }

  .table-wrap table {
    min-width: 0;
  }

  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap tfoot,
  .table-wrap tr,
  .table-wrap th,
  .table-wrap td {
    display: block;
    width: 100%;
  }

  .table-wrap thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .table-wrap tbody {
    display: grid;
    gap: 10px;
  }

  .table-wrap tr {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
  }

  .table-wrap td,
  .table-wrap th {
    display: grid;
    grid-template-columns: minmax(92px, 38%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
    font-size: 0.88rem;
  }

  .table-wrap td:last-child,
  .table-wrap th:last-child {
    border-bottom: 0;
  }

  .table-wrap td::before,
  .table-wrap th::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .table-wrap td[colspan],
  .table-wrap th[colspan] {
    display: block;
  }

  .table-wrap td[colspan]::before,
  .table-wrap th[colspan]::before {
    display: none;
  }

  .table-wrap .subtext {
    margin-top: 4px;
  }
}
