:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef3f8;
  --ink: #17202a;
  --muted: #637083;
  --line: #d9e1ea;
  --nav: #111827;
  --nav-soft: #1f2937;
  --accent: #2563eb;
  --green: #16a34a;
  --yellow: #d97706;
  --red: #dc2626;
  --gray: #6b7280;
  --shadow: 0 18px 45px rgba(17, 24, 39, 0.08);
  --card-gap: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 18px;
  color: white;
  background: linear-gradient(180deg, #111827 0%, #182236 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #2f80ed;
  font-size: 22px;
  font-weight: 800;
}

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

.brand span {
  margin-top: 3px;
  color: #b8c2d6;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  color: #d7deeb;
  background: transparent;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.nav-item:link,
.nav-item:visited,
.nav-item:hover,
.nav-item:focus,
.nav-item:active {
  color: #d7deeb;
  text-decoration: none;
}

.nav-item:hover,
.nav-item:focus-visible,
.nav-item.active,
.nav-item[aria-current="page"] {
  color: white;
  background: var(--nav-soft);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: #dbe5f4;
  font-size: 13px;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

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

.topbar h1,
.section-heading h2,
.hero-panel h2,
.client-card h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.period-chip,
.tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 7px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.hero-panel,
.client-card,
.search-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--card-gap);
  padding: 30px;
  margin-bottom: 22px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-panel h2,
.section-heading h2 {
  max-width: 900px;
  font-size: 32px;
  line-height: 1.12;
}

.hero-copy,
.panel p,
.client-card p {
  color: var(--muted);
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  padding: 13px 18px;
  color: white;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.secondary-action,
.table-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--ink);
  background: var(--surface);
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.secondary-action:hover,
.table-action:hover {
  border-color: #93c5fd;
  color: var(--accent);
}

.table-action:disabled {
  color: var(--muted);
  background: #eef2f7;
  cursor: not-allowed;
}

.section-heading {
  margin: 0 0 22px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--card-gap);
  margin-bottom: 22px;
}

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

.metric-card {
  min-height: 124px;
  padding: 18px;
}

.metric-card span,
.metric-card small {
  display: block;
}

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

.metric-card strong {
  display: block;
  margin: 12px 0 6px;
  font-size: 27px;
}

.two-column,
.period-grid {
  display: grid;
  gap: var(--card-gap);
  margin-bottom: 22px;
}

.two-column {
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
}

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

.panel,
.period-card {
  padding: 20px;
}

.period-card {
  cursor: pointer;
}

.period-card.selected {
  border-color: #93c5fd;
  outline: 3px solid #dbeafe;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel h3,
.period-card h3 {
  margin: 0 0 10px;
}

.alert-list,
.results-list {
  display: grid;
  gap: 12px;
}

.alert-row,
.result-item {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.result-item {
  grid-template-columns: minmax(0, 1fr) auto auto;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.result-item:hover {
  border-color: #93c5fd;
}

.status-dot {
  width: 11px;
  height: 11px;
  flex: 0 0 11px;
  border-radius: 999px;
  display: inline-block;
}

.green {
  background: var(--green);
}

.yellow {
  background: var(--yellow);
}

.red {
  background: var(--red);
}

.gray {
  background: var(--gray);
}

.positive {
  color: var(--green);
}

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

.negative {
  color: var(--red);
}

.neutral {
  color: var(--gray);
}

.tag.green {
  color: #166534;
  background: #dcfce7;
  border-color: #bbf7d0;
}

.tag.yellow {
  color: #92400e;
  background: #fef3c7;
  border-color: #fde68a;
}

.tag.red {
  color: #991b1b;
  background: #fee2e2;
  border-color: #fecaca;
}

.tag.gray {
  color: #374151;
  background: #f3f4f6;
}

.decision-panel {
  background: #f8fbff;
}

.decision-score {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 22px;
  padding: 14px;
  border-radius: 8px;
  background: #e8f1ff;
}

.control-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 26px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.control-hero h2 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0;
}

.control-status {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.control-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.control-toolbar label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.control-toolbar select {
  min-width: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: white;
}

.control-layout {
  grid-template-columns: minmax(0, 1fr);
}

.operations-panel {
  margin-bottom: 22px;
}

.masters-panel {
  grid-column: 1 / -1;
}

.masters-panel .panel-header {
  align-items: flex-start;
}

.masters-panel .data-table th,
.masters-panel .data-table td {
  white-space: normal;
}

.masters-panel .control-table td:first-child small {
  max-width: none;
  overflow-wrap: anywhere;
  white-space: normal;
}

.control-table td:first-child small {
  display: block;
  max-width: 220px;
  margin-top: 3px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-message {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
}

.control-message > span:last-child {
  display: grid;
  gap: 4px;
}

.control-message strong {
  color: var(--ink);
}

.quality-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) repeat(3, minmax(0, 1fr));
  gap: var(--card-gap);
  margin-bottom: 18px;
}

.quality-card {
  min-height: 170px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.quality-card span,
.quality-card small {
  display: block;
}

.quality-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.quality-card > strong {
  display: block;
  margin: 18px 0 8px;
  font-size: 42px;
  letter-spacing: 0;
}

.quality-card small {
  font-weight: 800;
}

.quality-summary {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.quality-summary p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.quality-summary strong {
  display: inline;
  margin: 0;
  color: var(--ink);
  font-size: inherit;
}

.quality-card .quality-summary-label {
  display: inline;
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
}

.quality-panel {
  min-height: 170px;
  box-shadow: var(--shadow);
}

.quality-detail-panel {
  margin-bottom: 18px;
}

.quality-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--card-gap);
}

.quality-detail-grid > div {
  min-height: 118px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.quality-detail-grid strong {
  display: block;
  margin-bottom: 8px;
}

.quality-list {
  display: grid;
  gap: 8px;
}

.quality-list p,
.quality-detail-grid p {
  margin: 0;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

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

.data-table th,
.data-table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  text-transform: uppercase;
}

.recommendation {
  background: #eef2ff;
  border-color: #c7d2fe;
}

.timeline {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.timeline div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(67, 56, 202, 0.18);
}

.timeline span {
  color: #4338ca;
  font-weight: 700;
  text-align: right;
}

.search-panel input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
}

.results-list {
  margin-bottom: 22px;
}

.client-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 18px;
}

.client-tab {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--muted);
  background: var(--surface);
  font-weight: 800;
  cursor: pointer;
}

.client-tab.active,
.client-tab:hover {
  color: white;
  border-color: var(--accent);
  background: var(--accent);
}

.client-tab-panel {
  display: none;
}

.client-tab-panel.active {
  display: block;
}

.client-alert {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid #fde68a;
  border-radius: 8px;
  color: #92400e;
  background: #fef3c7;
  font-weight: 700;
}

.client-alert[hidden] {
  display: none;
}

.client-profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--card-gap);
}

.is-loading {
  position: relative;
  min-width: 9ch;
  min-height: 1.1em;
  color: transparent !important;
  border-radius: 6px;
}

.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #edf2f7 0%, #dbe5f0 45%, #edf2f7 90%);
  background-size: 220% 100%;
  animation: skeleton-pulse 1.15s ease-in-out infinite;
}

.metric-card strong.is-loading {
  width: min(100%, 12ch);
}

.quality-card > strong.is-loading {
  width: 5ch;
}

@keyframes skeleton-pulse {
  0% {
    background-position: 120% 0;
  }
  100% {
    background-position: -120% 0;
  }
}

.client-profile-grid div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.client-profile-grid span,
.client-profile-grid strong {
  display: block;
}

.client-profile-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.client-profile-grid strong {
  margin-top: 5px;
  overflow-wrap: anywhere;
}

.error-toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  max-width: min(520px, calc(100vw - 32px));
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #7f1d1d;
  background: #fee2e2;
  box-shadow: var(--shadow);
}

.error-toast[hidden],
.diagnostic-modal[hidden] {
  display: none;
}

.error-toast strong,
.error-toast span {
  display: block;
}

.error-toast span {
  margin-top: 3px;
  font-size: 13px;
}

.diagnostic-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 22px;
}

.diagnostic-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
}

.diagnostic-dialog {
  position: relative;
  z-index: 1;
  width: min(820px, 100%);
  max-height: min(760px, calc(100vh - 44px));
  overflow: auto;
  padding: 20px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.icon-action {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: white;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.inline-action {
  width: fit-content;
  border: 0;
  padding: 0;
  color: var(--accent);
  background: transparent;
  font-weight: 800;
  text-decoration: underline;
  cursor: pointer;
}

.diagnostic-grid {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 10px 14px;
  margin: 0 0 14px;
}

.diagnostic-grid dt {
  color: var(--muted);
  font-weight: 800;
}

.diagnostic-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.diagnostic-dialog pre {
  max-height: 300px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  color: #e5e7eb;
  background: #111827;
  white-space: pre-wrap;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-shell {
  width: min(440px, 100%);
}

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

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 32px;
  text-align: center;
  letter-spacing: 0;
}

.login-panel h2 {
  margin: 0 0 22px;
  font-size: 20px;
  text-align: center;
  letter-spacing: 0;
}

.login-form,
.admin-form {
  display: grid;
  gap: 12px;
}

.login-form {
  width: 100%;
}

.login-form label {
  display: grid;
  gap: 7px;
  width: 100%;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.login-form > label > input,
.login-form .password-input {
  display: block;
  width: 100%;
  height: 42px;
  max-width: 100%;
}

.login-form input,
.admin-form input,
.admin-form select,
#admin-user-query {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: white;
}

.password-field,
.password-input {
  position: relative;
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.password-field:focus-within,
.password-input:focus-within {
  border-color: #93c5fd;
}

.password-field input,
.password-input input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  padding: 11px 46px 11px 12px;
  background: transparent;
}

.password-toggle {
  box-sizing: border-box;
  position: absolute;
  top: 50%;
  right: 12px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  transform: translateY(-50%);
  color: var(--muted);
  opacity: 0;
  cursor: pointer;
  pointer-events: none;
  transition: opacity 0.15s ease, color 0.15s ease;
  z-index: 2;
}

.password-field:focus-within .password-toggle,
.password-input:focus-within .password-toggle {
  opacity: 1;
  pointer-events: auto;
}

.password-toggle:hover,
.password-toggle:focus-visible {
  color: var(--accent);
}

.password-toggle svg {
  width: 20px;
  height: 20px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.login-message {
  min-height: 24px;
  margin-top: 12px;
  color: var(--red);
  font-weight: 800;
}

.admin-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
}

.admin-form .primary-action {
  min-height: 42px;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 230px minmax(0, 1fr);
  }

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

  .two-column {
    grid-template-columns: 1fr;
  }
}

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

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

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

  .workspace {
    padding: 18px;
  }

  .topbar,
  .hero-panel,
  .client-card,
  .search-panel,
  .control-hero,
  .control-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .admin-form {
    grid-template-columns: 1fr;
  }

  .control-toolbar select,
  .control-toolbar button {
    width: 100%;
  }

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

  .quality-detail-grid {
    grid-template-columns: 1fr;
  }

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

  .hero-panel h2,
  .section-heading h2 {
    font-size: 25px;
  }

  .data-table {
    display: block;
    overflow-x: auto;
    white-space: normal;
  }

  .client-profile-grid {
    grid-template-columns: 1fr;
  }

  .error-toast {
    left: 16px;
    right: 16px;
    flex-direction: column;
    align-items: stretch;
  }

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