*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f3f4f6;
  color: #111827;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: #ffffff;
  color: #ffffff;
}

.logo-banner {
  height: 85px;
  object-fit: contain;
}

.user-label {
  margin-right: 0.75rem;
  font-size: 0.85rem;
  opacity: 0.9;
}

.app-main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.25rem 1rem;
}

.card {
  width: 100%;
  max-width: 1200px;
  background: #ffffff;
  border-radius: 0.75rem;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.12);
  padding: 1.25rem 1.5rem;
}

.card-login {
  max-width: 420px;
  max-height: auto;
  height: fit-content;
  margin-top: -85px;
}

.card-title {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
  font-weight: 600;
}

.card-subtitle {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  color: #6b7280;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.field-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: #374151;
}

.field input[type="text"],
.field input[type="email"],
.field input[type="password"] {
  border-radius: 0.5rem;
  border: 1px solid #d1d5db;
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus {
  border-color: #0f567f;
  box-shadow: 0 0 0 2px rgba(15, 86, 127, 0.25);
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.btn {
  border: none;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.6rem 1.1rem;
  font-size: 0.95rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}

.btn-small {
  padding: 0.35rem 0.85rem;
  font-size: 0.8rem;
}

.btn-primary {
  background: #0f567f;
  color: #ffffff;
  box-shadow: 0 10px 18px rgba(15, 86, 127, 0.35);
}

.btn-primary:hover {
  background: #0b3958;
}

.btn-secondary {
  background: #eef5fb;
  color: #0f567f;
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  border: 1px solid rgba(15, 86, 127, 0.2);
}

.btn-secondary:hover {
  background-color: #e0edf7;
}

.btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.status {
  min-height: 1.1rem;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: #6b7280;
}

.status-inline {
  margin-top: 0;
}

.status-error {
  color: #b91c1c;
}

.status-success {
  color: #047857;
}

.hidden {
  display: none !important;
}

/* Viewer */

.card-viewer {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
}

.viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.viewer-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

.scope-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: #e5f2fb;
}

.scope-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
}

.scope-text {
  font-size: 0.8rem;
  color: #0b3958;
}

.table-shell {
  flex: 1;
  min-height: 0;
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
}

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.table-scroll {
  flex: 1;
  min-height: 0;
  border-radius: 0.5rem;
  border: 1px solid #e5e7eb;
  overflow: auto;
  background: #ffffff;
}

.cal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.cal-table thead {
  position: sticky;
  top: 0;
  background: #edf2f7;
  z-index: 1;
}

.cal-table th,
.cal-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
  white-space: nowrap;
}

.cal-table tbody tr:nth-child(even) {
  background: #f9fafb;
}

.cal-table tbody tr:hover {
  background: #dbeafe;
}

.cal-table tbody tr.selected {
  background: #bfdbfe;
}

/* Detail overlay */

.detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: stretch;
  justify-content: center;
  z-index: 40;
}

.detail-dialog {
  margin: 1.25rem;
  max-width: 960px;
  width: 100%;
  background: #ffffff;
  border-radius: 0.75rem;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.45);
  padding: 1rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2.5rem);
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.icon-btn {
  border-radius: 999px;
  border: none;
  background: #e5f2fb;
  color: #0b3958;
  width: 32px;
  height: 32px;
  font-size: 1.1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: #d1e4f7;
}

.detail-header-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.detail-title {
  font-size: 1rem;
  font-weight: 600;
}

.detail-subtitle {
  font-size: 0.8rem;
  color: #6b7280;
}

.detail-meta {
  margin-top: 0.35rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  font-size: 0.8rem;
  max-height: 180px;
  overflow: auto;
}

.detail-meta-grid {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 0.2rem 0.75rem;
}

.detail-meta-label {
  font-weight: 500;
  color: #4b5563;
}

.detail-meta-value {
  color: #111827;
  word-break: break-all;
}

.detail-section-title {
  margin: 0.6rem 0 0.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #374151;
}

.detail-json {
  margin: 0;
  flex: 1;
  min-height: 0;
  border-radius: 0.5rem;
  border: 1px solid #e5e7eb;
  background: #0b1120;
  color: #f9fafb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.78rem;
  padding: 0.5rem 0.75rem;
  overflow: auto;
}

@media (max-width: 900px) {
  .card-viewer {
    height: auto;
  }
  .detail-dialog {
    margin: 0.75rem;
    max-height: calc(100vh - 1.5rem);
  }
}

@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  .card {
    padding: 1.1rem 1rem;
  }
  .viewer-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .viewer-controls {
    align-items: flex-start;
  }
}


/* --- Calibration tree theming & search --- */

.cal-tree-root,
.detail-json.cal-tree-root {
  background: #f5f7fb;
  padding: 8px 12px;
  border-radius: 4px;
  overflow: auto;
}

.cal-row {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) minmax(80px, 0.8fr) minmax(50px, 0.6fr) minmax(120px, 1fr) minmax(220px, 1.4fr);
  align-items: baseline;
  column-gap: 12px;
  padding: 3px 6px;
  font-family: Consolas, Menlo, Monaco, monospace;
  font-size: 12px;
  border-radius: 4px;
  margin: 1px 0;
  color: #1f2933;
}

.cal-row[data-depth="0"] { background: #e3edff; }
.cal-row[data-depth="1"] { background: #edf2ff; }
.cal-row[data-depth="2"] { background: #f5f7ff; }
.cal-row[data-depth="3"],
.cal-row[data-depth="4"],
.cal-row[data-depth="5"] { background: #f9f9ff; }

.cal-group {
  font-weight: 700;
}

.cal-leaf .cal-name {
  opacity: 0.95;
}

.cal-value {
  min-width: 90px;
  text-align: right;
}

.cal-unit {
  min-width: 50px;
}

.cal-search-row {
  margin: 4px 0 6px;
  display: flex;
  justify-content: flex-end;
}

#cal-search {
  width: 220px;
  max-width: 100%;
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 4px;
  border: 1px solid #cbd2e1;
  outline: none;
}

#cal-search:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 1px rgba(37,99,235,0.15);
}

/* --- Summary filter panel --- */
.filter-toggle-btn {
  margin-left: auto;
}

.filter-panel {
  background: #f7f7fb;
  border: 1px solid #dde2f2;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 8px;
}

.filter-panel.hidden {
  display: none;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 6px;
}

.filter-label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
}

.filter-label input,
.filter-label select {
  margin-top: 2px;
  padding: 4px 6px;
  font-size: 12px;
  border-radius: 4px;
  border: 1px solid #cbd2e1;
}

.filter-label input:focus,
.filter-label select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 1px rgba(37,99,235,0.15);
}

.filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.hidden-column {
  display: none;
}
.cal-raw,
.cal-mapdebug {
  font-size: 11px;
  opacity: 0.75;
}
