/* Shared presentation contract. No canvas geometry or business state changes. */
:root {
  --ui-font-size: 14px;
  --ui-font-small: 13px;
  --ui-control-height: 36px;
  --bs-primary: #6366f1;
  --bs-primary-rgb: 99, 102, 241;
  --bs-success-rgb: 5, 150, 105;
  --bs-warning-rgb: 180, 83, 9;
  --bs-danger-rgb: 220, 38, 38;
  --bs-info-rgb: 37, 99, 235;
  --bs-secondary-rgb: 100, 116, 139;
}

body { font-size: var(--ui-font-size); line-height: 1.6; }
[hidden] { display: none !important; }
button, input, select, textarea { font-family: var(--font-base); }
small, .small, .form-text, .invalid-feedback { font-size: var(--ui-font-small); }
/* Keep long or stacked messages within the viewport, with reachable close buttons. */
#flash-container {
  width: min(350px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
}
.flash-toast .toast-body { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.flash-toast .btn-close { flex-shrink: 0; margin-top: .75rem !important; }
.app-content { padding-bottom: 24px; }
.app-content .page-header :is(h3, h4),
.app-content > .container-fluid > :is(h3, h4),
.app-content > .container-fluid > .d-flex.justify-content-between.mb-4 :is(h3, h4) {
  font-size: 20px;
}
.app-content .breadcrumb { font-size: var(--ui-font-small); margin-bottom: 0; }
.page-header { gap: 12px; align-items: center; flex-wrap: wrap; }
.page-header > .col { min-width: 0; }
.page-header > div:not(.page-actions) { min-width: 0; max-width: 100%; }
.app-content :is(h2, h3, h4, h5) { overflow-wrap: anywhere; }
.breadcrumb-item { min-width: 0; overflow-wrap: anywhere; }
.modal-content, .modal-title, .alert { overflow-wrap: anywhere; }
.modal-header .btn-close { flex-shrink: 0; }
.app-header .navbar-nav.ms-auto, .app-header .nav-item.dropdown { min-width: 0; }
.app-header .navbar-username { min-width: 0; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-header .dropdown-menu { max-width: calc(100vw - 2rem); overflow-wrap: anywhere; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.page-actions > .btn { margin: 0 !important; }
.app-content > .container-fluid > .d-flex.justify-content-between.mb-4 {
  flex-wrap: wrap; gap: 12px;
}
.app-content > .container-fluid > .d-flex.justify-content-between.mb-4 > .d-flex { flex-wrap: wrap; }
.app-content > .container-fluid > .d-flex.justify-content-between.mb-4 > div:not(.page-actions) { min-width: 0; max-width: 100%; }

.app-content .card-header { font-size: 16px; line-height: 1.5; min-height: 48px; overflow-wrap: anywhere; }
.app-content .card-title { font-size: 16px; float: none; }
.app-content .card-header :is(small, .small, .text-muted) { font-size: var(--ui-font-size); }
.app-content .card-header .badge { font-size: var(--ui-font-small); }
.app-content .card-header.d-flex::after { display: none; }

/* The small/large Bootstrap variants share the same business-control size. */
.btn, .btn-sm, .btn-lg, .btn-group-sm > .btn {
  --bs-btn-font-size: var(--ui-font-size);
  --bs-btn-line-height: 1.4;
  font-size: var(--ui-font-size);
  line-height: 20px;
  min-height: var(--ui-control-height);
  padding: 7px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  gap: 4px;
  white-space: nowrap;
  font-weight: 500;
  letter-spacing: 0;
}
.btn > .bi { line-height: 1; margin: 0 !important; }
.training-detail-actions .btn { min-width: 144px; }
.btn { --bs-btn-disabled-bg: var(--bs-btn-bg); --bs-btn-disabled-border-color: var(--bs-btn-border-color); }
.btn-primary { --bs-btn-bg: #6366f1; --bs-btn-border-color: #6366f1; --bs-btn-hover-bg: #4f46e5; --bs-btn-hover-border-color: #4f46e5; --bs-btn-active-bg: #4338ca; --bs-btn-active-border-color: #4338ca; }
.btn-outline-primary { --bs-btn-color: #6366f1; --bs-btn-border-color: #6366f1; --bs-btn-hover-bg: #6366f1; --bs-btn-hover-border-color: #6366f1; --bs-btn-active-bg: #4f46e5; --bs-btn-active-border-color: #4f46e5; }
.btn-success { color: #fff; background: #059669; border-color: #059669; --bs-btn-hover-bg: #047857; --bs-btn-hover-border-color: #047857; --bs-btn-active-bg: #065f46; --bs-btn-active-border-color: #065f46; }
.btn-outline-success { --bs-btn-color: #047857; --bs-btn-border-color: #059669; --bs-btn-hover-bg: #059669; --bs-btn-hover-border-color: #059669; --bs-btn-active-bg: #047857; --bs-btn-active-border-color: #047857; }
.btn-danger { background: #dc2626; border-color: #dc2626; --bs-btn-hover-bg: #b91c1c; --bs-btn-hover-border-color: #b91c1c; }
.btn-outline-danger { color: #dc2626; border-color: #dc2626; --bs-btn-hover-bg: #dc2626; --bs-btn-hover-border-color: #dc2626; }
.btn-info { color: #fff; background: #2563eb; border-color: #2563eb; --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #1d4ed8; --bs-btn-hover-border-color: #1d4ed8; }
.btn-outline-info { color: #2563eb; border-color: #2563eb; --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #2563eb; --bs-btn-hover-border-color: #2563eb; }
.btn-warning { color: #fff; background: #b45309; border-color: #b45309; --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #92400e; --bs-btn-hover-border-color: #92400e; }
.btn-outline-warning { --bs-btn-color: #b45309; --bs-btn-border-color: #b45309; --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #b45309; --bs-btn-hover-border-color: #b45309; }
.btn-secondary { background: #64748b; border-color: #64748b; --bs-btn-hover-bg: #475569; --bs-btn-hover-border-color: #475569; }
.btn-outline-secondary { --bs-btn-color: #475569; --bs-btn-border-color: #94a3b8; --bs-btn-hover-bg: #64748b; --bs-btn-hover-border-color: #64748b; }
.btn:focus-visible { outline: 2px solid #6366f1; outline-offset: 2px; }
.btn-link { min-height: 28px; padding: 3px 6px; }
.app-content .btn:not(.btn-link) { font-size: var(--ui-font-size); padding: 7px 12px; }
.app-content .reader-test .reader-submit-area .btn { font-size: var(--ui-font-size); padding: 7px 12px; }
.label-row .btn-link { min-height: 24px; }

.app-content :is(.form-label, .form-check-label, .input-group-text),
.app-content .reader-test .reader-settings-body > .form-label { font-size: var(--ui-font-size); }
.form-control, .form-control-sm, .form-select, .form-select-sm {
  font-size: var(--ui-font-size);
  line-height: 20px;
  min-height: var(--ui-control-height);
  padding: 7px 12px;
}
.form-control::file-selector-button { font: inherit; line-height: inherit; }
.input-group-text { min-height: var(--ui-control-height); }
.form-label { line-height: 22px; margin-bottom: 6px; }

.app-content .table {
  --bs-table-color: #1e293b;
  --bs-table-striped-bg: #f8fafc;
  --bs-table-striped-color: #1e293b;
  --bs-table-hover-bg: #eef2ff;
  --bs-table-hover-color: #1e293b;
  --bs-table-active-bg: #e0e7ff;
  font-size: var(--ui-font-size);
  line-height: 22px;
  overflow-wrap: anywhere;
}
.app-content .table :is(th, td) { font-size: var(--ui-font-size); vertical-align: middle; }
.app-content .table thead th { padding: 12px; color: #475569; font-weight: 600; }
.app-content .table tbody td { padding: 12px; }
/* Only explicitly marked index cells are centered; detail labels are not indices. */
.app-content .table tbody td:first-child { color: var(--color-text); font-size: var(--ui-font-size); text-align: left; }
.app-content .table .table-index { text-align: center !important; width: 64px; color: var(--color-text-muted); }
.app-content .table :is(small, .small, code) { font-size: inherit; line-height: inherit; }
.app-content .table code { color: #475569; background: #f1f5f9; font-family: inherit; }
.table-number, .table-time, .count-pair { font-variant-numeric: tabular-nums; }
.table-number, .table-status, .table-time { white-space: nowrap; }
.table-status { min-width: 112px; }
.count-pair { display: inline-flex; align-items: baseline; gap: 4px; color: var(--color-text); white-space: nowrap; }
.count-pair > * { font: inherit; color: inherit; }
.status-stack { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.status-stack > * { margin: 0 !important; }
.app-content :is(.badge, .reader-tag) { font-size: var(--ui-font-small); line-height: 18px; padding: 3px 8px; letter-spacing: 0; vertical-align: middle; }
.app-content .badge :is(small, .small) { font-size: inherit; }
.status-badge, .task-status { display: inline-flex; align-items: center; justify-content: center; min-width: 72px; }
.app-content .table .table-actions { text-align: left; white-space: nowrap; }
.table-actions > form { display: inline-flex !important; vertical-align: middle; }
.table-actions > :is(a, button, form) { margin: 0 4px 0 0 !important; vertical-align: middle; }
.app-content .table-actions :is(a, button) {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 32px; line-height: 20px; font-size: var(--ui-font-size) !important;
  padding: 5px 6px !important; gap: 4px; margin: 0 !important;
  font-weight: 500; text-decoration: none;
}
.app-content .table-actions :is(a, button) > .bi { line-height: 1; margin: 0 !important; }
.detail-table > tbody > tr > td:first-child { min-width: 112px; width: 128px; white-space: nowrap; color: var(--color-text-muted) !important; }
.detail-table > tbody > tr > td:last-child { overflow-wrap: anywhere; }
.app-content .page-link { font-size: var(--ui-font-size); min-height: 36px; display: inline-flex; align-items: center; justify-content: center; }
/* Mouse clicks need no focus halo; keyboard navigation keeps its focus indicator. */
.pagination .page-link:focus:not(:focus-visible),
.market-pagination .btn:focus:not(:focus-visible) {
  outline: none;
  box-shadow: none;
}

/* Dedicated annotation/reading workspaces retain their canvas and preview geometry. */
.app-content :is(.img-thumb, .class-chip, .label-row, .img-list .item, .kp-item) { font-size: var(--ui-font-size); }
.app-content :is(.lbl-info, .reader-muted, .reader-range, .reader-reason, .reader-details-body, .reader-frame-caption) { font-size: var(--ui-font-small); }
.app-content :is(.reader-card-header h4, .reader-gauge-heading h5) { font-size: 16px; }
.app-content .reader-page-header h3 { font-size: 20px; }
.app-content .reader-value:not(.reader-value-empty) strong { color: var(--color-accent); }
.manual-content { margin-left: 280px; max-width: 900px; min-width: 0; }
.manual-section { overflow-x: auto; }
.app-content .manual-section :is(p, ul), .app-content .manual-sidebar .nav-link { font-size: var(--ui-font-size); }
@media (max-width: 991px) {
  .manual-content { margin-left: 0; max-width: 100%; }
}
@media (max-width: 767px) {
  .page-actions { width: 100%; justify-content: flex-start; }
  .app-content .table :is(th, td) { padding: 10px; }
}
