:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --dark: #0f172a;
  --dark-2: #1e293b;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --green: #059669;
  --green-soft: #d1fae5;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

/* Top Navigation */
.topbar {
  background: var(--dark);
  color: #fff;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.5px;
  color: #fff;
  text-decoration: none;
}
.brand .dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 10px #10b981;
}
.scale-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.scale-pill {
  background: var(--dark-2);
  color: #cbd5e1;
  border: 1.5px solid #334155;
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}
.scale-pill:hover { border-color: #38bdf8; color: #fff; }
.scale-pill.active {
  background: #0284c7;
  border-color: #38bdf8;
  color: #fff;
  box-shadow: 0 0 0 3px rgba(56,189,248,0.22);
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.status-dot.online { background: #10b981; }
.status-dot.offline { background: #ef4444; }

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.nav-link {
  color: #cbd5e1;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.86rem;
  font-weight: 600;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  cursor: pointer;
}
.nav-link:hover { background: rgba(255,255,255,0.14); color: #fff; }

/* Layout */
.container {
  max-width: 1520px;
  margin: 0 auto;
  padding: 18px;
}
.grid-main {
  display: grid;
  grid-template-columns: 440px 1fr;
  gap: 18px;
  align-items: start;
}
@media (max-width: 1080px) {
  .grid-main { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(15,23,42,0.05);
  margin-bottom: 16px;
}
.card-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 12px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* LCD Weight Display */
.lcd-box {
  background: #020617;
  border: 2px solid #1e293b;
  border-radius: 14px;
  padding: 18px 20px;
  color: #34d399;
  position: relative;
  overflow: hidden;
}
.lcd-box.offline { border-color: #7f1d1d; color: #f87171; }
.lcd-box.unstable { border-color: #b45309; color: #fbbf24; }
.lcd-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: #94a3b8;
  margin-bottom: 6px;
}
.lcd-value {
  font-family: 'DejaVu Sans Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 3.3rem;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1.05;
  text-align: right;
}
.lcd-unit {
  font-size: 1.2rem;
  margin-left: 6px;
  opacity: 0.78;
}
.lcd-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 0.78rem;
  color: #94a3b8;
  border-top: 1px solid #1e293b;
  padding-top: 8px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}
.badge-green { background: var(--green-soft); color: #065f46; }
.badge-amber { background: var(--amber-soft); color: #92400e; }
.badge-red { background: var(--red-soft); color: #991b1b; }
.badge-blue { background: #e0f2fe; color: #075985; }
.badge-gray { background: #e2e8f0; color: #334155; }

/* Forms & Buttons */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.form-group { margin-bottom: 10px; }
.form-group.full { grid-column: 1 / -1; }
label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 4px;
}
input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(2,132,199,0.15);
}
.ecv-input {
  font-family: ui-monospace, monospace;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 16px;
  border-radius: 9px;
  font-weight: 700;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: #047857; }
.btn-amber { background: var(--amber); color: #fff; }
.btn-red { background: var(--red); color: #fff; }
.btn-outline { background: #fff; color: #1e293b; border: 1px solid var(--border); }
.btn-outline:hover { background: #f8fafc; }
.btn-sm { padding: 6px 11px; font-size: 0.8rem; border-radius: 7px; }
.btn-lg { padding: 14px 20px; font-size: 1.02rem; width: 100%; }

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.tab-btn {
  padding: 9px 15px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* Tables */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}
th, td {
  padding: 9px 10px;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
  vertical-align: middle;
}
th {
  background: var(--surface-2);
  color: #475569;
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
tr:hover td { background: #f8fafc; }

/* Photos */
.photo-thumb {
  width: 96px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  cursor: pointer;
}
.photo-preview-box {
  background: #0f172a;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #334155;
  margin-top: 8px;
}
.photo-preview-box img {
  width: 100%;
  max-height: 210px;
  object-fit: cover;
  display: block;
}
.photo-caption {
  padding: 8px 10px;
  color: #e2e8f0;
  font-size: 0.8rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}

/* Modal / Lightbox */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal-box {
  background: #fff;
  border-radius: 14px;
  max-width: 780px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}

/* Toast */
#toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--dark);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  display: none;
  z-index: 2000;
  max-width: 420px;
}
#toast.ok { border-left: 5px solid #10b981; }
#toast.err { border-left: 5px solid #ef4444; }
