:root {
  color-scheme: light;
  font-family: Arial, sans-serif;
  color: #172331;
  background: #edf2f5;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
}

button {
  font: inherit;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1px solid #ccd5de;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.app-logo {
  width: auto;
  height: 64px;
  object-fit: contain;
}

.brand h1 {
  margin: 0 0 5px;
  font-size: 1.35rem;
  line-height: 1.2;
}

.version {
  margin: 0;
  color: #5c6976;
  font-size: 0.85rem;
}

.header-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px 22px;
  margin: 0;
}

.header-status div {
  min-width: 90px;
}

.header-status dt {
  margin-bottom: 3px;
  color: #687682;
  font-size: 0.7rem;
  font-weight: bold;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.header-status dd {
  margin: 0;
  font-size: 0.82rem;
  font-weight: bold;
  white-space: nowrap;
}

.header-button,
.primary-button,
.table-button {
  padding: 7px 12px;
  color: #fff;
  background: #176a9b;
  border: 1px solid #125a84;
  border-radius: 4px;
  font-weight: bold;
  cursor: pointer;
}

.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  background: #87929b;
  border-radius: 50%;
}

.status-pending,
.status-placeholder {
  background: #87929b;
}

.status-good {
  background: #25854e;
}

.status-bad {
  background: #c43c3c;
}

.app-nav {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  background: #17324d;
}

.app-nav button {
  padding: 13px 18px;
  color: #dbe6ee;
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  cursor: pointer;
}

.app-nav button:hover,
.app-nav button:focus-visible,
.app-nav button.active {
  color: #fff;
  background: #234866;
  border-bottom-color: #68b8dc;
}

.connection-bar {
  display: flex;
  align-items: center;
  gap: 22px;
  min-height: 44px;
  padding: 9px 24px;
  color: #425260;
  background: #f8fafb;
  border-bottom: 1px solid #d5dde3;
  font-size: 0.82rem;
}

.connection-bar p {
  margin: 0 0 0 auto;
  color: #7a3c3c;
}

.app-content {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

.page-heading {
  margin: 0 0 18px;
  font-size: 1.35rem;
}

.equipment-loading {
  color: #687682;
}

.equipment-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.equipment-card {
  overflow: hidden;
  min-width: 0;
  background: #fff;
  border: 1px solid #cbd5dd;
  border-radius: 7px;
  box-shadow: 0 2px 5px rgb(24 50 75 / 8%);
}

.card-header {
  margin: 0;
  padding: 13px 15px;
  color: #fff;
  background: #17324d;
  font-size: 1rem;
}

.penstock-image-area {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 190px;
  padding: 14px;
  background: #e8edf0;
  border-bottom: 1px solid #d3dce3;
}

.penstock-image-area img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.position-text {
  margin: 0;
  padding: 11px 14px;
  color: #223a50;
  background: #f7f9fa;
  border-bottom: 1px solid #dbe2e7;
  font-weight: bold;
  text-align: center;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  padding: 12px;
}

.emergency-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding-top: 0;
}

.control-button {
  min-height: 38px;
  color: #fff;
  border: 1px solid rgb(0 0 0 / 18%);
  border-radius: 4px;
  font-size: 0.76rem;
  font-weight: bold;
}

.button-close,
.button-emergency {
  background: #b83838;
}

.button-open {
  background: #287d4c;
}

.button-hold {
  color: #2d2a16;
  background: #e2bd3c;
}

.status-table {
  width: calc(100% - 24px);
  margin: 0 12px 12px;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.status-table th,
.status-table td {
  padding: 8px;
  border: 1px solid #d5dde3;
  text-align: left;
}

.status-table th {
  color: #425260;
  background: #eef2f5;
}

.status-table .no-data,
.no-data {
  color: #71808c;
}

.status-table .no-data {
  text-align: center;
}

.status-table td.no-data {
  color: #71808c;
  background: #f2f4f5;
}

.status-table td.value-font-dark {
  color: #172331;
}

.status-table td.value-font-grey {
  color: #71808c;
}

.status-table td.value-font-green {
  color: #16713d;
  font-weight: bold;
}

.status-table td.value-font-red {
  color: #b31515;
  font-weight: bold;
}

.status-table td.value-font-yellow,
.status-table td.value-font-dark-yellow {
  color: #886500;
  font-weight: bold;
}

.status-table td.value-background-white {
  background: #fff;
}

.status-table td.value-background-yellow {
  background: #ffe66b;
}

.status-table td[data-role="field-value"] {
  color: var(--value-fg, inherit);
  background: var(--value-bg, transparent);
}

.status-table td.value-blink,
.log-table td.value-blink {
  animation: status-value-blink 1s ease-in-out infinite;
}

@keyframes status-value-blink {
  50% {
    opacity: 0.35;
    outline: 2px solid currentColor;
    outline-offset: -2px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .log-table td.value-blink {
    animation: none;
  }
}

.water-display {
  min-height: 271px;
  padding: 20px 12px;
  background: #e8edf0;
  border-bottom: 1px solid #d3dce3;
}

.current-level {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.scope-label {
  color: #60717e;
  font-size: 0.68rem;
  font-weight: bold;
  line-height: 1.2;
  text-transform: uppercase;
}

.current-level strong {
  font-size: 0.9rem;
}

.liquid-tube {
  position: relative;
  box-sizing: border-box;
  height: 225px;
  width: 64px;
  min-height: 225px;
  overflow: hidden;
  background: linear-gradient(90deg, #d8e2e8, #f8fbfc 35%, #f8fbfc 65%, #d8e2e8);
  border: 5px solid #667985;
  border-radius: 24px;
  box-shadow: inset 0 0 8px rgb(23 50 77 / 28%);
}

.liquid-fill {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  background: linear-gradient(90deg, #1673ac, #42b6e8 45%, #1687c4);
  border-top: 2px solid #8bd9f4;
  height: var(--water-level-percent, 0%);
  transition: height 250ms ease;
}

.liquid-fill[hidden],
.water-level-pointer[hidden] {
  display: none;
}

.water-gauge {
  display: grid;
  grid-template-columns: 48px 26px 64px minmax(90px, 1fr);
  gap: 5px;
  align-items: center;
  height: 225px;
}

.water-scale-labels,
.water-scale-ticks,
.water-tube-wrap {
  position: relative;
  height: 225px;
}

.water-scale-label {
  position: absolute;
  right: 3px;
  color: #344a57;
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  font-weight: bold;
  line-height: 1;
  white-space: nowrap;
  transform: translateY(-50%);
}

.water-scale-ticks {
  border-right: 2px solid #526672;
}

.water-scale-ticks.invalid {
  border-right-color: #a4afb5;
}

.water-tick {
  position: absolute;
  right: 0;
  display: block;
  transform: translateY(-50%);
}

.water-tick-major {
  width: 18px;
  border-top: 2px solid #526672;
}

.water-tick-minor {
  width: 9px;
  border-top: 1px solid #748995;
}

.water-tube-wrap {
  width: 64px;
}

.water-level-pointer {
  position: absolute;
  z-index: 2;
  bottom: var(--water-level-percent, 0%);
  left: 50%;
  width: 54px;
  height: 0;
  border-top: 3px solid #c62d2d;
  filter: drop-shadow(0 1px 1px rgb(0 0 0 / 35%));
  transform: translate(-50%, 50%);
  transition: bottom 250ms ease;
}

.water-level-pointer::after {
  position: absolute;
  top: -7px;
  left: -5px;
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 8px solid #c62d2d;
  content: "";
}

.current-level {
  text-align: center;
}

.placeholder-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 18px;
}

.placeholder-card,
.placeholder-section,
.simple-page {
  background: #fff;
  border: 1px solid #d3dce3;
  border-radius: 7px;
  box-shadow: 0 2px 5px rgb(24 50 75 / 8%);
}

.placeholder-card {
  min-height: 170px;
  padding: 18px;
}

.placeholder-card h3,
.placeholder-section h3,
.simple-page h2 {
  margin: 0;
}

.placeholder-card p,
.placeholder-section p,
.simple-page p {
  margin: 10px 0 0;
  color: #74808a;
  font-size: 0.88rem;
}

.logs-layout {
  display: grid;
  gap: 18px;
}

.log-section {
  overflow: hidden;
  background: #fff;
  border: 1px solid #cbd5dd;
  border-radius: 7px;
  box-shadow: 0 2px 5px rgb(24 50 75 / 8%);
}

.log-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: #e8edf0;
  border-bottom: 1px solid #cbd5dd;
}

.log-section-header h3 {
  margin: 0;
  font-size: 1rem;
}

.log-section-actions,
.penstock-log-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.penstock-log-selector button {
  padding: 6px 10px;
  color: #425765;
  font-size: 0.78rem;
  font-weight: bold;
  background: #fff;
  border: 1px solid #9aabb6;
  border-radius: 4px;
}

.penstock-log-selector button:hover,
.penstock-log-selector button:focus-visible,
.penstock-log-selector button.active {
  color: #fff;
  background: #176a9b;
  border-color: #176a9b;
}

.log-export-button {
  padding: 6px 12px;
  color: #fff;
  font-size: 0.78rem;
  font-weight: bold;
  text-decoration: none;
  background: #176a9b;
  border-radius: 4px;
}

.log-table-wrap {
  overflow-x: auto;
}

.log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.log-table th,
.log-table td {
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid #e1e7eb;
}

.log-table th {
  color: #425765;
  background: #f4f7f8;
}

.log-section[data-log-id="system-log"] .log-table th,
.log-section[data-log-id="system-log"] .log-table td,
.log-section[data-log-id="penstock-status-log"] .log-table th,
.log-section[data-log-id="penstock-status-log"] .log-table td,
.log-section[data-log-id="water-level-status-log"] .log-table th,
.log-section[data-log-id="water-level-status-log"] .log-table td {
  text-align: center;
  vertical-align: middle;
}

.log-table tbody tr:last-child td {
  border-bottom: 0;
}

.log-empty {
  color: #71808c;
  text-align: center !important;
}

.log-error {
  color: #a01818;
  text-align: center !important;
  background: #fff2f2;
}

.placeholder-section {
  min-height: 120px;
  padding: 18px;
}

.simple-page {
  padding: 22px;
}

.login-panel,
.form-panel {
  max-width: 480px;
  margin: 30px auto;
  padding: 24px;
  background: #fff;
  border: 1px solid #cbd5dd;
  border-radius: 7px;
  box-shadow: 0 2px 5px rgb(24 50 75 / 8%);
}

.stack-form,
.form-field {
  display: grid;
  gap: 9px;
}

.stack-form {
  gap: 16px;
}

.form-field span {
  color: #425765;
  font-size: 0.78rem;
  font-weight: bold;
}

.form-field input,
.user-table input {
  width: 100%;
  padding: 8px 9px;
  border: 1px solid #9aabb6;
  border-radius: 4px;
}

.form-message,
.password-rule,
.form-note {
  margin: 0;
  color: #60717e;
  font-size: 0.82rem;
}

.form-error {
  color: #a01818;
}

.user-table-wrap {
  overflow-x: auto;
  background: #fff;
  border: 1px solid #cbd5dd;
  border-radius: 6px;
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.user-table th,
.user-table td {
  padding: 7px;
  text-align: center;
  white-space: nowrap;
  border-bottom: 1px solid #e1e7eb;
}

.user-table th {
  color: #425765;
  background: #f4f7f8;
}

.user-table input {
  min-width: 130px;
}

.table-button {
  padding: 5px 8px;
  font-size: 0.72rem;
}

.state-green {
  color: #16713d;
  font-weight: bold;
}

.state-blue {
  color: #176a9b;
  font-weight: bold;
}

.user-log-panel {
  margin-top: 24px;
}

.trend-panel {
  overflow: hidden;
  background: #fff;
  border: 1px solid #cbd5dd;
  border-radius: 7px;
  box-shadow: 0 2px 5px rgb(24 50 75 / 8%);
}

.trend-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: #e8edf0;
  border-bottom: 1px solid #cbd5dd;
}

.trend-range-controls {
  display: flex;
  gap: 8px;
}

.trend-range-controls button,
.trend-export-button {
  padding: 7px 13px;
  font-size: 0.8rem;
  font-weight: bold;
  border-radius: 4px;
}

.trend-range-controls button {
  color: #425765;
  background: #fff;
  border: 1px solid #9aabb6;
}

.trend-range-controls button:hover,
.trend-range-controls button:focus-visible,
.trend-range-controls button.active {
  color: #fff;
  background: #176a9b;
  border-color: #176a9b;
}

.trend-export-button {
  color: #fff;
  text-decoration: none;
  background: #176a9b;
}

.trend-status {
  min-height: 20px;
  margin: 0;
  padding: 8px 14px 0;
  color: #60717e;
  background: #eaf6fb;
}

.trend-status-error {
  color: #a01818;
}

.trend-chart {
  width: 100%;
  height: min(68vh, 620px);
  min-height: 420px;
}

@media (max-width: 1050px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-status {
    justify-content: flex-start;
  }

  .placeholder-grid,
  .equipment-grid {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }
}

@media (max-width: 1199px) and (min-width: 700px) {
  .equipment-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .app-header,
  .app-content {
    padding: 16px;
  }

  .app-logo {
    height: 46px;
  }

  .brand h1 {
    font-size: 1rem;
  }

  .app-nav {
    overflow-x: auto;
    padding: 0 8px;
  }

  .connection-bar {
    align-items: flex-start;
    flex-direction: column;
    gap: 7px;
    padding: 10px 16px;
  }

  .connection-bar p {
    margin-left: 0;
  }

  .placeholder-grid,
  .equipment-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 699px) {
  .equipment-grid {
    grid-template-columns: 1fr;
  }
}

/* V19 adjustment: enlarge penstock status images */
.equipment-card img,
.penstock-card img,
.device-card img,
.position-card img {
  width: min(82%, 320px);
  max-height: 230px;
  object-fit: contain;
}

.equipment-image-area,
.penstock-image-area,
.position-image-area,
.device-image-area {
  min-height: 230px;
  padding: 16px 12px;
}

/* V19 adjustment: enlarge penstock position images */
.penstock-image-area {
  min-height: 250px;
  padding: 16px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.penstock-image-area img[data-role="position-image"] {
  width: min(86%, 330px) !important;
  max-width: 330px !important;
  max-height: 235px !important;
  height: auto !important;
  object-fit: contain !important;
}
