:root {
  --ink: #161616;
  --red: #4fb847;
  --paper: #f5f6f8;
  --line: #e6e6e8;
}

html, body {
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Inter Tight", "Segoe UI", sans-serif;
}

body {
  margin: 0;
}

.app-topbar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: #fff;
  border-top: 6px solid var(--red);
  padding: 0.55rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 var(--line);
}

.app-topbar img {
  height: 3.1rem;
  width: auto;
}

.app-topbar-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.app-topbar-text strong {
  font-size: 1.05rem;
}

.app-topbar-text span {
  color: var(--red);
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

h2, h3 {
  font-weight: 700;
}

#loginSection h2,
#registerSection h2,
#resetPasswordSection h2 {
  display: inline-block;
  border-bottom: 3px solid var(--red);
  padding-bottom: 0.15rem;
  margin-bottom: 1rem;
}

#loginSection,
#registerSection,
#resetPasswordSection {
  max-width: 760px;
  margin: 1.25rem auto;
  background: #fff;
  border-radius: 16px;
  padding: 1.4rem 1.5rem 1.6rem;
  box-shadow: 0 10px 28px rgba(22, 22, 22, 0.06);
  text-align: left !important;
}

.form-control,
.form-select,
.text-input {
  border: 1px solid #d5d5d8;
  border-radius: 10px;
  min-height: 2.4rem;
  max-width: 420px;
}

input[type="button"],
input[type="submit"],
button:not(.list-group-item):not(.nav-link) {
  background: var(--red);
  color: #fff;
  border: 0;
  border-radius: 999px;
  font-weight: 700;
  padding: 0.45rem 1.1rem;
  cursor: pointer;
}

.btn-link,
span.btn-link,
.prompt {
  background: transparent !important;
  color: var(--red) !important;
  border-radius: 0 !important;
  padding: 0 !important;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

.app-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  list-style: none;
  margin: 0;
  padding: 0.45rem 0.75rem;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.app-menu .nav-item {
  position: relative;
  list-style: none;
}

.app-menu .nav-link {
  color: var(--ink);
  font-weight: 650;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
}

.app-menu .nav-link:hover,
.app-menu .dropdown-menu .nav-link:hover {
  background: var(--red);
  color: #fff;
}

.app-menu .dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 30;
  min-width: 220px;
  margin: 0;
  padding: 0.35rem;
  list-style: none;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(22, 22, 22, 0.14);
}

.app-menu .dropdown-menu.show {
  display: block;
}

.app-tabs {
  padding: 0.4rem 0.6rem 0;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.app-tabs .nav-link {
  color: var(--ink);
  font-weight: 600;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
}

.app-tabs .nav-link.active {
  color: var(--red);
  background: transparent;
  border-bottom-color: var(--red);
}

.app-tab-close {
  margin-left: 0.45rem;
  font-weight: 700;
}

.tab-pane {
  background: #fff;
}

.tab-pane:not(.active) {
  display: none;
}

.tab-pane.active {
  display: block;
}

.app-grid {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  max-height: calc(100vh - 16px);
  box-shadow: 0 8px 24px rgba(22, 22, 22, 0.05);
}

.app-grid-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  max-height: calc(100vh - 70px);
}

.app-toolbar {
  display: flex;
  flex: 0 0 auto;
  gap: 0.4rem;
  padding: 0.55rem;
  background: #fff;
  position: relative;
  z-index: 4;
}

body:has(> * > .app-grid) {
  height: 100% !important;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body:has(> * > .app-grid) > * {
  flex: 0 0 auto;
}

body:has(> * > .app-grid) > *:has(> .app-grid) {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

body:has(> * > .app-grid) .app-grid,
body:has(> * > .app-grid) .app-grid-scroll {
  max-height: none;
}

body.default {
  height: 100% !important;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.default #jqxWidget,
body.default #jqxTabs,
body.default #jqxTabs > .tab-content,
body.default .tab-pane.active {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

body.default #jqxMenu,
body.default #jqxTabs > .app-tabs,
body.default hr {
  flex: 0 0 auto;
}

body.default .tab-pane.active iframe {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  height: 100% !important;
  min-height: 0;
  border: 0;
}

.app-grid table {
  margin: 0;
  font-size: 0.92rem;
}

.app-grid thead tr:first-child th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  color: #000;
  font-weight: 700;
  white-space: nowrap;
  border-bottom: 1px solid #000;
}

.app-grid .app-filter th {
  position: sticky;
  top: 2.1rem;
  z-index: 2;
  background: #fff;
  color: var(--ink);
}

.app-filter-multi > button {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  background: #fff;
}

.app-filter-menu {
  display: none;
  position: fixed;
  z-index: 40;
  max-height: 240px;
  overflow: auto;
  background: #fff;
  color: #000;
  border: 1px solid #000;
  padding: 0.35rem 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.app-filter-menu label {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  margin: 0;
  padding: 0.15rem 0;
  font-weight: 400;
  cursor: pointer;
}

.app-filter-menu input {
  width: auto;
  min-height: 0;
  margin-top: 0.2rem;
}

.app-grid tbody button:not(.list-group-item):not(.nav-link) {
  white-space: nowrap;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  padding: 0.15rem 0.45rem;
}

.app-grid tbody tr.selected {
  outline: 2px solid var(--red);
  outline-offset: -2px;
}

.app-grid input,
.app-grid select {
  max-width: none;
  min-height: 1.8rem;
  padding: 0.15rem 0.35rem;
}

.app-window {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 50%;
  top: 6vh;
  transform: translateX(-50%);
  width: min(680px, 94vw);
  max-height: 86vh;
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  padding: 0.4rem 1rem 1rem;
  box-shadow: 0 18px 50px rgba(22, 22, 22, 0.28);
}

.app-window.open {
  display: block;
}

.app-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(22, 22, 22, 0.45);
  z-index: 1990;
}

.app-backdrop.open {
  display: block;
}

.app-toast {
  display: none;
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 3000;
  min-width: 220px;
  max-width: 360px;
  background: var(--ink);
  color: #fff;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border-left: 6px solid var(--red);
  box-shadow: 0 10px 24px rgba(22, 22, 22, 0.2);
}

.app-toast.open {
  display: block;
}

.app-toast.success {
  border-left-color: #1a7f37;
}

.app-toast.error {
  border-left-color: var(--red);
}

.app-loader {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 2500;
  background: rgba(245, 246, 248, 0.72);
  align-items: center;
  justify-content: center;
}

.app-loader.open {
  display: flex;
}

.app-loader div {
  background: #fff;
  border-radius: 14px;
  padding: 0.9rem 1.2rem;
  font-weight: 700;
  box-shadow: 0 10px 24px rgba(22, 22, 22, 0.12);
}

.app-error {
  color: var(--red);
  font-size: 0.82rem;
  font-weight: 600;
}

.app-panel {
  background: #fff;
  border: 0;
  border-radius: 12px;
  margin: 0.6rem;
  padding: 0.6rem 0.8rem 0.8rem;
  box-shadow: 0 8px 24px rgba(22, 22, 22, 0.05);
}

.app-panel-title {
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.app-checks {
  background: #fff;
  border: 1px solid #d5d5d8;
  border-radius: 10px;
  padding: 0.35rem 0.6rem;
  max-height: 160px;
  overflow: auto;
}

.app-checkline {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
  margin: 0.35rem 0.8rem 0.35rem 0;
}

.app-checks label {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin: 0.15rem 0;
  font-weight: 500;
}

.app-layout-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem 1.25rem;
}

.app-layout-col {
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.app-layout-col > .app-panel,
.app-layout-col .tab-pane > .app-panel {
  margin: 0;
  height: 100%;
}

.app-layout-col > .app-tabs {
  background: transparent;
  padding: 0;
}

.app-layout-col > .tab-content {
  background: #fff;
  border-radius: 0 0 12px 12px;
  box-shadow: 0 8px 24px rgba(22, 22, 22, 0.05);
  min-height: 420px;
}

[data-container="CompetitionExplorerPanel"] > span,
[data-container="PrintPanel"] span,
[data-container="ScanQueuePanel"] > span {
  display: block !important;
  width: 100% !important;
  float: none !important;
  max-width: 100%;
}

[data-container="CompetitionExplorerPanel"] .form-select,
[data-container="PrintPanel"] .form-select,
[data-container="ScanQueuePanel"] .form-select {
  width: 100%;
  max-width: none;
}

#refreshTree {
  position: absolute;
  top: 0.45rem;
  right: 0.65rem;
  z-index: 2;
}

[data-container="CompetitionExplorerPanel"] {
  position: relative;
  overflow: hidden;
}

[data-container="ScoresPanel"] span,
[data-container="PrintPanel"] span,
[data-container="ScanQueuePanel"] span {
  display: flex !important;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  width: 100% !important;
  max-width: 100%;
  float: none !important;
}

#selectionTree.app-tree {
  max-height: calc(100vh - 240px);
  overflow: auto;
  margin-top: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.app-tree .tree-children {
  display: none;
}

.app-tree .tree-children.open {
  display: block;
}

.app-tree .tree-caret {
  display: inline-block;
  width: 1rem;
  color: var(--red);
  font-size: 0.75rem;
}

.app-tree .tree-children .tree-node {
  padding-left: 1.4rem;
}

#selectionTree > .tree-level > .tree-children > .tree-level > .tree-node {
  padding-top: 0.2rem;
  padding-bottom: 0.2rem;
  line-height: 1.2;
}

.app-tree .tree-children .tree-children .tree-node {
  padding-left: 2.2rem;
}

[data-container="PrintPanel"] input[type="submit"] {
  margin: 0.35rem 0.35rem 0 0 !important;
}

.app-layout-col .app-grid {
  max-height: calc(100vh - 280px);
}

.app-layout-col .app-grid-scroll {
  max-height: calc(100vh - 330px);
}

.app-tree .list-group-item {
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  text-align: left;
  color: var(--ink);
  border-radius: 0;
}

.app-tree .list-group-item.active {
  background: var(--red);
  color: #fff;
}

#scoresGrid td[data-field=""] {
  cursor: pointer;
  font-weight: 600;
}

#scoresGrid td.app-cell-active {
  background: #f3faf2;
}

#scoresGrid td.app-cell-active input {
  border-color: var(--red);
  box-shadow: 0 0 0 2px rgba(79, 184, 71, 0.28);
}
