:root {
  --primary: #2c8795;
  --primary-dark: #1f6570;
  --primary-tint: #eaf4f5;
  --primary-soft: #7fbcc5;
  --chart-track: #e3eaea;
  --chart-track-2: #cfe0e2;
  --app-bg: #eef1f0;
  --surface: #ffffff;
  --surface-alt: #fafbfb;
  --surface-head: #f7f9f9;
  --border: #dde3e3;
  --border-soft: #eceff0;
  --border-row: #f2f5f5;
  --text: #101a1b;
  --text-2: #3c5053;
  --text-3: #6f8285;
  --text-4: #8a9a9c;
  --text-5: #9caaab;
  --warn: #c58a45;
  --warn-text: #a8722f;
  --warn-bg: #fdf6ee;
  --danger: #b8564a;
  --danger-bg: #f7e8e6;
  --ok-dot: #a8e0b4;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--app-bg);
  color: var(--text);
  font-family: "Archivo", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 13px;
  overflow-x: hidden;
}

table, .live-netto-value, .live-bt-value, .micro-label, td.netto-cell, td.alibi-cell {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

h1 { font-family: "Archivo", sans-serif; font-weight: 600; margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* shell */
.shell-header { background: var(--primary); color: #fff; }
.shell-nav {
  display: flex; align-items: center; gap: 30px;
  padding: 14px 30px;
  border-bottom: 1px solid rgba(255, 255, 255, .18);
}
.shell-logo img { height: 20px; filter: brightness(0) invert(1); display: block; }
.shell-links { display: flex; gap: 22px; flex: 1; }
.shell-links a {
  color: rgba(255, 255, 255, .72);
  font-weight: 500; font-size: 13px; padding-bottom: 2px;
}
.shell-links a.active {
  color: #fff; font-weight: 600;
  border-bottom: 2px solid #fff;
}
.nav-badge {
  display: inline-block; margin-left: 5px; padding: 1px 5px;
  font-family: "JetBrains Mono", monospace; font-size: 9.5px; font-weight: 700;
  letter-spacing: .04em; border-radius: 2px; vertical-align: 1px;
  background: rgba(255, 255, 255, .18); color: rgba(255, 255, 255, .92);
}
.shell-account { display: flex; align-items: center; gap: 12px; }
/* superadmin impersonating another user -- click returns to the original account */
.shell-impersonation { margin: 0; }
.shell-impersonation button {
  background: #7a5ba8; color: #fff; border: 1px solid rgba(255, 255, 255, .35); border-radius: 3px;
  padding: 5px 10px; font: 500 12px "Archivo", sans-serif; cursor: pointer; white-space: nowrap;
}
.shell-impersonation button:hover { background: #6a4d96; }
.shell-avatar {
  width: 28px; height: 28px; border-radius: 3px;
  background: rgba(255, 255, 255, .9); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 11px;
}
.shell-logout button {
  background: transparent; color: rgba(255, 255, 255, .8); border: none;
  cursor: pointer; font-size: 12px; font-family: "Archivo", sans-serif;
}
.shell-logout button:hover { color: #fff; }

.shell-page-header { padding: 18px 30px 20px; }
.page-breadcrumb {
  font-family: "JetBrains Mono", monospace; font-size: 11px; font-weight: 500;
  letter-spacing: .1em; text-transform: uppercase; color: rgba(255, 255, 255, .66);
  margin-bottom: 6px;
}
.page-header-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.page-header-row h1 { font-size: 26px; color: #fff; letter-spacing: -.015em; }
.page-meta {
  margin-top: 10px; font-family: "JetBrains Mono", monospace; font-size: 12.5px;
  color: rgba(255, 255, 255, .88); display: flex; align-items: center; gap: 8px;
}
.page-actions { display: flex; gap: 10px; }

.btn {
  border-radius: 3px; padding: 10px 16px; font-family: "Archivo", sans-serif;
  font-size: 12.5px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); font-weight: 500; }
.btn-secondary:hover { border-color: #b9c6c6; }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.shell-page-header .btn-secondary { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .42); }
.shell-page-header .btn-primary { background: #fff; color: var(--primary-dark); }
.btn-block { width: 100%; padding: 13px; font-size: 14px; }

.btn.btn-sm { padding: 6px 10px; font-size: 11.5px;}
.btn.btn-icon { padding: 8px; }

.page-action-form { margin: 0; }

.shell-content { padding: 22px 30px 30px; }

/* card */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; margin-bottom: 18px; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 20px; font-weight: 600; font-size: 13px;
  border-bottom: 1px solid var(--border-soft);
}
.card-header-meta { font-family: "JetBrains Mono", monospace; font-weight: 500; font-size: 11px; color: var(--text-4); }
.card-body { padding: 16px 20px; }
.card-footer { padding: 13px 20px; background: var(--surface-alt); border-top: 1px solid var(--border-soft); }
.empty-state { padding: 40px 20px; text-align: center; color: var(--text-3); }

/* forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 13px; }
.field label {
  font-family: "JetBrains Mono", monospace; font-size: 10.5px; font-weight: 500;
  letter-spacing: .12em; color: var(--text-4); text-transform: uppercase;
}
.field input, .field select {
  padding: 11px 13px; border: 1px solid var(--border); border-radius: 3px;
  font-family: "Archivo", sans-serif; font-size: 13.5px; color: var(--text);
  line-height: 1.3; background-color: #fff;
}
.field select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23667' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center;
}
.field input:focus, .field select:focus { outline: 2px solid var(--primary); outline-offset: 2px; border-color: var(--primary); }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); }
.checkbox-row input { width: 14px; height: 14px; accent-color: var(--primary); border-radius: 2px; }
.form-error { background: var(--danger-bg); color: var(--danger); border-radius: 3px; padding: 10px 13px; margin-bottom: 16px; font-size: 12px; }

.filters { display: flex; flex-wrap: wrap; gap: 13px; align-items: end; padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.filters .field { margin-bottom: 0; min-width: 150px; }

/* table */
.table-wrap { overflow-x: auto; max-height: calc(100vh - 220px); overflow-y: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 12px; }
.table th {
  text-align: right; padding: 10px 20px; background: var(--surface-head);
  font-size: 10px; font-weight: 500; letter-spacing: .09em; text-transform: uppercase; color: var(--text-4);
  border-bottom: 1px solid var(--border);
}
.table thead { position: sticky; top: 0; z-index: 1; }
.table th a { color: inherit; text-decoration: none; }
.table th a:hover { color: var(--text-2); }
.col-hidden { display: none; }
.col-picker { position: relative; }
.col-picker summary { cursor: pointer; list-style: none; }
.col-picker summary::-webkit-details-marker { display: none; }
.col-picker-menu {
  position: absolute; top: 100%; right: 0; margin-top: 4px; z-index: 10;
  background: var(--surface); border: 1px solid var(--border); border-radius: 4px;
  padding: 8px 12px; display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; white-space: nowrap;
}

/* Deliberately NOT position:absolute -- .table-wrap scrolls (overflow:
   auto), which clips anything floated out of a cell's own box. Flowing in
   place just grows the row instead. */
.row-actions { text-align: right; white-space: nowrap; }
.row-actions > a { font-size: 12px; }
.row-actions details { display: inline-block; text-align: left; vertical-align: top; }
.row-actions summary { cursor: pointer; list-style: none; font-size: 12px; color: var(--text-3); }
.row-actions summary:hover { color: var(--text); }
.row-actions summary::-webkit-details-marker { display: none; }
.row-actions .danger-confirm summary { color: var(--danger); }
.row-actions details form {
  margin-top: 8px; background: var(--surface-alt); border: 1px solid var(--border); border-radius: 4px;
  padding: 12px;
}
.row-actions .danger-confirm form { display: flex; white-space: normal; max-width: 220px; }
.row-actions .link-action {
  background: none; border: none; padding: 0; font: inherit; cursor: pointer;
  font-size: 12px; color: var(--text-3); margin-right: 12px;
}
.row-actions .link-action:hover { color: var(--text); }
.row-actions .inline-form { display: inline; }

/* modal (native <dialog>) */
.modal { border: none; border-radius: 6px; padding: 20px; width: 340px; max-width: calc(100vw - 32px); }
.modal::backdrop { background: rgba(16, 26, 27, .45); }
.modal .field { margin-bottom: 13px; }
.modal-title { margin: 0 0 16px; font-size: 15px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.table th:first-child, .table td:first-child { text-align: left; }
.table td { text-align: right; padding: 12px 20px; border-bottom: 1px solid var(--border-row); color: var(--text-2); }
.table tbody tr:hover { background: var(--surface-head); }
.table .netto-cell { color: var(--text); font-weight: 600; }
.table .alibi-cell { color: var(--primary); }
.table .dim { color: var(--text-5); text-align: center; }
.row-flash { animation: rowFlash 600ms ease-out; }
@keyframes rowFlash { from { background: var(--primary-tint); } to { background: transparent; } }

.pager { display: flex; justify-content: space-between; padding: 13px 20px; font-size: 12px; }

/* badges & status */
.badge { display: inline-block; border-radius: 2px; padding: 3px 8px; font-family: "JetBrains Mono", monospace; font-size: 10.5px; font-weight: 600; }
.badge-tint { background: var(--primary-tint); color: var(--primary-dark); }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-critical { background: red; color: white; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.status-dot.online { background: var(--ok-dot); }
.status-dot.offline { background: var(--danger); }
.status-dot.unknown { background: var(--text-5); }
.status-dot.pulsing { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .35; transform: scale(.82); } }

/* scale list */
.scale-card-list, .attention-list { display: flex; flex-direction: column; }
.scale-list-item { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border-row); color: var(--text); }
.scale-list-item:last-child { border-bottom: none; }
.scale-list-item:hover { background: var(--surface-head); }
.scale-list-name { flex: 1; font-weight: 500; }
.scale-list-value { font-family: "JetBrains Mono", monospace; font-size: 12.5px; font-weight: 600; color: var(--text); }
.scale-list-value.pending { color: var(--text-5); font-weight: 400; }
.scale-list-arrow { color: var(--text-4); }

/* dashboard */
.dashboard-top-row { display: grid; grid-template-columns: 1fr 1fr 320px; gap: 18px; align-items: start; margin-bottom: 18px; }
.dashboard-top-row .card { margin-bottom: 0; }
.attention-card .attention-list { max-height: 280px; overflow-y: auto; }
.attention-card .attention-badge { white-space: nowrap; }

/* scale detail */
.scale-grid { display: grid; grid-template-columns: 1fr 320px; gap: 18px; align-items: start; }
.scale-main, .scale-side { min-width: 0; }
.scale-side { display: flex; flex-direction: column; }

.live-body { display: flex; }
.live-cell { padding: 24px 26px 26px; border-right: 1px solid var(--border-soft); }
.live-cell:last-child { border-right: none; }
.live-cell-netto { min-width: 300px; }
.live-cell-bt { min-width: 132px; display: flex; flex-direction: column; gap: 16px; justify-content: center; }
.live-cell-chart { flex: 1; }

.micro-label { font-size: 10.5px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase; color: var(--text-4); margin-bottom: 8px; }
.live-netto-value { font-size: 74px; font-weight: 700; line-height: .9; letter-spacing: -.055em; }
.live-netto-value.dim { color: var(--text-5); }
.live-bt-value { font-size: 21px; font-weight: 600; }
.live-badge-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.live-tolerance { font-family: "JetBrains Mono", monospace; font-size: 11px; color: var(--text-4); }

.live-chart-labels {
  display: flex; justify-content: space-between; gap: 12px; white-space: nowrap;
  font-family: "JetBrains Mono", monospace; font-size: 10.5px; font-weight: 500; color: var(--text-4);
  margin-bottom: 10px; min-width: 0;
}
.live-chart-labels span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.live-chart { display: flex; align-items: flex-end; gap: 3px; height: 96px; }
.live-chart-bar { flex: 1; background: var(--chart-track); border-radius: 1px; min-height: 4px; }
.live-chart-bar:nth-last-child(-n+3) { background: var(--primary-soft); }
.live-chart-bar:last-child { background: var(--primary); }

.live-footer { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.weigh-form { display: flex; gap: 10px; flex: 1; }
.weigh-form input { flex: 1; max-width: 220px; padding: 11px 13px; border: 1px solid var(--border); border-radius: 3px; font-family: "Archivo", sans-serif; }
.live-footer-note { font-family: "JetBrains Mono", monospace; font-size: 11px; color: var(--text-5); margin-left: auto; }

.kv-list > div { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border-row); font-size: 12.5px; }
.kv-list > div:last-child { border-bottom: none; }
.kv-list span { color: var(--text-3); }
.kv-list strong { color: var(--text); font-weight: 500; }

.gateway-note { border-left: 2px solid #d4dcdc; padding: 12px 14px; font-size: 11.5px; line-height: 1.55; color: var(--text-3); }

.hidden { display: none; }

.kpi-tile { flex: 1; }
.kpi-value { font-size: 32px; font-weight: 700; font-family: "JetBrains Mono", monospace; }

.shortcut-row { display: flex; gap: 10px; margin-bottom: 18px; }

.credential-reveal { background: var(--primary-tint); border: 1px solid #b9d9dd; border-radius: 4px; padding: 16px 20px; margin-bottom: 18px; color: var(--primary-dark); }
.credential-reveal code { font-family: "JetBrains Mono", monospace; background: rgba(255,255,255,.6); padding: 1px 5px; border-radius: 2px; }

.daily-chart { display: flex; justify-content: space-between; align-items: flex-end; gap: 6px; height: 90px; padding-top: 10px; }
.daily-chart-col { display: flex; flex-direction: column; align-items: center; gap: 6px; flex: 1; height: 100%; justify-content: flex-end; }
.daily-chart-bar { width: 100%; background: var(--chart-track-2); border-radius: 1px; min-height: 3px; }
.daily-chart-bar.active { background: var(--primary); }
.daily-chart-col span { font-family: "JetBrains Mono", monospace; font-size: 10px; color: var(--text-4); }
.daily-chart-col span.active { color: var(--primary); font-weight: 600; }

/* login */
body.login-page { background: var(--primary); }
.login-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 44px 40px; }
.login-logo { width: 196px; filter: brightness(0) invert(1); margin-bottom: 32px; }
.login-card { width: 100%; max-width: 360px; padding: 30px; margin-bottom: 0; }
.login-card h1 { font-size: 18px; letter-spacing: -.01em; }
.login-subtitle { font-family: "JetBrains Mono", monospace; font-size: 12px; color: var(--text-4); margin: 6px 0 22px; }
.login-row { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 18px; }
.password-row { display: flex; gap: 8px; align-items: center; }
.password-row input { flex: 1; }
.link-btn { background: none; border: none; color: var(--primary); font-size: 11.5px; font-weight: 500; cursor: pointer; padding: 0; }
.login-footer { font-family: "JetBrains Mono", monospace; font-size: 11px; color: rgba(255, 255, 255, .6); margin-top: 24px; }

/* reporty */
.reports-grid { display: grid; grid-template-columns: 1fr 300px; gap: 18px; align-items: start; }
.reports-main, .reports-side { min-width: 0; display: flex; flex-direction: column; gap: 18px; }
.reports-side .card { margin-bottom: 0; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 14px; border: 1px dashed var(--text-5); font-size: 12px; color: var(--text-3); cursor: pointer; }
.chip input { accent-color: var(--primary); }
.chip:has(input:checked) { background: var(--primary-tint); border: 1px solid #b9d9dd; color: var(--primary-dark); }

.schedule-card { border: 1px solid var(--border); border-radius: 4px; padding: 12px 14px; }
.schedule-tile { border: 1px dashed var(--text-5); border-radius: 4px; padding: 12px 14px; background: none; color: var(--text-3); font-size: 12.5px; cursor: pointer; text-align: center; width: 100%; }
.schedule-tile:hover { border-color: var(--primary); color: var(--primary-dark); }

/* responsive */
@media (max-width: 900px) {
  .shell-links { overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  .scale-grid, .dashboard-top-row, .reports-grid { grid-template-columns: 1fr; }
  .live-body { flex-direction: column; }
  .live-cell, .live-cell-netto, .live-cell-bt { min-width: 0; border-right: none; border-bottom: 1px solid var(--border-soft); }
  .filters { flex-direction: column; align-items: stretch; }
}

@media (max-width: 640px) {
  .shell-nav { padding: 12px 16px; gap: 16px; }
  .shell-page-header, .shell-content { padding-left: 16px; padding-right: 16px; }
  .page-header-row { flex-wrap: wrap; }
  .live-netto-value { font-size: 52px; }
  .card-header { flex-wrap: wrap; gap: 6px; }
  .live-footer { flex-direction: column; align-items: stretch; }
  .weigh-form { min-width: 0; flex-wrap: wrap; }
  .weigh-form input { max-width: none; }
  .live-footer-note { margin-left: 0; }
  .field input, .field select, .weigh-form input { font-size: 16px; }
  .live-cell-chart { display: none; }
}

/* scale settings (templates/scale_settings.php) */
.settings-card { max-width: 520px; }
.settings-card .field-hint { margin: -6px 0 13px; font-size: 12px; color: var(--text-4); }
.settings-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
