* { box-sizing: border-box; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  margin: 0; color: #1a1a1a; background: #eef1f6;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: #16324f;
  box-shadow: 0 2px 8px rgba(10, 25, 47, .25);
}
header h1 { font-size: 18px; margin: 0; color: #fff; font-weight: 700; letter-spacing: .02em; }
header .muted { color: rgba(255, 255, 255, .75); }

.panel {
  margin: 18px 24px; padding: 20px 24px;
  background: #fff; border: none; border-radius: 12px;
  box-shadow: 0 1px 3px rgba(16, 36, 62, .08), 0 4px 14px rgba(16, 36, 62, .05);
}
.panel h2 {
  font-size: 13px; margin: 0 0 14px; text-transform: uppercase;
  letter-spacing: .07em; color: #16324f;
  display: flex; align-items: center; gap: 8px;
}
.panel h2::before {
  content: ""; display: inline-block; width: 4px; height: 16px;
  background: #16324f; border-radius: 2px;
}
.panel h3 { font-size: 14px; margin: 0 0 6px; color: #16324f; }

.source-row { display: flex; gap: 20px; flex-wrap: wrap; }
.source-block {
  min-width: 280px; flex: 1; max-width: 480px;
  border: 1px solid #e6e9f0; border-radius: 10px; padding: 16px 18px;
  background: #fafbfd;
}
.date-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.date-row input[type="date"] {
  padding: 7px 10px; border: 1px solid #d4d9e2; border-radius: 8px;
  font-size: 13px; background: #fff; color: #1a1a1a;
}

/* measure toggle: Value | Qty */
.view-toggle-wrap { display: flex; justify-content: center; margin: 18px 0 0; }
.view-toggle {
  display: inline-flex; border: 1px solid #d4d9e2; border-radius: 9px;
  overflow: hidden;
}
.vt-btn {
  padding: 8px 18px; border: none; background: #fff; cursor: pointer;
  font-size: 13px; font-weight: 600; color: #555; transition: all .15s;
}
.vt-btn + .vt-btn { border-left: 1px solid #d4d9e2; }
.vt-btn.active { background: #16324f; color: #fff; }
.vt-btn:hover:not(.active) { background: #eef1f6; }

.filter-row { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.dd-group { display: flex; flex-direction: row; align-items: center; gap: 10px; }
.dd-group .dd-name { min-width: 72px; }
.dd-name {
  font-size: 11px; font-weight: 600; color: #16324f;
  text-transform: uppercase; letter-spacing: .05em;
}
.dd { position: relative; }
.dd-btn {
  min-width: 150px; max-width: 240px; text-align: left;
  padding: 8px 30px 8px 12px; border: 1px solid #d4d9e2; border-radius: 8px;
  background: #fafbfd; font-size: 13px; color: #1a1a1a; cursor: pointer;
  position: relative; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dd-btn::after {
  content: "▾"; position: absolute; right: 10px; top: 50%;
  transform: translateY(-50%); color: #888; font-size: 11px;
}
.dd-btn:hover { border-color: #16324f; }
.dd-btn.active { border-color: #16324f; background: #eaf0f7; font-weight: 600; color: #16324f; }
.dd-menu {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 50;
  min-width: 220px; max-height: 280px; overflow-y: auto;
  background: #fff; border: 1px solid #d4d9e2; border-radius: 10px;
  box-shadow: 0 8px 28px rgba(16, 36, 62, .2); padding: 6px;
}
.dd.open .dd-menu { display: block; }
.dd.open .dd-btn { border-color: #16324f; box-shadow: 0 0 0 3px rgba(22, 50, 79, .12); }
.dd-item {
  display: flex; gap: 8px; align-items: center; padding: 6px 8px;
  font-size: 13px; border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.dd-item:hover { background: #eef1f6; }
.dd-item input { accent-color: #16324f; }
.dd-actions {
  display: flex; gap: 6px; padding: 2px 4px 8px; margin-bottom: 6px;
  border-bottom: 1px solid #eef0f4;
}
.dd-actions button {
  border: none; background: none; color: #16324f; font-size: 12px;
  font-weight: 600; cursor: pointer; padding: 3px 8px; border-radius: 5px;
}
.dd-actions button:hover { background: #eef1f6; }

.search-input {
  min-width: 220px; padding: 8px 12px; border: 1px solid #d4d9e2;
  border-radius: 8px; background: #fafbfd; font-size: 13px; color: #1a1a1a;
}
.search-input:focus { border-color: #16324f; outline: none; box-shadow: 0 0 0 3px rgba(22, 50, 79, .12); background: #fff; }

.btn {
  padding: 8px 16px; border: 1px solid #d4d9e2; border-radius: 8px;
  background: #fff; cursor: pointer; font-size: 13px; font-weight: 600;
  color: #16324f; transition: all .15s;
}
.btn:hover { background: #eef1f6; border-color: #16324f; }
.btn.primary {
  background: #16324f; border-color: #16324f; color: #fff;
  box-shadow: 0 2px 6px rgba(22, 50, 79, .3);
}
.btn.primary:hover { background: #0f2438; }
.btn.small { padding: 5px 12px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.danger { color: #b91c1c; border-color: #f3c8c8; }
.btn.danger:hover { background: #fde8e8; border-color: #b91c1c; }

header .btn { border-color: rgba(255, 255, 255, .4); background: transparent; color: #fff; }
header .btn:hover { background: rgba(255, 255, 255, .12); }

.muted { color: #777; font-size: 13px; }

main { margin: 18px 24px 40px; display: flex; flex-direction: column; gap: 18px; }

.card {
  background: #fff; border: none; border-radius: 12px; padding: 18px 22px;
  box-shadow: 0 1px 3px rgba(16, 36, 62, .08), 0 4px 14px rgba(16, 36, 62, .05);
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-head h3 { margin: 0; font-size: 15px; }

.empty-state { text-align: center; padding: 40px 20px; }
.empty-state h3 { margin: 0 0 8px; color: #16324f; }

/* KPI strip for dead-stock analysis */
.kpi-row { display: flex; gap: 14px; flex-wrap: wrap; }
.kpi {
  flex: 1; min-width: 160px; padding: 14px 18px;
  border: 1px solid #e6e9f0; border-radius: 10px; background: #fafbfd;
}
.kpi.warn { border-color: #f3c8c8; background: #fdf4f4; }
.kpi-label {
  font-size: 11px; font-weight: 600; color: #6b7280;
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px;
}
.kpi-value { font-size: 22px; font-weight: 800; color: #16324f; font-variant-numeric: tabular-nums; }
.kpi.warn .kpi-value { color: #b91c1c; }
.kpi-sub { font-size: 12px; color: #6b7280; margin-top: 4px; }

table.pivot td.desc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }

.table-wrap {
  overflow-x: auto; display: inline-block; background: #fff;
  padding: 20px 26px; border: 1px solid #e2e4e9; border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .06);
}

.scale-inner { display: table; min-width: 100%; }

.img-title {
  text-align: center; font-weight: 800; font-size: 16px;
  letter-spacing: .08em; white-space: nowrap; color: #16324f;
  padding-bottom: 10px; margin-bottom: 2px;
  border-bottom: 3px solid #16324f;
}
.img-sub {
  text-align: center; font-size: 12px; color: #6b7280;
  margin-bottom: 14px;
}

table.pivot {
  border-collapse: collapse; font-size: 13px;
  font-variant-numeric: tabular-nums; width: 100%;
}
table.pivot th, table.pivot td {
  border: none; padding: 7px 14px; white-space: nowrap;
}
table.pivot thead th {
  background: #16324f; color: #fff; font-weight: 600; font-size: 12px;
  letter-spacing: .03em; border-right: 1px solid rgba(255, 255, 255, .18);
}
table.pivot thead th:first-child { border-radius: 6px 0 0 0; }
table.pivot thead th:last-child { border-right: none; border-radius: 0 6px 0 0; }
table.pivot thead th.sub { background: #2c4f74; }
table.pivot thead th.grand { background: #0f2438; }
table.pivot tbody td { border-bottom: 1px solid #e8ebef; }
table.pivot tbody tr:nth-child(even) td { background: #f5f8fb; }
table.pivot td.num { text-align: right; min-width: 44px; }
table.pivot td.rowhead {
  font-weight: 700; color: #16324f; border-right: 2px solid #16324f;
}

/* region group label + region subtotal rows */
table.pivot tbody tr.region-row td {
  background: #eaf0f7; color: #16324f; font-weight: 700; font-size: 12px;
  letter-spacing: .06em; text-transform: uppercase;
  border-top: 2px solid #16324f;
}
table.pivot tbody tr.region-total td {
  font-weight: 700; background: #eef2f8; color: #16324f;
  border-top: 1px solid #d4d9e2; border-bottom: 2px solid #b9c4d4;
}
table.pivot tbody tr.total td {
  font-weight: 700; background: #dbe5f0; color: #16324f;
  border-top: 2px solid #16324f; border-bottom: none;
}
table.pivot tbody tr.total td:first-child { border-radius: 0 0 0 6px; }
table.pivot tbody tr.total td:last-child { border-radius: 0 0 6px 0; }
table.pivot tbody td.grand { font-weight: 700; }
table.pivot tbody tr td.over30 {
  font-weight: 700; background: #fde8e8; color: #b91c1c;
  border-left: 2px solid #f3c8c8;
}
table.pivot tbody tr.total td.over30,
table.pivot tbody tr.region-total td.over30 { background: #f6d6d6; }

/* upload history list */
.scrollbox { max-height: 168px; overflow-y: auto; overflow-x: hidden; }
table.mini { border-collapse: collapse; font-size: 12px; width: 100%; }
table.mini th, table.mini td { padding: 6px 8px; text-align: left; border-bottom: 1px solid #e8ebef; white-space: nowrap; }
table.mini .btn.small { padding: 3px 8px; font-size: 11px; }
table.mini thead th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #16324f;
  position: sticky; top: 0; background: #fff; z-index: 1;
}
table.mini td.actions { text-align: right; }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #16324f; color: #fff; padding: 11px 20px; border-radius: 8px;
  font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none;
  box-shadow: 0 4px 16px rgba(16, 36, 62, .35);
}
#toast.show { opacity: .95; }

footer { padding: 12px 24px 30px; }

.badge {
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
  background: #e8b73c; color: #16324f; border-radius: 4px;
  padding: 3px 9px; vertical-align: middle; margin-left: 8px;
}

/* ---------- mobile ---------- */
@media (max-width: 640px) {
  header { padding: 12px 16px; }
  header h1 { font-size: 15px; }
  .panel { margin: 12px; padding: 14px 16px; }
  main { margin: 12px 12px 30px; gap: 12px; }
  .filter-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .dd-group { width: 100%; }
  .dd-group .dd-name { min-width: 62px; }
  .dd { flex: 1; }
  .dd-btn { width: 100%; min-width: 0; }
  .search-input { flex: 1; min-width: 0; }
  #clearFilters { align-self: flex-end; }
  .card { padding: 12px 14px; }
  .card-head { flex-wrap: wrap; gap: 8px; }
  .table-wrap { display: block; padding: 12px; width: 100%; }
  table.pivot { font-size: 12px; }
  table.pivot th, table.pivot td { padding: 5px 8px; }
  .img-title { font-size: 13px; }
}
