:root {
  /* light only: the page background below is fixed white, but the drawio
     export's shapes/pipes/text use CSS light-dark() colors - if the browser
     is in dark mode those resolve to white-on-white and vanish. */
  color-scheme: light;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --bad: #c0392b;
  --stale: #b08900;
  --accent: #1f5f8b;
  --accent-dark: #174a6c;
}

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

#app {
  display: flex;
  align-items: stretch;
  /* Without this, #app's height is just whatever main-col's content needs -
     if the diagram scales down short (e.g. a narrow window), that can be
     less than the viewport, leaving the sidebar's border short of the
     bottom of the page instead of reaching it. */
  min-height: 100vh;
}

#main-col {
  flex: 1 1 auto;
  min-width: 0;
}

#pinned-sidebar {
  flex: 0 0 460px;
  width: 460px;
  max-height: 100vh;
  overflow-y: auto;
  border-right: 1px solid #d0d0d0;
  padding: 10px;
  box-sizing: border-box;
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid #d0d0d0;
  flex-wrap: wrap;
}

header h1 {
  font-size: 16px;
  margin: 0;
}

#controls {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

#as-of {
  color: #666;
}

main#diagram-container {
  padding: 10px;
}

main#diagram-container svg {
  width: 100%;
  height: auto;
  max-height: calc(100vh - 60px);
}

text.value.bad {
  fill: var(--bad) !important;
}

text.value.stale {
  fill: var(--stale) !important;
}

text.value {
  cursor: pointer;
}

#hover-popup {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  background: #ffffff;
  border: 1px solid #333333;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  padding: 6px 8px 10px;
}

#hover-title {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
}

#hover-chart {
  width: 460px;
  height: 210px;
}

.hover-empty {
  font-size: 10px;
  color: #888888;
  text-align: center;
  padding: 40px 0;
}

#hover-popup .u-legend {
  display: none;
}

.pinned-card-chart .u-legend {
  font-size: 10px;
  color: #444444;
}

.pinned-card-chart .u-legend th {
  font-weight: normal;
}

/* --- pinned signal column --- */

.pinned-card {
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  margin-bottom: 12px;
  padding: 8px;
  background: #fafafa;
  animation: pinned-card-in 120ms ease-out;
}

@keyframes pinned-card-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.pinned-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.pinned-card-title {
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.pinned-card-close {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  color: #666666;
  padding: 2px 6px;
  border-radius: 4px;
}

.pinned-card-close:hover {
  background: #e0e0e0;
  color: #1a1a1a;
}

.pinned-card-range {
  margin-bottom: 6px;
}

.pinned-card-range select {
  font-size: 12px;
  padding: 2px 4px;
}

.pinned-card-chart {
  width: 100%;
}

.pinned-card-loading {
  font-size: 11px;
  color: #888888;
  text-align: center;
  padding: 100px 0;
}

#logout-link {
  font: inherit;
  color: #555555;
  background: transparent;
  border: 1px solid #c8c8c8;
  border-radius: 6px;
  padding: 3px 10px;
  cursor: pointer;
}

#logout-link:hover {
  background: #f0f0f0;
  color: var(--fg);
}

#pw-toggle[aria-pressed="true"] {
  font-weight: 700;
  text-decoration: underline;
}

#logout-link:focus-visible,
#pw-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.9);
  color: var(--fg);
}

@supports (backdrop-filter: blur(1px)) {
  #login-overlay {
    background: rgba(20, 30, 40, 0.45);
    backdrop-filter: blur(6px);
  }
}

#login-overlay[hidden] {
  display: none;
}

#login-form {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 360px;
  box-sizing: border-box;
  margin: auto;
  padding: 24px;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.login-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.login-logo {
  flex: 0 0 auto;
  border-radius: 8px;
}

#login-form h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
}

.login-sub {
  margin: 2px 0 0;
  font-size: 14px;
  color: #5f5f5f;
}

#login-form label {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

#login-form input {
  height: 44px;
  box-sizing: border-box;
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 0 12px;
  margin-bottom: 14px;
  border: 1px solid #8a8f94;
  border-radius: 8px;
  background: #ffffff;
  color: var(--fg);
}

#login-form input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.pw-wrap {
  position: relative;
}

.pw-wrap input {
  padding-right: 64px;
}

#pw-toggle {
  position: absolute;
  top: 0;
  right: 0;
  height: 44px;
  padding: 0 12px;
  font: inherit;
  font-size: 14px;
  color: var(--accent);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

#login-error {
  margin: 0 0 14px;
  min-height: 2.6em;
  box-sizing: border-box;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.3;
  color: #8f241a;
  background: #fdecea;
  border: 1px solid transparent;
  border-radius: 8px;
  opacity: 0;
  transition: opacity 150ms;
}

#login-error:not(:empty) {
  opacity: 1;
  border-color: #e6a8a1;
}

#login-submit {
  height: 44px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  color: #ffffff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

#login-submit:hover:not(:disabled) {
  background: var(--accent-dark);
}

#login-submit:disabled {
  opacity: 0.7;
  cursor: progress;
}

#login-submit:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: no-preference) {
  #login-form.shake {
    animation: login-shake 300ms;
  }
}

@keyframes login-shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
