html { font-size: 14px; }
@media (min-width: 768px) { html { font-size: 16px; } }

:root {
  --kf-sidebar-width: 220px;
  --kf-sidebar-collapsed: 56px;
  --kf-topbar-height: 52px;
}

body { margin-bottom: 0; }
.navbar-brand { letter-spacing: 0.02em; }
.card { border-radius: 0.5rem; }
.progress { border-radius: 0.25rem; }
.btn-link.nav-link { text-decoration: none; }

/* Top bar */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  min-height: var(--kf-topbar-height);
}
.app-topbar .navbar-brand { font-size: 1.1rem; }
.app-topbar .sidebar-toggle { line-height: 1; text-decoration: none; }

/* Sidebar */
.app-sidebar {
  position: fixed;
  top: var(--kf-topbar-height);
  left: 0;
  bottom: 0;
  width: var(--kf-sidebar-width);
  background: #1e293b;
  color: #e2e8f0;
  overflow-x: hidden;
  overflow-y: auto;
  z-index: 1020;
  transition: width 0.2s ease;
  box-shadow: 2px 0 8px rgba(0,0,0,.08);
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 0.5rem;
  gap: 0.15rem;
}
.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: #cbd5e1;
  text-decoration: none;
  border-radius: 0.375rem;
  padding: 0.55rem 0.75rem;
  white-space: nowrap;
  font-size: 0.925rem;
}
.sidebar-nav .nav-link:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}
.sidebar-nav .nav-link.active {
  background: #0d6efd;
  color: #fff;
}
.sidebar-nav .nav-icon {
  flex: 0 0 1.25rem;
  text-align: center;
  font-size: 0.95rem;
  line-height: 1;
}
.sidebar-nav .nav-label { overflow: hidden; text-overflow: ellipsis; }

/* Collapsed sidebar */
body.has-sidebar.sidebar-collapsed .app-sidebar {
  width: var(--kf-sidebar-collapsed);
}
body.has-sidebar.sidebar-collapsed .sidebar-nav .nav-label {
  display: none;
}
body.has-sidebar.sidebar-collapsed .sidebar-nav .nav-link {
  justify-content: center;
  padding: 0.55rem 0.35rem;
}
body.has-sidebar.sidebar-collapsed .sidebar-nav .nav-icon {
  flex: none;
}

/* Main content offset */
body.has-sidebar .app-content {
  margin-left: var(--kf-sidebar-width);
  padding: 1.25rem 1.5rem 3rem;
  min-height: calc(100vh - var(--kf-topbar-height) - 40px);
  transition: margin-left 0.2s ease;
}
body.has-sidebar.sidebar-collapsed .app-content {
  margin-left: var(--kf-sidebar-collapsed);
}
body.has-sidebar .app-footer {
  margin-left: var(--kf-sidebar-width);
  transition: margin-left 0.2s ease;
}
body.has-sidebar.sidebar-collapsed .app-footer {
  margin-left: var(--kf-sidebar-collapsed);
}

@media (max-width: 767.98px) {
  .app-sidebar {
    width: var(--kf-sidebar-width);
    transform: translateX(0);
  }
  body.has-sidebar.sidebar-collapsed .app-sidebar {
    width: 0;
    padding: 0;
    overflow: hidden;
  }
  body.has-sidebar .app-content,
  body.has-sidebar .app-footer {
    margin-left: 0;
  }
  body.has-sidebar:not(.sidebar-collapsed) .app-content {
    margin-left: 0;
  }
}

/* Modals above content; toast host */
#appFormModal,
#appConfirmModal {
  z-index: 1060;
}
.modal-backdrop {
  z-index: 1055;
}
#toast-host {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1080;
}

/* Resizable form dialog: fixed title, scrollable fields, fixed actions */
#appFormModal .modal-dialog {
  position: relative;
  width: min(560px, 95vw);
  height: min(640px, 90vh);
  max-width: 95vw;
  max-height: 92vh;
  min-width: 320px;
  min-height: 240px;
  resize: both;
  overflow: hidden;
  margin: 1.75rem auto;
}
#appFormModal .modal-content {
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#appFormModal .modal-header {
  flex: 0 0 auto;
  user-select: none;
  cursor: move;
}
#appFormModal .modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden !important;
  overflow-y: hidden !important;
  display: flex;
  flex-direction: column;
  padding: 0;
}
#appFormModal .modal-footer {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-start;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  background: #fff;
}
#appFormModal .modal-footer.d-none {
  display: none !important;
}
#appFormModal .modal-form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  margin: 0;
  width: 100%;
  max-width: none !important;
}
#appFormModal .modal-form-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem 1rem 0.5rem;
}
#appFormModal .modal-form-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  background: #fff;
}
#appFormModalBody .card {
  box-shadow: none !important;
  border: 0 !important;
  padding: 0 !important;
  max-width: 100% !important;
}
#appFormModalBody h1,
#appFormModalBody .h3 {
  display: none;
}

/* Excel-style report trend matrix */
.report-matrix {
  --report-matrix-navy: #0b1f3a;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
}
.report-matrix th,
.report-matrix td {
  white-space: nowrap;
  vertical-align: middle;
}
.report-matrix .report-matrix-head th {
  background: var(--report-matrix-navy);
  color: #fff;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 2;
}
.report-matrix .report-matrix-head th:first-child,
.report-matrix .report-matrix-sticky {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
  min-width: 10rem;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.06);
}
.report-matrix .report-matrix-head th:first-child {
  z-index: 3;
  background: var(--report-matrix-navy);
  color: #fff;
}
.report-matrix .report-matrix-section td {
  background: var(--report-matrix-navy);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.8rem;
  padding-top: 0.55rem;
  padding-bottom: 0.55rem;
}
.report-matrix .report-matrix-total td,
.report-matrix .report-matrix-summary td {
  background: #f1f5f9;
}
.report-matrix .report-matrix-total .report-matrix-sticky,
.report-matrix .report-matrix-summary .report-matrix-sticky {
  background: #f1f5f9;
}
.report-matrix .text-end {
  font-variant-numeric: tabular-nums;
}


.report-matrix .report-drill {
  cursor: pointer;
}
.report-matrix .report-drill:hover {
  background-color: #e8f0fe !important;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.report-matrix .report-matrix-total .report-drill:hover,
.report-matrix .report-matrix-summary .report-drill:hover {
  background-color: #dbe7f8 !important;
}
.report-matrix .report-matrix-sticky.report-drill:hover {
  background-color: #e8f0fe !important;
}
.report-matrix .report-matrix-total .report-matrix-sticky.report-drill:hover,
.report-matrix .report-matrix-summary .report-matrix-sticky.report-drill:hover {
  background-color: #dbe7f8 !important;
}

@media print {
  .no-print,
  .app-sidebar,
  .app-topbar,
  .btn-group,
  button[onclick="window.print()"] {
    display: none !important;
  }
  body.has-sidebar .app-content,
  body.has-sidebar .app-footer {
    margin-left: 0 !important;
  }
  .report-matrix .report-matrix-sticky,
  .report-matrix .report-matrix-head th:first-child {
    position: static;
    box-shadow: none;
  }
  .card {
    box-shadow: none !important;
    border: 1px solid #dee2e6 !important;
  }
}

.password-field {
  position: relative;
}
.password-field .form-control {
  padding-right: 2.75rem;
}
.password-field .password-toggle {
  position: absolute;
  top: 50%;
  right: 0.35rem;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: #495057;
  padding: 0.25rem 0.4rem;
  line-height: 1;
  z-index: 2;
}
.password-field .password-toggle:hover { color: #0d6efd; }
.password-toggle-icon {
  display: inline-block;
  width: 1.15rem;
  height: 1.15rem;
  vertical-align: middle;
}
