* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --ok: #16a34a;
  --warn: #dc2626;
}

html, body {
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  .btn.process-toggle {
    width: 100%;
    padding: 10px 12px;
    font-weight: 600;
    border-radius: 8px;
    transition: background-color 0.2s, border-color 0.2s;
    background: #e5e7eb;
    border-color: #d1d5db;
    color: #6b7280;
  }

  .btn.process-toggle:hover:not(:disabled) {
    background: #d1d5db;
  }

  .btn.process-toggle.on {
    background: #86efac;
    border-color: #4ade80;
    color: #166534;
  }

  .btn.process-toggle.on:hover:not(:disabled) {
    background: #4ade80;
  }

  .btn.process-toggle.off {
    background: #e5e7eb;
    border-color: #d1d5db;
    color: #6b7280;
  }

  .btn.process-toggle.off:hover:not(:disabled) {
    background: #d1d5db;
  }
  margin: 0 auto;
  padding: 16px;
}

.page-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

body.system-page .page-topbar {
  flex-direction: column;
  gap: 8px;
  text-align: center;
}

body.system-page .page-title-block {
  align-items: center;
}

.shared-page-header {
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px 12px;
  text-align: center;
}

.page-title-block {
  display: flex;
  flex-direction: column;
}

.page-title {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.2px;
}

.page-subtitle {
  margin: 6px 0 0;
  color: #4b5563;
  font-size: 13px;
}

.page-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.page-nav a {
  text-decoration: none;
  color: #111827;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 8px;
}

.page-nav a:hover {
  background: #f3f4f6;
}

.page-nav a.active,
.page-nav a[aria-current="page"] {
  background: #111827;
  color: #ffffff;
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
}

.title-link {
  text-decoration: none;
  color: inherit;
}

.card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 14px;
}

.card.span-2 {
  grid-column: 1 / -1;
}

.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.card-header h2 {
  margin: 0;
  font-size: 16px;
}

.card-subtitle {
  margin: 6px 0 0;
  color: #4b5563;
  font-size: 13px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.btn {
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 7px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: #fff;
  color: #374151;
}

.btn:hover:not(:disabled) {
  background: #f9fafb;
}

.btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.btn-primary {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1d4ed8;
}

.btn-primary:hover:not(:disabled) {
  background: #dbeafe;
}

.btn.process-toggle {
  width: 100%;
  padding: 10px 12px;
  font-weight: 600;
  border-radius: 8px;
  transition: background-color 0.2s, border-color 0.2s;
  background: #e5e7eb;
  border-color: #d1d5db;
  color: #6b7280;
}

.btn.process-toggle:hover:not(:disabled) {
  background: #d1d5db;
}

.btn.process-toggle.on {
  background: #86efac;
  border-color: #4ade80;
  color: #166534;
}

.btn.process-toggle.on:hover:not(:disabled) {
  background: #4ade80;
}

.btn.process-toggle.off {
  background: #e5e7eb;
  border-color: #d1d5db;
  color: #6b7280;
}

.btn.process-toggle.off:hover:not(:disabled) {
  background: #d1d5db;
}

.btn.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

.status {
  min-height: 1.2em;
  font-size: .88rem;
  color: #4b5563;
}

.status.error {
  color: #b91c1c;
}

.status.success {
  color: #166534;
}

.pill-status {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #f3f4f6;
  color: #4b5563;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.pill-status.success {
  background: #ecfdf5;
  color: #166534;
}

.pill-status.error {
  background: #fef2f2;
  color: #b91c1c;
}

body.index-page .status-icon {
  position: absolute;
  right: 8px;
  top: 8px;
  display: inline-flex;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #9ca3af;
  border-radius: 999px;
  border: 1px solid #d1d5db;
  box-shadow: 0 0 0 2px #ffffff;
}

body.index-page .status-icon.connected {
  background: #22c55e;
  border-color: #86efac;
}

body.index-page .status-icon.disconnected {
  background: #ef4444;
  border-color: #fecaca;
}

.dashboard {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 12px 12px;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 0;
}

.gauge-section {
  position: relative;
  flex: 0 0 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 68px 0 0;
  overflow: visible;
}

.gauge-header {
  position: absolute;
  top: 8px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 52px;
  z-index: 2;
}

.gauge-title-link {
  text-decoration: none;
  color: #111827;
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1.1;
}

.title-menu {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.title-menu-links {
  display: flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 8px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}

.title-menu-links::-webkit-scrollbar {
  display: none;
}

[data-site-header] {
  min-height: 52px;
}

.title-brand {
  color: #111827;
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.1;
}

.title-menu-item {
  color: #9ca3af;
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.1;
  flex: 0 0 auto;
}

.title-menu-item.is-active {
  color: #111827;
}

a.title-menu-item:hover {
  color: #6b7280;
}

#wind-meter {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#wind-meter > div {
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
}

#wind-meter svg {
  width: 100%;
  height: auto;
  max-height: 100%;
}

.graph-section {
  flex: 0 0 auto;
  min-height: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 8px 8px 0;
  overflow: visible;
}

.graph-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 0 0 10px;
}

.graph-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0;
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  text-decoration: none;
  text-underline-offset: 2px;
}

.tab-label-short {
  display: none;
}

.graph-tab.active {
  font-weight: 700;
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

.graph-range-row {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

.site-notice {
  max-width: 520px;
  margin: 4px auto 2px;
  padding: 10px 14px;
  color: #6b7280;
  font-size: 0.82rem;
  line-height: 1.55;
  text-align: center;
}

.site-notice p {
  margin: 0;
}

.site-notice-link {
  color: #2563eb;
  text-decoration: none;
  white-space: nowrap;
}

.site-notice-link:hover {
  text-decoration: underline;
}

.graph-range-menu {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.graph-range-label {
  color: #4b5563;
  font-size: 0.84rem;
  font-weight: 600;
}

.graph-range-tab {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 0.84rem;
  color: #9ca3af;
  cursor: pointer;
}

.graph-range-tab:hover {
  color: #6b7280;
}

.graph-range-tab.active {
  color: #111827;
  font-weight: 600;
  cursor: default;
  pointer-events: none;
}

.graph-container {
  width: 100%;
  height: 100%;
  position: relative;
}

#wind-chart {
  width: 100% !important;
  height: 100% !important;
}

.event-timeline {
  position: absolute;
  inset: 0;
  display: block;
  overflow: hidden;
}

.timeline-axis {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: #94a3b8;
}

.timeline-events {
  position: absolute;
  inset: 0;
}

.timeline-marker {
  position: absolute;
  transform: translateX(-50%);
  border: none;
  background: transparent;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.system-layout {
  padding-top: 18px;
  padding-bottom: 24px;
}

.status-card-panel {
  padding: 16px;
}

.status-groups {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.status-group {
  border: 1px solid #eef2f6;
  border-radius: 10px;
  padding: 12px;
  background: #ffffff;
}

.status-group.status-group-span-2 {
  grid-column: 1 / -1;
}

.status-group h3 {
  margin: 0 0 10px;
  font-size: 14px;
  color: #111827;
}

.status-list {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border: 1px solid #eef2f6;
  border-radius: 8px;
  background: #ffffff;
  min-width: 0;
}

.metric dt {
  color: #374151;
  font-size: 12px;
  font-weight: 700;
}

.metric dd {
  margin: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.metric.metric-full {
  grid-column: 1 / -1;
}

.system-form {
  display: block;
}

.system-grid {
  align-items: start;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-span-2 {
  grid-column: span 2;
}

.field label {
  font-size: .86rem;
  color: #4b5563;
  font-weight: 600;
}

.field input {
  height: 38px;
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font: inherit;
  color: #111827;
  background: #ffffff;
}

.field input:focus {
  outline: 2px solid #bfdbfe;
  border-color: #60a5fa;
}

.field-help {
  font-size: .78rem;
  color: #6b7280;
}

.form-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.auth-layout {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
}

.auth-panel {
  width: 100%;
  max-width: 360px;
  padding: 0 20px;
  text-align: center;
}

.auth-title {
  margin: 0 0 10px;
  font-size: 28px;
  font-weight: 600;
  color: #111827;
}

.auth-copy {
  margin: 0 0 18px;
  color: #4b5563;
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-label {
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
}

.auth-input {
  height: 42px;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font: inherit;
  color: #111827;
  background: #ffffff;
}

.auth-input:focus {
  outline: 2px solid #bfdbfe;
  border-color: #60a5fa;
}

.auth-submit {
  width: 100%;
}

.notice-layout {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
}

.notice-card {
  max-width: 720px;
  width: 100%;
  padding: 0 24px;
  text-align: center;
}

.notice-title {
  margin: 0 0 12px;
  font-size: 28px;
  line-height: 1.15;
  color: #111827;
  font-weight: 600;
}

.notice-copy {
  margin: 0 auto 10px;
  max-width: 40ch;
  color: #4b5563;
  font-size: 1rem;
}


/* Landscape phone */
@media (max-height: 500px) and (orientation: landscape) {
  .dashboard {
    flex-direction: row;
    gap: 8px;
    padding-bottom: 8px;
  }
  
  .gauge-section {
    flex: 1;
  }
  
  .graph-section {
    flex: 1;
    min-height: 0;
  }

  .gauge-title-link {
    font-size: 1.15rem;
  }

  .title-brand {
    font-size: 1.15rem;
  }

  .title-menu-item {
    font-size: 0.95rem;
  }
}

/* Tablet and up */
@media (min-width: 768px) {
  .gauge-title-link {
    font-size: 1.6rem;
  }

  .title-brand {
    font-size: 1.6rem;
  }

  .title-menu-item {
    font-size: 1rem;
  }
  
  .dashboard {
    padding: 0 12px 12px;
    gap: 12px;
  }
  
  .gauge-section,
  .graph-section {
    padding: 8px;
    border-radius: 0;
  }
  
  .graph-section {
    min-height: 320px;
  }
}

@media (max-width: 720px) {
  .page-topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .grid,
  .status-groups,
  .status-list,
  .form-grid,
  .form-grid-4 {
    grid-template-columns: 1fr;
  }

  .field-span-2 {
    grid-column: auto;
  }

  .form-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .actions {
    justify-content: stretch;
  }

  .actions .btn {
    flex: 1;
  }

  .notice-card {
    padding: 0 18px;
  }

  .notice-title {
    font-size: 24px;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .dashboard {
    padding: 0 16px 16px;
    gap: 16px;
  }
  
  .gauge-section {
    min-height: min(52vh, 500px);
  }

  .graph-section {
    min-height: 340px;
  }
}

/* Very small phones */
@media (max-height: 600px) and (orientation: portrait) {
  .gauge-title-link {
    font-size: 1.2rem;
  }

  .title-brand {
    font-size: 1.2rem;
  }

  .title-menu-item {
    font-size: 0.9rem;
  }
  
  .dashboard {
    padding: 0 8px 8px;
    gap: 8px;
  }
  
  .gauge-section,
  .graph-section {
    padding: 6px;
    border-radius: 0;
  }
  
  .graph-section {
    min-height: 0;
  }
}

@media (max-width: 680px) {
  .graph-menu {
    gap: 8px;
    margin-bottom: 8px;
  }

  .graph-range-menu {
    justify-content: center;
    gap: 6px;
  }

  .graph-range-label {
    font-size: 0.8rem;
  }

  .graph-range-tab {
    font-size: 0.78rem;
  }

  .graph-tab {
    font-size: 0.88rem;
  }

  .tab-label-full {
    display: none;
  }

  .tab-label-short {
    display: inline;
  }

}