:root {
  --bg:#061624;
  --panel:#081c2a;
  --panel2:#0d2233;
  --border:#12364d;
  --text:#f2f6fa;
  --muted:#8ea1b1;
  --critical:#ff3d4f;
  --warning:#ffc21c;
  --normal:#00c86f;
  --purple:#9c4dff;
  --blue:#1693ff;
}

* { box-sizing:border-box; }

html { scroll-behavior:smooth; }

body {
  margin:0;
  background:
    radial-gradient(circle at 80% 0%, rgba(22,147,255,.10), transparent 28%),
    var(--bg);
  color:var(--text);
  font-family:Arial, Helvetica, sans-serif;
}

button,input { font:inherit; }
button { cursor:pointer; }

.app-shell {
  max-width:1240px;
  min-height:100vh;
  margin:0 auto;
  padding:18px 18px 92px;
}

.topbar {
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:16px;
  margin-bottom:18px;
}

.brand {
  display:flex;
  gap:12px;
  align-items:center;
}

.menu-icon {
  width:40px;
  height:40px;
  display:grid;
  place-items:center;
  border:1px solid var(--border);
  border-radius:10px;
  font-size:21px;
}

.brand h1 {
  margin:0;
  font-size:23px;
}

.brand p {
  margin:4px 0 0;
  color:var(--muted);
  font-size:11px;
}

.header-equipment {
  text-align:right;
  padding:8px 12px;
  border:1px solid var(--border);
  border-radius:10px;
  background:rgba(8,28,42,.76);
}

.header-equipment span {
  display:block;
  color:var(--muted);
  font-size:8px;
}

.header-equipment strong {
  display:block;
  margin-top:3px;
  color:#61b8ff;
  font-size:12px;
}

.app-page {
  display:none;
}

.app-page.active {
  display:block;
  animation:fadeIn .18s ease;
}

@keyframes fadeIn {
  from { opacity:0; transform:translateY(4px); }
  to { opacity:1; transform:translateY(0); }
}

.page-title {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  margin-bottom:14px;
}

.page-title h2 {
  margin:0;
  font-size:20px;
}

.page-title p {
  margin:4px 0 0;
  color:var(--muted);
  font-size:10px;
}

.card {
  border:1px solid var(--border);
  border-radius:13px;
  background:linear-gradient(180deg, rgba(13,34,51,.98), rgba(7,27,42,.98));
  box-shadow:0 15px 34px rgba(0,0,0,.16);
}

.summary-grid {
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:10px;
}

.summary-card {
  min-height:108px;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
}

.summary-icon {
  width:38px;
  height:38px;
  display:grid;
  place-items:center;
  border-radius:50%;
  border:2px solid currentColor;
  margin-bottom:5px;
}

.critical { color:var(--critical); }
.warning { color:var(--warning); }
.normal { color:var(--normal); }
.total { color:var(--purple); }

.summary-value {
  font-size:22px;
  font-weight:800;
}

.summary-label {
  margin-top:3px;
  font-size:8px;
  font-weight:800;
}

.critical-text { color:var(--critical); }
.warning-text { color:var(--warning); }
.normal-text { color:var(--normal); }
.total-text { color:var(--purple); }


.motor-card {
  margin-top:14px;
  padding:15px;
}

.motor-title-row {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
}

.motor-title-row h2 {
  margin:0;
  font-size:17px;
}

.motor-title-row p {
  margin:4px 0 0;
  color:var(--muted);
  font-size:9px;
}

.status-pill {
  padding:6px 10px;
  border-radius:5px;
  font-size:8px;
  font-weight:800;
}

.normal-bg { background:var(--normal); color:white; }
.warning-bg { background:var(--warning); color:#312500; }
.critical-bg { background:var(--critical); color:white; }
.replace-bg { background:#d90000; color:white; }

.motor-content {
  display:grid;
  grid-template-columns:1fr 1.2fr .65fr;
  align-items:center;
  gap:22px;
  margin-top:13px;
}

.motor-info {
  display:grid;
  gap:3px;
}

.info-row {
  display:grid;
  grid-template-columns:92px 1fr;
  gap:8px;
  padding:4px 0;
  font-size:10px;
}

.info-row span { color:var(--muted); }
.info-row strong { color:#dbe6ed; }
.info-row.accent strong { color:var(--warning); }

.motor-photo-wrap {
  position:relative;
  min-height:190px;
  display:grid;
  place-items:center;
  overflow:hidden;
  border-radius:12px;
  background:
    radial-gradient(circle at center, rgba(22,147,255,.22), transparent 56%),
    #04101a;
  border:1px solid rgba(73,180,255,.17);
}

.motor-photo {
  position:relative;
  z-index:2;
  width:100%;
  max-width:430px;
  height:190px;
  object-fit:contain;
  filter:drop-shadow(0 16px 20px rgba(0,0,0,.42));
}

.photo-glow {
  position:absolute;
  inset:20% 15%;
  background:rgba(22,147,255,.16);
  filter:blur(42px);
  border-radius:50%;
}

.overall-box {
  text-align:center;
}

.muted {
  color:var(--muted);
  font-size:8px;
}

.overall-status {
  margin-top:7px;
  padding:11px 6px;
  border-radius:6px;
  font-size:10px;
  font-weight:800;
}

.updated-label { margin-top:14px; }

.updated-time {
  white-space:pre-line;
  margin-top:3px;
  font-size:9px;
}


.dashboard-bottom-grid {
  display:grid;
  grid-template-columns:1.55fr .75fr;
  gap:12px;
  margin-top:14px;
}

.trend-card {
  min-height:320px;
  padding:15px;
}

.trend-header {
  display:flex;
  justify-content:space-between;
  gap:12px;
  align-items:flex-start;
}

.trend-header h2 {
  margin:0;
  font-size:15px;
}

.trend-header p {
  margin:4px 0 0;
  color:var(--muted);
  font-size:9px;
}

.legend {
  display:flex;
  gap:14px;
  margin:12px 0 6px;
  font-size:9px;
}

.legend-r { color:var(--critical); }
.legend-s { color:var(--warning); }
.legend-t { color:var(--normal); }

#trendCanvas {
  display:block;
  width:100%;
  height:235px;
}

.action-stack {
  display:grid;
  gap:10px;
}

.action-card {
  width:100%;
  min-height:96px;
  display:grid;
  grid-template-columns:42px 1fr auto;
  align-items:center;
  gap:9px;
  border:1px solid var(--border);
  padding:12px;
  color:var(--text);
  text-align:left;
}

.action-card:hover {
  border-color:#1e5575;
  transform:translateY(-1px);
}

.action-card small {
  display:block;
  margin-top:4px;
  color:var(--muted);
  font-size:8px;
}

.action-icon { font-size:26px; }
.blue { color:var(--blue); }
.green { color:var(--normal); }
.purple { color:var(--purple); }


.equipment-grid {
  display:grid;
  grid-template-columns:repeat(2,1fr);
  gap:14px;
}

.equipment-card {
  padding:15px;
  cursor:pointer;
  transition:.18s ease;
}

.equipment-card:hover {
  transform:translateY(-2px);
  border-color:#1f5d82;
}

.equipment-card.selected {
  box-shadow:0 0 0 2px rgba(22,147,255,.23);
  border-color:#1687dc;
}

.equipment-top {
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:10px;
}

.equipment-name {
  font-size:18px;
  font-weight:800;
}

.equipment-title {
  margin-top:4px;
  color:var(--muted);
  font-size:9px;
}

.equipment-image {
  width:100%;
  height:150px;
  object-fit:contain;
  margin:10px 0;
  background:#04101a;
  border-radius:9px;
}

.equipment-meta {
  display:grid;
  grid-template-columns:repeat(2,1fr);
  gap:8px;
  margin-top:8px;
}

.meta-box {
  padding:9px;
  background:#061624;
  border:1px solid var(--border);
  border-radius:8px;
}

.meta-box span {
  display:block;
  color:var(--muted);
  font-size:8px;
}

.meta-box strong {
  display:block;
  margin-top:3px;
  font-size:10px;
}

.select-equipment-btn {
  width:100%;
  margin-top:12px;
}


.measurement-toolbar {
  display:flex;
  gap:8px;
}

.measurement-card {
  overflow:hidden;
}

.formula-info {
  padding:11px 12px;
  color:#a7b7c4;
  font-size:9px;
  border-bottom:1px solid var(--border);
}

.table-wrap {
  overflow:auto;
  max-height:calc(100vh - 255px);
}

table {
  width:100%;
  min-width:1500px;
  border-collapse:collapse;
}

thead {
  position:sticky;
  top:0;
  z-index:4;
  background:#0d2b43;
}

th,td {
  padding:10px 8px;
  border-top:1px solid rgba(255,255,255,.04);
  text-align:center;
  font-size:9px;
}

th {
  color:#c5d2dc;
  font-size:8px;
}

.row-number {
  color:#8da6b8;
  font-weight:800;
}

.editable-value {
  color:white;
  font-weight:800;
}

.computed {
  color:#d2dee6;
}

.status-cell {
  display:inline-block;
  min-width:76px;
  padding:5px 8px;
  border-radius:5px;
  font-size:8px;
  font-weight:800;
}

.correction-badge {
  display:inline-block;
  min-width:64px;
  padding:4px 6px;
  border-radius:5px;
  font-size:7px;
  font-weight:800;
}

.correction-badge.manual {
  color:var(--warning);
  border:1px solid rgba(255,194,28,.36);
  background:rgba(255,194,28,.10);
}

.correction-badge.auto {
  color:var(--normal);
  border:1px solid rgba(0,200,111,.36);
  background:rgba(0,200,111,.10);
}

.reading-count {
  display:block;
  color:var(--muted);
  font-size:7px;
  margin-top:3px;
}

.edit-button {
  padding:5px 9px;
  color:#5fb9ff;
  border:1px solid rgba(22,147,255,.48);
  border-radius:5px;
  background:rgba(22,147,255,.08);
}

.primary-button,.secondary-button,.ghost-btn,.link-button {
  border-radius:7px;
  font-weight:700;
}

.primary-button {
  padding:9px 13px;
  color:white;
  border:1px solid #2687d5;
  background:#1177c5;
}

.secondary-button {
  padding:9px 13px;
  color:#dce6ed;
  border:1px solid var(--border);
  background:#102a3b;
}

.ghost-btn {
  padding:8px 11px;
  color:#72c0ff;
  border:1px solid rgba(22,147,255,.35);
  background:rgba(22,147,255,.07);
}

.link-button {
  padding:5px 8px;
  color:var(--blue);
  border:none;
  background:transparent;
}


.placeholder-card {
  min-height:300px;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  text-align:center;
  padding:30px;
}

.placeholder-icon {
  font-size:48px;
  color:var(--blue);
}

.placeholder-card h3 {
  margin:12px 0 0;
}

.placeholder-card p {
  max-width:520px;
  color:var(--muted);
  font-size:10px;
  line-height:1.6;
}


.bottom-nav {
  position:fixed;
  left:50%;
  bottom:0;
  transform:translateX(-50%);
  z-index:20;
  width:min(1240px,100%);
  height:70px;
  display:grid;
  grid-template-columns:repeat(5,1fr);
  border-top:1px solid var(--border);
  background:rgba(7,27,42,.97);
  backdrop-filter:blur(13px);
}

.bottom-nav button {
  border:none;
  background:transparent;
  color:var(--muted);
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  gap:3px;
}

.bottom-nav button span {
  font-size:20px;
}

.bottom-nav button small {
  font-size:8px;
}

.bottom-nav button.active {
  color:var(--blue);
}


.modal-overlay {
  position:fixed;
  inset:0;
  z-index:100;
  display:grid;
  place-items:center;
  padding:18px;
  background:rgba(0,0,0,.68);
  backdrop-filter:blur(5px);
}

.modal-overlay.hidden {
  display:none;
}

.modal-card {
  width:min(720px,100%);
  border:1px solid #1a4762;
  border-radius:14px;
  overflow:hidden;
  background:#081c2a;
  box-shadow:0 30px 90px rgba(0,0,0,.54);
}

.modal-header {
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  padding:18px;
  border-bottom:1px solid var(--border);
}

.modal-header h2 {
  margin:0;
  font-size:18px;
}

.modal-header p {
  margin:5px 0 0;
  color:var(--muted);
  font-size:9px;
}

.close-button {
  border:none;
  background:transparent;
  color:white;
  font-size:28px;
}

#measurementForm {
  padding:18px;
}

.readonly-info {
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:9px;
  margin-bottom:14px;
}

.readonly-info > div {
  padding:9px;
  border-radius:8px;
  border:1px solid var(--border);
  background:#061624;
}

.readonly-info span {
  display:block;
  color:var(--muted);
  font-size:8px;
}

.readonly-info strong {
  display:block;
  margin-top:4px;
  font-size:12px;
}

.form-grid {
  display:grid;
  grid-template-columns:repeat(2,1fr);
  gap:12px;
}

.form-grid label {
  display:flex;
  flex-direction:column;
  gap:6px;
  font-size:9px;
  font-weight:700;
  color:#c9d5de;
}

.form-grid input {
  padding:10px;
  color:white;
  outline:none;
  border-radius:7px;
  border:1px solid #1a4762;
  background:#061624;
}

.form-grid input:focus {
  border-color:var(--blue);
}

.field-hint {
  color:var(--muted);
  font-size:8px;
  line-height:1.4;
}

.calculation-note {
  margin-top:14px;
  padding:10px;
  color:#a9c9df;
  font-size:8px;
  line-height:1.5;
  border:1px solid rgba(22,147,255,.25);
  border-radius:8px;
  background:rgba(22,147,255,.07);
}

.modal-footer {
  display:flex;
  justify-content:flex-end;
  gap:8px;
  margin-top:16px;
}

.toast {
  position:fixed;
  right:20px;
  bottom:88px;
  z-index:150;
  opacity:0;
  transform:translateY(10px);
  pointer-events:none;
  transition:.2s ease;
  padding:11px 14px;
  color:white;
  border:1px solid var(--border);
  border-radius:8px;
  background:#102a3b;
}

.toast.show {
  opacity:1;
  transform:translateY(0);
}


@media (max-width:820px) {
  .app-shell { padding:12px 10px 86px; }
  .summary-grid { gap:6px; }
  .summary-card { min-height:92px; }
  .summary-value { font-size:18px; }

  .motor-content {
    grid-template-columns:1fr;
  }

  .motor-photo-wrap {
    min-height:170px;
  }

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

  .readonly-info,
  .form-grid {
    grid-template-columns:1fr 1fr;
  }
}

@media (max-width:520px) {
  .brand p { display:none; }
  .header-equipment span { display:none; }

  .page-title {
    align-items:flex-start;
  }

  .summary-label {
    font-size:7px;
  }

  .summary-icon {
    width:32px;
    height:32px;
  }

  .readonly-info,
  .form-grid {
    grid-template-columns:1fr;
  }
}


/* V10 History by Date */
.history-toolbar {
  display:flex;
  gap:8px;
  align-items:center;
}

.date-filter {
  padding:8px 10px;
  color:#dce7ee;
  border:1px solid var(--border);
  border-radius:7px;
  background:#071b2a;
}

.history-card {
  overflow:hidden;
}

.history-summary {
  display:grid;
  grid-template-columns:repeat(3, 1fr);
  gap:0;
  border-bottom:1px solid var(--border);
}

.history-summary > div {
  padding:12px;
  text-align:center;
  border-right:1px solid var(--border);
}

.history-summary > div:last-child {
  border-right:none;
}

.history-summary span {
  display:block;
  color:var(--muted);
  font-size:8px;
}

.history-summary strong {
  display:block;
  margin-top:4px;
  font-size:13px;
}

.history-table {
  min-width:1120px;
}

.history-table-wrap {
  max-height:calc(100vh - 260px);
}

.history-date-cell {
  color:#6ec1ff;
  font-weight:700;
}

.history-empty {
  padding:30px !important;
  color:var(--muted);
  text-align:center;
}

@media (max-width:680px) {
  .history-toolbar {
    width:100%;
    flex-direction:column;
    align-items:stretch;
  }

  .history-summary {
    grid-template-columns:1fr;
  }

  .history-summary > div {
    border-right:none;
    border-bottom:1px solid var(--border);
  }
}


/* V10.2 */
.danger-outline-btn {
  padding:8px 11px;
  border:1px solid rgba(255,61,79,.55);
  border-radius:7px;
  background:rgba(255,61,79,.08);
  color:#ff6877;
  font-weight:700;
}

.danger-outline-btn:hover {
  background:rgba(255,61,79,.16);
}


/* V10.4 Expanded Motor List */
.equipment-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.equipment-image {
  height: 115px;
}

.equipment-card {
  padding: 12px;
}

.equipment-name {
  font-size: 16px;
}

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

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