:root {
  --navy: #0f2744;
  --navy-2: #16365c;
  --teal: #0f766e;
  --teal-2: #115e59;
  --ink: #142033;
  --muted: #5c6b80;
  --line: #e4e9f0;
  --bg: #f3f6f8;
  --card: #ffffff;
  --danger: #b42318;
  --ok: #067647;
  --warn: #b54708;
  --sat: env(safe-area-inset-top);
  --sar: env(safe-area-inset-right);
  --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left);
  --touch: 44px;
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow-x: hidden;
}

a { color: var(--teal-2); }

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--navy);
  color: #fff;
  padding-top: var(--sat);
  padding-left: var(--sal);
  padding-right: var(--sar);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .2);
}

.app-header .navbar {
  padding-top: 0;
  padding-bottom: 0;
}

.navbar-brand {
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  color: #fff !important;
  font-weight: 700;
  letter-spacing: .01em;
}

.navbar-toggler {
  min-width: var(--touch);
  min-height: var(--touch);
  border-color: rgba(255, 255, 255, .35);
}

.navbar-dark .navbar-nav .nav-link,
.app-header .nav-link,
.app-header .btn-link {
  color: #e8eef6 !important;
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  padding: 10px 12px;
}

.app-header .dropdown-menu {
  border: 0;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(15, 39, 68, .16);
  padding: 6px;
}

.app-header .dropdown-item {
  min-height: var(--touch);
  display: flex;
  align-items: center;
  border-radius: 8px;
}

.logout-form { margin: 0; }

.app-main {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 16px max(16px, var(--sar)) calc(28px + var(--sab)) max(16px, var(--sal));
}

.page-head { margin-bottom: 14px; }
.page-head h1 { font-size: 1.45rem; margin: 0 0 4px; }
.page-head p { margin: 0; color: var(--muted); }

.dash-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.dash-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  min-height: 112px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 1px 2px rgba(15, 39, 68, .04);
}

.dash-card strong { font-size: 1.05rem; }
.dash-card span { color: var(--muted); font-size: .92rem; }
.dash-card em {
  font-style: normal;
  font-weight: 700;
  color: var(--teal-2);
}

.filter-panel, .panel, .auth-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 14px;
}

.filter-panel > summary {
  min-height: var(--touch);
  display: flex;
  align-items: center;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.filter-panel > summary::-webkit-details-marker { display: none; }

.filter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 8px;
}

.field label {
  display: block;
  font-size: .82rem;
  font-weight: 650;
  margin-bottom: 6px;
  color: var(--navy);
}

.field input:not([type="checkbox"]),
.field select,
.auth-card input,
.btn,
.nav-link {
  min-height: var(--touch);
}

.validation-summary-valid { display: none; }

.field input:not([type="checkbox"]),
.field select,
.auth-card input {
  width: 100%;
  border: 1px solid #cfd7e3;
  border-radius: 10px;
  padding: 8px 12px;
  background: #fff;
  font-size: 16px;
}

.check {
  min-height: var(--touch);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.check input { width: 22px; height: 22px; }

.btn {
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-2); color: #fff; }
.btn-ghost { background: #e8eef5; color: var(--navy); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: .9rem;
  margin: 0 0 10px;
}

.totals {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.total-chip {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.total-chip span { display: block; color: var(--muted); font-size: .78rem; }
.total-chip strong { font-size: 1.05rem; }

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
}

.report-table th,
.report-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
}

.report-table th {
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}

.report-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.side {
  display: inline-flex;
  min-width: 28px;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 800;
}

.side-b { background: #fef4e6; color: var(--warn); }
.side-a { background: #e7f6ef; color: var(--ok); }

.tone-done { background: #e9f8ef; }
.tone-late { background: #fdecec; }

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}

.pager-links { display: flex; gap: 8px; }

.alert {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.alert-danger { background: #fdecec; color: var(--danger); }
.alert-ok { background: #e7f6ef; color: var(--ok); }

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

.login-body {
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 0% 0%, rgba(29, 78, 137, .55), transparent 60%),
    linear-gradient(165deg, #0f2744 0%, #0e3a40 55%, #0f766e 140%);
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding:
    calc(20px + var(--sat))
    calc(16px + var(--sar))
    calc(20px + var(--sab))
    calc(16px + var(--sal));
}

.login-card {
  width: min(420px, 100%);
  background: #fff;
  color: var(--ink);
  border-radius: 22px;
  padding: 28px 22px 22px;
  box-shadow: 0 24px 60px rgba(6, 18, 36, .28);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.login-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--navy);
  color: #fff;
  font-weight: 800;
  letter-spacing: .02em;
}

.login-brand strong { display: block; font-size: 1.05rem; }
.login-brand span { color: var(--muted); font-size: .88rem; }

.login-card h1 {
  margin: 0 0 6px;
  font-size: 1.55rem;
}

.login-card .lede {
  margin: 0 0 18px;
  color: var(--muted);
}

.login-card .btn-primary {
  width: 100%;
  margin-top: 4px;
}

@media (min-width: 768px) {
  .login-card { padding: 36px 32px 28px; }
}

.user-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.stack-form { display: grid; gap: 12px; }

@media (max-width: 575.98px) {
  .report-table thead { display: none; }
  .report-table, .report-table tbody, .report-table tr, .report-table td { display: block; width: 100%; }
  .report-table tr {
    margin: 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
  }
  .report-table td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--line);
  }
  .report-table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--muted);
    flex: 0 0 42%;
  }
  .report-table .num { text-align: right; }
  .table-scroll { background: transparent; border: 0; overflow: visible; }
}

@media (min-width: 576px) {
  .report-table.months { min-width: 1100px; }
  .report-table.wide { min-width: 980px; }
  .report-table.months th:first-child,
  .report-table.months td:first-child {
    position: sticky;
    left: 0;
    background: #fff;
    z-index: 2;
  }
  .report-table.months th:first-child { z-index: 3; background: #f8fafc; }
}

@media (min-width: 768px) {
  .dash-grid { grid-template-columns: 1fr 1fr; }
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .totals { grid-template-columns: 1fr 1fr; }
  .app-main { padding-top: 22px; }
}

@media (min-width: 1024px) {
  .filter-grid.wide { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: 1fr 1fr 1fr; }
  .totals.three { grid-template-columns: 1fr 1fr 1fr; }
}

.product-open { min-height: var(--touch); min-width: 72px; }

.product-dialog {
  width: min(960px, calc(100vw - 16px));
  max-height: min(86vh, 900px);
  margin: auto;
  border: 0;
  border-radius: 16px;
  padding: 0;
  color: var(--ink);
}

.product-dialog::backdrop { background: rgba(15, 39, 68, .45); }

.product-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.product-dialog-head h2 { margin: 0; font-size: 1.15rem; }

.product-dialog-body {
  overflow: auto;
  max-height: calc(86vh - 72px);
  padding: 12px 12px calc(12px + var(--sab));
}

.supplier-text { white-space: pre-wrap; }
