:root {
  --sidebar-width: 260px;
  --primary: #0F4C81;
  --secondary: #00A3A3;
  --accent: #FFC857;
  --sidebar-bg: #0F4C81;
  --sidebar-bg-2: #0F4C81;
  --accent-soft: rgba(0, 163, 163, 0.22);
  --page-bg: #F5F9FC;
  --text-muted: #5d6d7a;
  /* Typography: Segoe UI / Consolas with webfont fallbacks (see fonts.css) */
  --font-sans: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  --font-sans-semibold: "Segoe UI Semibold", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  --font-mono: Consolas, "Courier New", monospace;
  --font-menu: 15px;
  --font-page-title: 24px;
  --font-section: 18px;
  --font-label: 14px;
  --font-input: 14px;
  --font-button: 14px;
  --font-grid-header: 13px;
  --font-grid-row: 13px;
  --font-report: 10.5pt;
  --font-result: 11pt;
  --font-numeric: 13px;
  --weight-regular: 400;
  --weight-semibold: 600;
}

html, body {
  height: 100%;
}

body {
  background: var(--page-bg);
  font-family: var(--font-sans);
  font-size: var(--font-label);
  font-weight: var(--weight-regular);
  color: #1c2b36;
}

.form-control,
.form-select,
.form-check-input,
.input-group-text {
  border-color: #6c757d;
}

input[type="checkbox"]:not(.form-check-input) {
  -webkit-appearance: none;
  appearance: none;
  width: 1.05rem;
  height: 1.05rem;
  margin: 0.15rem 0 0;
  vertical-align: middle;
  border: 1px solid #6c757d;
  border-radius: 0.2rem;
  background-color: #fff;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 0.72rem 0.72rem;
  cursor: pointer;
}

input[type="checkbox"]:not(.form-check-input):checked {
  background-color: var(--primary);
  border-color: var(--primary);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3e%3c/svg%3e");
}

input[type="checkbox"]:not(.form-check-input):focus-visible {
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: #fff;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 1040;
  overflow-y: auto;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 3px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--sidebar-bg);
}

.sidebar-brand .brand-title {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.1;
  margin: 0;
}

.sidebar-brand .brand-sub {
  font-size: 0.8rem;
  opacity: 0.7;
  margin: 0.15rem 0 0;
}

.brand-org {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  margin-top: 0.15rem;
}

.brand-org .brand-sub {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
}

.brand-settings {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  margin-top: -0.15rem;
  border-radius: 0.35rem;
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none;
}

.brand-settings:hover,
.brand-settings:focus {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.company-logo-preview {
  width: 160px;
  height: 72px;
  object-fit: contain;
  object-position: left center;
  background: #f3f6f8;
  border: 1px solid #d7dee4;
  border-radius: 0.5rem;
  padding: 0.35rem;
}

.sidebar .nav-section {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.55;
  padding: 1rem 1.25rem 0.35rem;
}

.sidebar .nav-link {
  color: rgba(255, 255, 255, 0.9);
  border-radius: 0.5rem;
  margin: 0.15rem 0.75rem;
  padding: 0.55rem 0.85rem;
  font-family: var(--font-sans);
  font-size: var(--font-menu);
  font-weight: var(--weight-regular);
}

.sidebar .nav-link:hover,
.sidebar .nav-link:focus {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.sidebar .nav-link.active {
  color: #fff;
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.main-area {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.sidebar-session {
  margin-top: 0.9rem;
}

.sidebar-field-label {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.62;
  margin-bottom: 0.3rem;
}

.sidebar-branch-form {
  margin: 0;
}

.sidebar-branch-form .form-select {
  width: 100%;
  background-color: #fff;
  color: var(--sidebar-bg);
}

.sidebar-branch-name {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.sidebar-user-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
  font-weight: 600;
}

.sidebar-logout-form {
  margin: 0;
  flex: 0 0 auto;
}

.sidebar-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  padding: 0;
  border: 0;
  border-radius: 0.4rem;
  background: transparent;
  color: rgba(255, 255, 255, 0.88);
}

.sidebar-logout:hover,
.sidebar-logout:focus {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.sidebar-toggle {
  position: fixed;
  top: 0.7rem;
  left: 0.7rem;
  z-index: 1025;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid #d5dee6;
  border-radius: 0.5rem;
  background: #fff;
  color: var(--sidebar-bg);
  align-items: center;
  justify-content: center;
  box-shadow: 0 0.2rem 0.6rem rgba(15, 42, 61, 0.12);
}

#page-content .page-header {
  position: sticky;
  top: 0;
  z-index: 1010;
  background: var(--page-bg);
  margin-top: -1.25rem;
  margin-left: -1.25rem;
  margin-right: -1.25rem;
  margin-bottom: 0.85rem !important;
  padding: 1.25rem 1.25rem 0.75rem;
  border-bottom: 1px solid #e5ebf0;
}

.sidebar-empty {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.85rem;
  padding: 1rem 1.25rem;
}

.perm-table th,
.perm-table td {
  vertical-align: middle;
}

.perm-section td {
  background: #f4f7f8;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #5d6b76;
}

.perm-all-row th {
  font-weight: 500;
  border-bottom-width: 1px;
}

.branch-role-block + .branch-role-block {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid #e5ebf0;
}

.role-check {
  background: #f7fafb;
  border-radius: 0.5rem;
  padding: 0.45rem 0.6rem 0.45rem 2rem;
  min-height: 2.4rem;
}

html:has(body.auth-body) {
  height: 100%;
}

.auth-body {
  margin: 0;
  min-height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: auto;
  font-family: var(--font-sans);
  font-size: var(--font-label);
  background-color: #0f4c81;
  background-image:
    linear-gradient(
      115deg,
      rgba(15, 76, 129, 0.55) 0%,
      rgba(0, 163, 163, 0.28) 42%,
      rgba(245, 249, 252, 0.82) 68%,
      rgba(245, 249, 252, 0.94) 100%
    ),
    var(--auth-photo);
  background-size: cover;
  background-position: left center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.auth-split {
  flex: 1 1 auto;
  display: flex;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  background: transparent;
}

.auth-visual {
  flex: 1.15 1 0;
  min-width: 0;
  position: relative;
  background: transparent;
}

.auth-visual-shade {
  position: absolute;
  left: 2.5rem;
  right: 2.5rem;
  bottom: 2.5rem;
  color: #fff;
}

.auth-visual-kicker {
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.75rem;
  opacity: 0.9;
  margin-bottom: 0.4rem;
  text-shadow: 0 0.2rem 0.8rem rgba(15, 42, 61, 0.45);
}

.auth-visual-title {
  font-family: var(--font-sans-semibold);
  font-size: 2.4rem;
  font-weight: var(--weight-semibold);
  line-height: 1.15;
  margin: 0;
  text-shadow: 0 0.35rem 1.1rem rgba(15, 42, 61, 0.45);
}

.auth-panel {
  flex: 0.85 1 0;
  min-width: 0;
  display: flex;
  align-items: safe center;
  justify-content: center;
  background: transparent;
  padding: 2rem 1.25rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 1rem;
  box-shadow: 0 0.8rem 2rem rgba(15, 42, 61, 0.18);
  padding: 2rem 1.75rem 1.75rem;
}

.auth-logo {
  width: 180px;
  height: 72px;
  object-fit: contain;
  object-position: left center;
  display: block;
  margin-bottom: 0.75rem;
}

.auth-org {
  color: var(--primary);
  font-family: var(--font-sans-semibold);
  font-weight: var(--weight-semibold);
  font-size: var(--font-section);
  line-height: 1.3;
  margin: 0 0 0.35rem;
}

.auth-heading {
  font-family: var(--font-sans-semibold);
  font-size: var(--font-page-title);
  font-weight: var(--weight-semibold);
  margin: 0 0 0.35rem;
  color: var(--primary);
}

.auth-lead {
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: var(--font-label);
  margin-bottom: 1.25rem;
}

.auth-form .form-control {
  border-radius: 0.6rem;
}

@media (max-width: 991.98px) {
  .auth-body {
    background-attachment: scroll;
    background-position: 20% center;
  }

  .auth-split {
    flex-direction: column;
  }

  .auth-visual {
    flex: none;
    width: 100%;
    min-height: 200px;
  }

  .auth-panel {
    flex: 1 1 auto;
    width: 100%;
  }

  .auth-visual-title {
    font-size: 1.7rem;
  }

  .auth-visual-shade {
    left: 1.25rem;
    right: 1.25rem;
    bottom: 1.25rem;
  }
}

@media (max-width: 991.98px) and (max-height: 900px) {
  .auth-visual {
    min-height: 140px;
  }

  .auth-visual-title {
    font-size: 1.35rem;
  }

  .auth-panel {
    padding: 1rem;
  }

  .auth-card {
    padding: 1.25rem 1.25rem 1rem;
  }

  .auth-logo {
    width: 140px;
    height: 56px;
    margin-bottom: 0.4rem;
  }

  .auth-lead {
    margin-bottom: 0.75rem;
  }
}

.auth-footer {
  font-size: 0.92rem;
  color: var(--text-muted, #5b6b7c);
  text-align: center;
}

.auth-footer a {
  font-weight: 500;
}

.sa-body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 0%, rgba(14, 116, 144, 0.08), transparent 42%),
    linear-gradient(180deg, #f3f7f9 0%, #e8eef2 100%);
  font-family: var(--font-sans);
  font-size: var(--font-label);
  color: #16324f;
}

.sa-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.5rem;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid rgba(22, 50, 79, 0.08);
  backdrop-filter: blur(8px);
}

.sa-brand {
  font-family: var(--font-sans-semibold);
  font-weight: var(--weight-semibold);
  font-size: var(--font-section);
  letter-spacing: 0.02em;
}

.sa-brand span {
  margin-left: 0.45rem;
  font-family: var(--font-sans);
  font-weight: var(--weight-regular);
  font-size: var(--font-label);
  color: #0e7490;
}

.sa-topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sa-user {
  font-family: var(--font-mono);
  font-size: var(--font-numeric);
}

.sa-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
}

#page-content {
  padding: 1.25rem;
  flex: 1;
}

#page-content.loading {
  opacity: 0.55;
  pointer-events: none;
}

.card-stat {
  border: 0;
  border-radius: 0.85rem;
  box-shadow: 0 0.35rem 1rem rgba(15, 42, 61, 0.06);
}

.card-stat .stat-value {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: var(--weight-semibold);
  color: var(--sidebar-bg);
}

.card-stat .stat-label {
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: var(--font-label);
}

.table-panel {
  background: #fff;
  border-radius: 0.85rem;
  box-shadow: 0 0.35rem 1rem rgba(15, 42, 61, 0.06);
  padding: 1rem;
}

#page-content table.table:not(.perm-table) > tbody > tr.row-selected > *,
#page-content table.table:not(.perm-table) > tbody > tr.row-selected:hover > * {
  --bs-table-bg-state: rgba(43, 176, 166, 0.32);
  --bs-table-bg-type: rgba(43, 176, 166, 0.32);
  --bs-table-accent-bg: rgba(43, 176, 166, 0.32);
}

#page-content table.table:not(.perm-table) > tbody > tr {
  cursor: pointer;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 991.98px) {
  .sidebar-toggle {
    display: inline-flex;
  }

  #page-content .page-header {
    padding-left: 3.5rem;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.show {
    transform: translateX(0);
  }

  .main-area {
    margin-left: 0;
  }

  .sidebar-backdrop.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 1035;
  }
}

/* Catalog drag-reorder */
.diagnos-grip-col {
  width: 1.65rem;
  padding: 0.15rem 0.45rem 0.15rem 0.15rem !important;
  vertical-align: middle;
  text-align: center;
}

.diagnos-grip {
  display: block;
  width: 12px;
  height: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: grab;
  user-select: none;
  -webkit-user-drag: none;
  opacity: 1;
}

.diagnos-grip:hover {
  opacity: 1;
  filter: brightness(0.85);
}

.diagnos-grip:active {
  cursor: grabbing;
}

.diagnos-grip-disabled {
  cursor: not-allowed;
  opacity: 0.55;
  pointer-events: none;
  filter: none;
}

.diagnos-sort-ghost {
  opacity: 0.45;
  background: #e8f7f5 !important;
}

.diagnos-sort-chosen {
  background: #f3fbfa !important;
}

.diagnos-sort-drag {
  opacity: 0.95;
}

.diagnos-sorting-busy {
  opacity: 0.7;
  pointer-events: none;
}

.dashboard-chart {
  position: relative;
  height: 280px;
}

.dashboard-chart-pie {
  height: 300px;
}

.dashboard-pie-summary {
  color: var(--text-muted);
  font-size: 0.9rem;
}

#page-content table.dash-day-grid > tbody > tr {
  cursor: default;
}

#page-content table.dash-day-grid > tbody > tr.is-today > * {
  --bs-table-bg-state: var(--accent-soft);
  --bs-table-bg-type: var(--accent-soft);
  --bs-table-accent-bg: var(--accent-soft);
  font-weight: 600;
}

#page-content h1,
#page-content h2,
#page-content .h4,
.page-heading,
.sa-main h1,
.auth-heading {
  font-family: var(--font-sans-semibold);
  font-size: var(--font-page-title);
  font-weight: var(--weight-semibold);
  line-height: 1.25;
}

#page-content h3,
#page-content .h5,
.section-header,
.sa-main h2,
.nav-section-title {
  font-family: var(--font-sans-semibold);
  font-size: var(--font-section);
  font-weight: var(--weight-semibold);
  line-height: 1.3;
}

#page-content .form-label,
#page-content .form-check-label,
.auth-form .form-label,
.auth-form .form-check-label,
.sa-main .form-label,
.table-panel .form-label {
  font-family: var(--font-sans);
  font-size: var(--font-label);
  font-weight: var(--weight-regular);
}

.form-control,
.form-select,
.form-control-lg,
textarea.form-control,
.select2-container--default .select2-selection--single .select2-selection__rendered,
.select2-container--default .select2-results__option {
  font-family: var(--font-sans);
  font-size: var(--font-input);
  font-weight: var(--weight-regular);
}

.btn,
.btn-lg,
.btn-sm {
  font-family: var(--font-sans-semibold);
  font-size: var(--font-button);
  font-weight: var(--weight-semibold);
}

.btn-sm {
  font-size: 12px;
}

.btn-primary {
  background-color: var(--primary);
  border-color: var(--primary);
}

.btn-primary:hover,
.btn-primary:focus {
  background-color: #0c3e69;
  border-color: #0c3e69;
}

.btn-outline-primary {
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

#page-content table.table > thead th,
.table-panel table.table > thead th,
.sa-main table.table > thead th {
  font-family: var(--font-sans-semibold);
  font-size: var(--font-grid-header);
  font-weight: var(--weight-semibold);
}

#page-content table.table > tbody td,
.table-panel table.table > tbody td,
.sa-main table.table > tbody td {
  font-family: var(--font-sans);
  font-size: var(--font-grid-row);
  font-weight: var(--weight-regular);
}

.num,
.font-mono,
#page-content td.code,
#page-content td code,
.sa-main .font-mono {
  font-family: var(--font-mono);
  font-size: var(--font-numeric);
  font-weight: var(--weight-regular);
}

.result-value,
.lab-result {
  font-family: var(--font-sans-semibold);
  font-size: var(--font-result);
  font-weight: var(--weight-semibold);
}

.report-text {
  font-family: var(--font-sans);
  font-size: var(--font-report);
  font-weight: var(--weight-regular);
}

.sort-link {
  color: inherit;
  text-decoration: none;
  font-family: var(--font-sans-semibold);
  font-weight: var(--weight-semibold);
}

.sort-link:hover,
.sort-link.is-sorted {
  color: var(--secondary);
}

a {
  color: var(--primary);
}

a:hover {
  color: #0c3e69;
}

.sidebar a {
  color: inherit;
}

