:root {
  --bg: #f5f7f9;
  --ink: #16202a;
  --muted: #66727f;
  --line: #d9e0e7;
  --panel: #ffffff;
  --accent: #176b87;
  --accent-dark: #0f4f63;
  --mint: #2a9d8f;
  --gold: #c98514;
  --red: #b83b4a;
  --excel-blue: #0f6cbd;
  --excel-blue-dark: #084f8f;
  --excel-row: #f4f9ff;
  --excel-row-alt: #eaf4ff;
  --excel-green: #107c41;
  --shadow: 0 14px 34px rgba(20, 35, 50, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #102531;
}

.login-screen.hidden {
  display: none;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  background: white;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.login-panel h1 {
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.app-header {
  min-height: 112px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 32px;
  background: #102531;
  color: white;
}

.eyebrow {
  margin: 0 0 6px;
  color: #9dc7d5;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 760;
}

h2 {
  font-size: 18px;
  font-weight: 740;
}

.header-actions,
.filter-tools,
.segmented {
  display: flex;
  gap: 8px;
  align-items: center;
}

button {
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

.primary-button {
  background: #e6f5f8;
  color: #102531;
  font-weight: 720;
}

.ghost-button {
  background: transparent;
  color: white;
  border-color: rgba(255, 255, 255, 0.28);
}

.danger-button {
  background: #fff0f2;
  border-color: #f0bec5;
  color: var(--red);
  font-weight: 720;
}

.app-shell {
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
}

.filters {
  align-self: start;
  position: sticky;
  top: 16px;
  display: grid;
  gap: 18px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.filters section {
  display: grid;
  gap: 10px;
}

.section-title {
  font-size: 13px;
  font-weight: 780;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.title-row span:last-child {
  color: var(--accent);
  letter-spacing: 0;
  text-transform: none;
}

label {
  display: grid;
  gap: 5px;
  color: #384653;
  font-size: 14px;
  font-weight: 640;
}

input[type="date"],
input[type="search"],
input[type="file"],
input[type="text"],
input[type="password"] {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
  background: white;
}

input[type="file"] {
  padding: 7px 10px;
}

.upload-box span {
  color: #384653;
}

.upload-status {
  min-height: 32px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #f2f7f8;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.upload-status.error {
  background: #fff0f2;
  color: var(--red);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
}

.segmented {
  padding: 3px;
  background: #eef3f5;
  border-radius: 7px;
}

.segmented button {
  flex: 1;
  background: transparent;
  color: #3d4a55;
}

.segmented button.active {
  background: white;
  color: var(--accent-dark);
  box-shadow: 0 1px 5px rgba(16, 37, 49, 0.14);
}

.filter-tools button {
  flex: 1;
  background: #edf5f7;
  color: var(--accent-dark);
  border-color: #c7dfe6;
}

.reset-button {
  padding: 4px 10px;
  font-size: 12px;
  background: #edf5f7;
  color: var(--accent-dark);
  border: 1px solid #c7dfe6;
  border-radius: 6px;
  cursor: pointer;
}

.reset-button:hover {
  background: #dceaef;
}

textarea#pasteData {
  width: 100%;
  min-height: 120px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  resize: vertical;
  background: #fbfdfd;
}

select#pasteServer {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.user-list,
.network-list {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px;
  display: grid;
  gap: 2px;
}

.network-list {
  max-height: none;
}

.user-list label,
.network-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 0 6px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 560;
}

.user-list label:hover,
.network-list label:hover {
  background: #f0f6f7;
}

.content {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
}

.kpi,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi {
  min-height: 104px;
  padding: 18px;
  display: grid;
  align-content: space-between;
}

.kpi span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.kpi strong {
  font-size: 28px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel-header p,
.badge {
  color: var(--muted);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef4f5;
  white-space: nowrap;
}

.chart-panel canvas {
  width: 100%;
  min-height: 260px;
  border-radius: 6px;
  background: #fbfcfd;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(230px, 0.55fr) minmax(230px, 0.55fr);
  gap: 20px;
}

.table-wrap {
  overflow: auto;
  max-height: 520px;
  border: 1px solid var(--line);
  border-radius: 7px;
  scrollbar-color: var(--excel-blue) #e7eef5;
  scrollbar-width: thin;
}

.table-wrap::-webkit-scrollbar,
.user-list::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

.table-wrap::-webkit-scrollbar-track,
.user-list::-webkit-scrollbar-track {
  background: #e7eef5;
  border-radius: 999px;
}

.table-wrap::-webkit-scrollbar-thumb,
.user-list::-webkit-scrollbar-thumb {
  background: var(--excel-blue);
  border: 3px solid #e7eef5;
  border-radius: 999px;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 1080px;
  background: white;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid #d5e6f7;
  border-right: 1px solid #d5e6f7;
  text-align: left;
  font-size: 13px;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, var(--excel-blue), var(--excel-blue-dark));
  color: white;
  font-weight: 780;
  z-index: 1;
  border-bottom: 1px solid #083f74;
  border-right: 1px solid rgba(255, 255, 255, 0.22);
}

th:first-child {
  border-top-left-radius: 6px;
}

th:last-child {
  border-top-right-radius: 6px;
}

.print-table-title {
  display: none;
}

tbody tr:nth-child(odd) {
  background: var(--excel-row);
}

tbody tr:nth-child(even) {
  background: var(--excel-row-alt);
}

.sort-button {
  width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: inherit;
  text-align: left;
  white-space: nowrap;
}

.sort-button::after {
  content: "";
  display: inline-block;
  width: 12px;
  margin-left: 5px;
  color: #cfeaff;
}

.sort-button.active.asc::after {
  content: "^";
}

.sort-button.active.desc::after {
  content: "v";
}

tbody tr:hover {
  background: #d8edff;
}

.detail-table {
  max-height: 620px;
}

.server-mix {
  display: grid;
  gap: 14px;
}

.mix-row {
  display: grid;
  gap: 7px;
}

.mix-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 720;
}

.bar {
  height: 12px;
  background: #eef3f5;
  border-radius: 999px;
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.status-active {
  color: var(--mint);
  font-weight: 720;
}

.status-completed {
  color: #56616b;
  font-weight: 650;
}

.empty {
  color: var(--muted);
  padding: 16px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .filters {
    position: static;
  }

  .kpi-grid,
  .split {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 660px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 22px 18px;
  }

  .app-shell {
    padding: 14px;
  }

  .kpi-grid,
  .split {
    grid-template-columns: 1fr;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions button {
    flex: 1;
  }
}

@media print {
  @page {
    size: landscape;
    margin: 0.35in;
  }

  body {
    background: white;
  }

  .filters,
  .header-actions,
  .login-screen {
    display: none;
  }

  .app-header {
    color: #102531;
    background: white;
    border-bottom: 1px solid var(--line);
  }

  .app-shell {
    display: block;
    padding: 0;
  }

  .content {
    display: block;
    padding: 0;
  }

  .panel,
  .kpi {
    box-shadow: none;
    border: 0;
    padding: 10px 0;
  }

  .panel {
    break-inside: auto;
  }

  .report-table-panel {
    break-before: page;
    page-break-before: always;
  }

  .kpi {
    break-inside: avoid;
  }

  .panel-header {
    break-after: avoid;
    page-break-after: avoid;
  }

  .kpi-grid,
  .split {
    display: block;
  }

  .split {
    display: flex;
    flex-direction: column;
  }

  .server-mix-panel {
    order: 1;
  }

  .network-mix-panel {
    order: 2;
  }

  .user-summary-panel {
    order: 3;
  }

  .table-wrap,
  .detail-table {
    overflow: visible;
    max-height: none;
    border: 0;
    scrollbar-width: none;
  }

  .table-wrap::-webkit-scrollbar,
  .detail-table::-webkit-scrollbar {
    display: none;
  }

  table {
    min-width: 0;
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
    page-break-inside: auto;
    break-inside: auto;
  }

  /* Critical: browsers only repeat thead across page breaks when the thead
     is in its own table-header-group AND nothing above it establishes a
     new block formatting context (overflow, contain, etc.). */
  thead {
    display: table-header-group !important;
    break-inside: avoid;
    page-break-inside: avoid;
    break-after: avoid;
    page-break-after: avoid;
  }

  thead tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .print-table-title {
    display: table-row;
  }

  .print-table-title th {
    background: white !important;
    color: #102531 !important;
    border: 0;
    padding: 0 0 10px;
    font-size: 15px;
    text-align: left;
  }

  tbody {
    display: table-row-group;
  }

  tr {
    page-break-inside: avoid;
    break-inside: avoid;
    page-break-after: auto;
  }

  th {
    position: static !important;
    top: auto !important;
    background: var(--excel-blue-dark) !important;
    color: white !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  th,
  td {
    white-space: normal;
    padding: 5px 6px;
    font-size: 9px;
    border: 1px solid #9ebfe0;
  }

  .sort-button {
    font-size: 9px;
  }

  tbody tr:nth-child(odd) {
    background: #f4f9ff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  tbody tr:nth-child(even) {
    background: #eaf4ff !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
