:root {
  --color-primary: #1f4e79;
  --color-primary-dark: #163a5c;
  --color-accent: #d98c00;
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-border: #d9dee3;
  --color-text: #1c2733;
  --color-muted: #5b6b7a;
  --color-danger: #b3261e;
  --color-success: #1e7a3c;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--color-bg);
  color: var(--color-text);
}

.initial-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  font-size: 1.1rem;
  color: var(--color-muted);
}

#blazor-error-ui {
  background: #fdece9;
  border-top: 3px solid var(--color-danger);
  bottom: 0;
  box-shadow: 0 -1px 6px rgba(0,0,0,0.15);
  display: none;
  left: 0;
  padding: 0.8rem 1.2rem;
  position: fixed;
  width: 100%;
  z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; float: right; }

.app-layout { display: flex; min-height: 100vh; }

.app-sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--color-primary-dark);
  color: #eef2f6;
  padding: 1rem 0;
}
.app-sidebar .brand {
  font-weight: 700;
  font-size: 1.15rem;
  padding: 0 1.2rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: 0.6rem;
}
.app-sidebar nav a {
  display: block;
  padding: 0.55rem 1.2rem;
  color: #cfe0ef;
  text-decoration: none;
  font-size: 0.94rem;
}
.app-sidebar nav a.active, .app-sidebar nav a:hover {
  background: var(--color-primary);
  color: #fff;
}
.app-sidebar .nav-section {
  padding: 0.9rem 1.2rem 0.3rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8fa9c0;
}

.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.app-topbar {
  height: 56px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 1.2rem;
  gap: 0.8rem;
}
.app-topbar .user-chip { font-size: 0.88rem; color: var(--color-muted); }
.app-topbar button.link-btn {
  background: none; border: none; color: var(--color-primary); cursor: pointer; font-size: 0.88rem;
}

.app-content { padding: 1.4rem; flex: 1; }

h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.8rem; }

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  margin-bottom: 1.2rem;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
table.data-table th, table.data-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
}
table.data-table th { color: var(--color-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
table.data-table tr:hover { background: #f8fafb; }
table.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.7rem 1rem;
  align-items: end;
}
.form-field { display: flex; flex-direction: column; gap: 0.25rem; }
.form-field label { font-size: 0.8rem; color: var(--color-muted); }
.form-field input, .form-field select {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 5px;
  font-size: 0.92rem;
}
.form-field input[type=checkbox] { width: 1.1rem; height: 1.1rem; }

button, .btn {
  cursor: pointer;
  border-radius: 5px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: 0.42rem 0.85rem;
  font-size: 0.88rem;
  color: var(--color-text);
}
button.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
button.btn-primary:hover { background: var(--color-primary-dark); }
button.btn-danger { color: var(--color-danger); border-color: #f0c4c0; }
button.btn-danger:hover { background: #fdece9; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.btn-sm { padding: 0.25rem 0.55rem; font-size: 0.8rem; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.9rem; gap: 0.8rem; flex-wrap: wrap; }

.badge {
  display: inline-block;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-active { background: #e4f4e9; color: var(--color-success); }
.badge-inactive { background: #f1f2f4; color: var(--color-muted); }
.badge-status { background: #eaf1fa; color: var(--color-primary); }

.alert { padding: 0.6rem 0.9rem; border-radius: 6px; font-size: 0.88rem; margin-bottom: 0.8rem; }
.alert-error { background: #fdece9; color: var(--color-danger); border: 1px solid #f0c4c0; }
.alert-success { background: #e4f4e9; color: var(--color-success); border: 1px solid #bfe4cb; }

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--color-primary-dark), var(--color-primary));
}
.login-card {
  background: var(--color-surface);
  border-radius: 10px;
  padding: 2rem 2.2rem;
  width: 340px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.25);
}
.login-card h1 { text-align: center; color: var(--color-primary-dark); }
.login-card .form-field { margin-bottom: 0.9rem; }
.login-card button { width: 100%; margin-top: 0.4rem; }

.live-weight {
  font-size: 3rem;
  font-weight: 700;
  color: var(--color-primary-dark);
  font-variant-numeric: tabular-nums;
}
.live-weight.unstable { color: var(--color-accent); }
.live-weight-unit { font-size: 1.1rem; color: var(--color-muted); margin-left: 0.3rem; }

.receipt-shell {
  max-width: 620px;
  margin: 1.5rem auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.6rem 2rem;
}
.receipt-actions {
  max-width: 620px;
  margin: 0 auto 0.8rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}
.receipt-title {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-primary-dark);
  margin-bottom: 0.2rem;
}
.receipt-subtitle {
  text-align: center;
  color: var(--color-muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.receipt-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  color: var(--color-muted);
  border-bottom: 1px dashed var(--color-border);
  padding-bottom: 0.6rem;
  margin-bottom: 0.8rem;
}
.receipt-weights {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  text-align: center;
  background: #f4f6f8;
  border-radius: 6px;
  padding: 0.8rem 0;
  margin: 1rem 0;
}
.receipt-weights .label { font-size: 0.75rem; color: var(--color-muted); text-transform: uppercase; }
.receipt-weights .value { font-size: 1.3rem; font-weight: 700; color: var(--color-primary-dark); }
.receipt-row {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  font-size: 0.9rem;
  border-bottom: 1px solid #f0f2f4;
}
.receipt-row .k { color: var(--color-muted); }
.receipt-row .v { font-weight: 600; text-align: right; }
.receipt-footer {
  text-align: center;
  font-size: 0.75rem;
  color: var(--color-muted);
  margin-top: 1.2rem;
}

@media print {
  .receipt-actions, .app-sidebar, .app-topbar { display: none !important; }
  .receipt-shell { border: none; box-shadow: none; margin: 0; max-width: 100%; }
  body { background: #fff; }
}
