*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Roboto, Helvetica, Arial, sans-serif;
  color: #111;
}

/* Logged-in shell: one viewport for header + chart (no page scroll on ACE tab). */
body.app-shell-visible {
  height: 100vh;
  overflow: hidden;
}

body.app-shell-visible .page-bg {
  min-height: 0;
  height: 100%;
  max-height: 100vh;
  padding: 0.5rem 0.75rem 0.65rem;
  box-sizing: border-box;
  align-items: stretch;
}

body.app-shell-visible .dashboard-card {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  min-width: 0;
  padding: 0.75rem 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
}

body.app-shell-visible .dashboard-header {
  margin-bottom: 0.65rem;
  gap: 0.5rem;
}

body.app-shell-visible .dashboard-title {
  font-size: clamp(1.25rem, 3vw, 1.65rem);
}

body.app-shell-visible .tab-strip {
  margin: 0 -1rem 0.5rem;
  padding: 0.35rem 0.5rem 0;
}

body.app-shell-visible #panel-ace.panel--visible {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body.app-shell-visible #panel-manager.panel--visible {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Same vertical stretch as Overview / ACE so the shared .panel::before watermark centers in one spot. */
body.app-shell-visible #panel-access.panel--visible,
body.app-shell-visible #panel-dev.panel--visible {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Base .chart-wrap uses min-height 380px; logged-in layout fills viewport instead. */
body.app-shell-visible .chart-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0.4rem 0.5rem 0.25rem;
}

body.app-shell-visible .chart-canvas-box {
  flex: 1 1 auto;
  min-height: 12rem;
  height: auto;
}

.page-bg {
  min-height: 100vh;
  padding: 2rem 1.25rem 3rem;
  background: linear-gradient(90deg, #f0f9ff 0%, #fffdf0 100%);
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.dashboard-card {
  width: 100%;
  max-width: 1120px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.08),
    0 2px 8px rgba(15, 23, 42, 0.04);
  padding: 2rem 2.25rem 2.5rem;
}

.dashboard-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.logo {
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: 0.06em;
  color: #0a2f6b;
  justify-self: start;
}

.dashboard-title {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  color: #000;
  text-align: center;
  grid-column: 2;
}

.header-actions {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.user-chip {
  font-size: 0.8125rem;
  color: #475569;
  max-width: min(28rem, 50vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-text {
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #1976d2;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.35rem;
  border-radius: 4px;
}

.btn-text:hover {
  background: rgba(25, 118, 210, 0.08);
}

.auth-gate {
  min-height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: linear-gradient(90deg, #f0f9ff 0%, #fffdf0 100%);
}

/* ``hidden`` must win over ``display: flex`` so the OAuth gate never stacks above the dashboard. */
.auth-gate[hidden],
#app-shell[hidden] {
  display: none !important;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: 16px;
  padding: 2rem 1.75rem;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
}

.auth-title {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
  font-weight: 700;
  text-align: center;
}

.auth-subtitle {
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
  color: #64748b;
  text-align: center;
}

.auth-origin-line {
  margin: 0 0 1rem;
  font-size: 0.8rem;
  color: #64748b;
  text-align: center;
  line-height: 1.5;
}

.auth-origin-line code {
  font-size: 0.75rem;
  word-break: break-all;
}

.auth-origin-line a {
  color: #2563eb;
}

.auth-hint {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: #64748b;
  line-height: 1.45;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.field-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  margin-top: 0.25rem;
}

.field-input {
  font-family: inherit;
  font-size: 0.9375rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}

.field-input:focus {
  outline: 2px solid rgba(25, 118, 210, 0.35);
  border-color: #1976d2;
}

.field-input--inline {
  min-width: 0;
  flex: 1 1 8rem;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.875rem;
  color: #475569;
}

.btn-primary {
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  margin-top: 0.5rem;
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 6px;
  background: #1976d2;
  color: #fff;
  cursor: pointer;
}

.btn-primary:hover {
  background: #1565c0;
}

.btn-primary--sm {
  margin-top: 0;
  padding: 0.45rem 0.85rem;
  font-size: 0.875rem;
  flex: 0 0 auto;
}

.form-error {
  margin: 0;
  font-size: 0.8125rem;
  color: #b91c1c;
}

.access-panel {
  padding: 0.25rem 0;
}

.access-intro {
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
  color: #475569;
  line-height: 1.5;
}

.access-section-title {
  margin: 1.25rem 0 0.65rem;
  font-size: 0.9375rem;
  font-weight: 700;
  color: #334155;
}

.access-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.dev-panel {
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  padding: 1.25rem;
  color: #64748b;
  min-width: 0;
  overflow-x: hidden;
}

.dev-sim-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
  margin-top: 1rem;
}

.dev-sim-form .field-label {
  flex: 0 0 100%;
}

.form-msg {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
  color: #15803d;
}

.form-msg--err {
  color: #b91c1c;
}

.name-pending {
  color: #94a3b8;
  font-style: italic;
}

.table-wrap {
  overflow-x: hidden;
  border: 1px solid #e8eef5;
  border-radius: 10px;
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.user-table th,
.user-table td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #e8eef5;
}

.user-table th {
  background: #f8fafc;
  font-weight: 600;
  color: #64748b;
}

.user-table tr:last-child td {
  border-bottom: none;
}

.user-table-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-table select {
  font-family: inherit;
  font-size: 0.8125rem;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
}

.tab-strip {
  background: #0f172a;
  margin: 0 -2.25rem 1.5rem;
  padding: 0.5rem 1rem 0;
}

.tab-bar {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.25rem;
  justify-content: flex-start;
}

.tab {
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.6rem 1.2rem 0.7rem;
  border: none;
  border-radius: 10px 10px 0 0;
  background: #e2e8f0;
  color: #1e293b;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab[hidden] {
  display: none !important;
}

.tab:hover:not(.tab--active) {
  background: #cbd5e1;
}

.tab:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 2px;
  z-index: 1;
}

.tab--active {
  background: #2563eb;
  color: #fff;
  padding-bottom: 0.85rem;
}

.tab--active:hover {
  background: #1d4ed8;
  color: #fff;
}

.panel {
  display: none;
  position: relative;
  min-width: 0;
  overflow-x: hidden;
}

.panel--visible {
  display: block;
}

/* QC logo watermark: full tab panel box (absolute + contain; clipped, no page growth). */
.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("/images/qc-watermark.png?v=20260623") center / contain no-repeat;
  opacity: 0.09;
  pointer-events: none;
}

.field-input--invalid {
  outline: 2px solid #ef4444;
  border-color: #ef4444 !important;
}

/* Overview tab: table + chart split (Project View lives in toolbar). */
.overview-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  flex: 1 1 auto;
  gap: 0.65rem;
  overflow-x: hidden;
}

.overview-toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.75rem;
}

.overview-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: stretch;
  gap: 0.65rem;
  min-height: 0;
  flex: 1 1 auto;
}

.overview-table-col {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.overview-table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(72vh, 36rem);
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
}

.overview-team-table {
  table-layout: fixed;
  width: 100%;
  border-collapse: collapse;
  font-size: 0.6875rem;
}

.overview-team-table th,
.overview-team-table td {
  border: 1px solid #d1d5db;
  padding: 0.3rem 0.35rem;
  text-align: left;
  vertical-align: middle;
  line-height: 1.25;
}

.overview-team-table thead th {
  background: #fff;
  font-weight: 700;
  color: #111;
  position: sticky;
  top: 0;
  z-index: 1;
  box-shadow: 0 1px 0 #d1d5db;
  white-space: normal;
  overflow-wrap: break-word;
  hyphens: auto;
}

.overview-team-table th:nth-child(1),
.overview-team-table td:nth-child(1) {
  width: 17%;
}

.overview-team-table th:nth-child(n + 2),
.overview-team-table td:nth-child(n + 2) {
  width: 13.83%;
}

.overview-td-name {
  font-weight: 500;
  color: #0f172a;
  overflow-wrap: break-word;
  word-break: break-word;
}

.overview-metric-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.overview-metric-cell--na {
  background: #f8fafc;
  color: #64748b;
}

/* Reserved for live data: match spreadsheet-style conditional formatting */
.overview-metric-cell--ok {
  background: #dcfce7;
  color: #14532d;
}

.overview-metric-cell--warn {
  background: #ffe4e6;
  color: #9f1239;
}

.overview-loading,
.overview-empty {
  padding: 0.75rem 0.5rem;
  color: #64748b;
  text-align: center;
}

.overview-chart-col {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.overview-chart-placeholder {
  flex: 1 1 auto;
  min-height: 9rem;
  max-height: min(42vh, 22rem);
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 0.5rem;
}

.overview-chart-placeholder-text {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: #94a3b8;
  text-align: center;
  line-height: 1.3;
}

@media (max-width: 900px) {
  .overview-split {
    grid-template-columns: 1fr;
  }

  .overview-table-col {
    min-width: 0;
  }

  .overview-table-wrap {
    max-height: min(40vh, 22rem);
  }

  .overview-chart-col {
    min-height: 8rem;
    max-height: min(24vh, 12rem);
  }

  .overview-chart-placeholder {
    max-height: 10rem;
    min-height: 5.5rem;
  }
}

.ace-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  flex: 1 1 auto;
  gap: 0.5rem;
  overflow-x: hidden;
}

.ace-panel-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem 1.25rem;
  align-items: start;
  flex-shrink: 0;
}

.ace-qc-view-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.ace-toolbar-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  min-width: min(100%, 14rem);
}

.ace-metric-block {
  text-align: right;
  font-size: 0.875rem;
  color: #334155;
}

.ace-metric-line {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  justify-content: flex-end;
  align-items: baseline;
}

.ace-metric-label {
  font-weight: 600;
  color: #64748b;
}

.ace-metric-value {
  font-variant-numeric: tabular-nums;
  min-width: 4.5ch;
}

.ace-chart-stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  align-self: stretch;
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
}

.ace-chart-title {
  margin: 0 0 0.35rem;
  padding: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: #64748b;
  text-align: left;
  width: 100%;
  box-sizing: border-box;
}

.ace-import-bar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid #e8eef5;
  border-radius: 10px;
  background: #fafbfc;
}

.ace-import-bar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
}

.ace-date-label--compact {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
  font-size: 0.8125rem;
  color: #475569;
}

.ace-date-inline-label {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* Override global .field-input--inline flex growth so date fields stay compact. */
.ace-date-input.field-input.field-input--inline,
.ace-date-input.field-input--inline {
  flex: 0 0 auto;
  width: auto;
  min-width: 9.35rem;
  max-width: 11rem;
  padding: 0.35rem 0.45rem;
  box-sizing: border-box;
}

@supports (field-sizing: content) {
  .ace-date-input.field-input--inline {
    field-sizing: content;
    min-width: 8.85rem;
    max-width: none;
  }
}

.ace-low-qc-wrap {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid #e8eef5;
  border-radius: 12px;
  background: #fff;
  padding: 0.5rem 0.75rem 0.65rem;
  overflow-x: hidden;
}

.ace-low-qc-heading {
  margin: 0 0 0.35rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #334155;
}

.ace-low-qc-table-wrap {
  max-height: min(40vh, 22rem);
  overflow-x: hidden;
  overflow-y: auto;
}

.ace-low-qc-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.ace-low-qc-table th,
.ace-low-qc-table td {
  border: 1px solid #e2e8f0;
  padding: 0.35rem 0.45rem;
  vertical-align: top;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.ace-low-qc-table th {
  background: #f8fafc;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}

body.app-shell-visible #panel-ace.panel--visible .ace-chart-wrap--compact {
  flex: 0 1 auto;
}

body.app-shell-visible #panel-ace.panel--visible .ace-chart-wrap--compact .chart-canvas-box {
  height: auto;
  max-height: 35vh;
  min-height: 10rem;
}

@media (max-width: 720px) {
  .ace-panel-toolbar {
    grid-template-columns: 1fr;
  }

  .ace-toolbar-right {
    align-items: stretch;
  }

  .ace-import-bar-row {
    justify-content: flex-start;
  }

  .ace-metric-block {
    text-align: left;
  }

  .ace-metric-line {
    justify-content: flex-start;
  }
}

.chart-wrap {
  background: #fff;
  border: 1px solid #e8eef5;
  border-radius: 12px;
  padding: 1rem 1rem 0.5rem;
  min-height: 380px;
}

.chart-label {
  margin: 0 0 0.5rem 0.25rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #94a3b8;
}

.chart-canvas-box {
  position: relative;
  height: min(52vh, 420px);
  width: 100%;
}

.placeholder-panel {
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: #64748b;
}

.placeholder-title {
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: #334155;
}

.placeholder-copy {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.5;
  max-width: 36rem;
  margin-inline: auto;
}

@media (max-width: 640px) {
  .dashboard-header {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .logo {
    justify-self: center;
  }

  .dashboard-title {
    grid-column: 1;
  }

  .header-actions {
    grid-column: 1;
    justify-self: center;
  }
}
