:root {
  --bg: #f3f7f4;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #5e6a7f;
  --line: #d7e0de;
  --green: #1f8f4e;
  --blue: #0b5cb8;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Manrope", "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 600px at -20% -20%, rgba(31, 143, 78, 0.14), transparent 55%),
    radial-gradient(900px 450px at 110% -10%, rgba(11, 92, 184, 0.14), transparent 50%),
    var(--bg);
}

.material-symbols-rounded {
  font-variation-settings: "FILL" 0, "wght" 520, "GRAD" 0, "opsz" 24;
}

.layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
  transition: grid-template-columns 0.22s ease;
}

.layout.logged-out {
  grid-template-columns: 1fr;
}

.layout.logged-out .sidebar {
  display: none;
}

.layout.logged-out .main {
  max-width: 1160px;
  width: 100%;
  margin: 0 auto;
}

.layout.collapsed {
  grid-template-columns: 84px 1fr;
}

.sidebar {
  background: linear-gradient(190deg, #10326f 0%, #0f4f8e 40%, #217f4a 100%);
  color: #eef8ff;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-right: 1px solid rgba(255, 255, 255, 0.16);
  transition: transform 0.24s ease;
  z-index: 30;
}

.sidebar-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.12rem;
}

.brand p {
  margin: 0;
  opacity: 0.88;
  font-size: 0.85rem;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.18);
  font-weight: 800;
  flex-shrink: 0;
}

.layout.collapsed .brand-copy,
.layout.collapsed .user-meta,
.layout.collapsed .nav-label {
  display: none;
}

.layout.collapsed .sidebar {
  padding-inline: 10px;
}

.layout.collapsed .nav-item,
.layout.collapsed .nav-logout {
  justify-content: center;
}

.layout.collapsed .sidebar-header {
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

.layout.collapsed .sidebar-control {
  position: static;
}

.user-meta {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.4;
  color: rgba(241, 249, 255, 0.86);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item {
  width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: #f5f9ff;
  background: rgba(255, 255, 255, 0.08);
  font-weight: 650;
  cursor: pointer;
  transition: 0.18s ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.17);
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.28);
  border-color: rgba(255, 255, 255, 0.35);
}

.nav-item.hidden {
  display: none;
}

.nav-icon {
  font-size: 20px;
  line-height: 1;
}

.nav-label {
  white-space: nowrap;
}

.main {
  padding: clamp(10px, 1.5vw, 18px);
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.topbar h2 {
  margin: 4px 0 0;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  margin-left: auto;
  display: inline-flex;
  gap: 8px;
}

.kicker {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.panel,
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.06);
  min-width: 0;
}

.card h3,
.card h4,
.card h5,
.card h6 {
  margin: 0;
}

.panel + .panel {
  margin-top: 12px;
}

.auth-wrap {
  min-height: calc(100vh - 36px);
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 14px;
}

.auth-hero {
  padding: 28px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(9, 66, 155, 0.97), rgba(17, 142, 80, 0.94));
  color: #f2fbff;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.auth-hero h2 {
  margin: 0 0 10px;
  font-size: clamp(1.3rem, 2vw, 1.9rem);
}

.auth-hero p {
  margin: 0;
  max-width: 44ch;
  line-height: 1.55;
}

.auth-card h3 {
  margin: 0 0 6px;
}

.auth-card form {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 9px 10px;
  font: inherit;
}

textarea {
  min-height: 100px;
  resize: vertical;
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 9px 13px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.12s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.btn,
.btn:link,
.btn:visited,
.btn:hover,
.btn:active {
  text-decoration: none !important;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
}

.btn.primary {
  color: #fff;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.btn.ghost {
  color: inherit;
  border-color: var(--line);
  background: #fff;
}

.btn-compact {
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 700;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.58;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.sidebar .btn.ghost {
  margin-top: auto;
  background: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.42);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.sidebar-control {
  border-color: rgba(255, 255, 255, 0.38);
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.menu-toggle {
  display: none;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr));
  gap: 10px;
}

.kpi {
  background: linear-gradient(180deg, #f7fcf9, #f5f8ff);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  min-width: 0;
}

.kpi .label {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.86rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.kpi .value {
  margin-top: 5px;
  font-size: 1.35rem;
  font-weight: 800;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr));
  gap: 10px;
  margin-top: 10px;
}

.content-tab-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.content-tabs {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
}

.content-tab-btn.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.file-tab-btn.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.content-tab-panel {
  margin-top: 2px;
}

.report-tab-panel,
.monitor-tab-panel,
.file-tab-panel {
  min-width: 0;
}

.report-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar > div,
.content-tab-header h3,
.report-header-row h3,
.actions h3,
.actions h4 {
  min-width: 0;
}

.report-period-tabs {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
}

.monitor-period-scroll,
.monitor-tabs-scroll {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.monitor-period-scroll .btn,
.monitor-tabs-scroll .btn {
  flex: 0 0 auto;
}

.report-period-btn.active,
.report-tab-btn.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.monitor-period-btn.active,
.monitor-tab-btn.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.splash-upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
  gap: 10px;
}

.upload-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fcfffd;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.upload-card h6,
.upload-card h5,
.upload-card h4 {
  margin: 0;
}

.dropzone {
  border: 1.5px dashed rgba(11, 92, 184, 0.35);
  border-radius: 10px;
  background: linear-gradient(180deg, #f6faff, #f8fcfa);
  padding: 12px;
  text-align: center;
  color: #39506f;
  font-size: 0.85rem;
  font-weight: 600;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.dropzone.dragover {
  border-color: var(--green);
  background: #eef9f2;
}

.dropzone.disabled {
  opacity: 0.65;
  pointer-events: none;
}

.batch-cards {
  display: grid;
  gap: 8px;
}

.batch-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fcfffd;
}

.batch-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.batch-meta {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.batch-meta .meta-label {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

.batch-meta .meta-value {
  font-size: 0.9rem;
  font-weight: 600;
  word-break: break-word;
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.health-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fbfefd;
}

.health-item .label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.health-item .value {
  margin-top: 3px;
  font-size: 1.08rem;
  font-weight: 800;
  word-break: break-word;
}

.table-wrap {
  display: block;
  overflow-x: auto;
  overflow-y: hidden;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: clamp(560px, 90vw, 760px);
  background: #fff;
}

.table-customer-directory {
  min-width: 980px;
}

.table-report {
  min-width: 860px;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 0.92rem;
  word-break: break-word;
}

th {
  position: sticky;
  top: 0;
  background: #f8fbfb;
  z-index: 1;
  color: #304258;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.76rem;
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-pill.ok {
  color: #176738;
  background: rgba(31, 143, 78, 0.12);
  border-color: rgba(31, 143, 78, 0.32);
}

.status-pill.warn {
  color: #8a5200;
  background: rgba(185, 111, 0, 0.14);
  border-color: rgba(185, 111, 0, 0.36);
}

.status-pill.bad {
  color: #9d1f17;
  background: rgba(180, 35, 24, 0.14);
  border-color: rgba(180, 35, 24, 0.34);
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  margin-bottom: 10px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.monitor-export-row {
  justify-content: flex-end;
}

.monitor-export-btn .material-symbols-rounded {
  font-size: 18px;
}

.simulate-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.simulate-inline input {
  width: 112px;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--muted);
}

.checkbox-inline input {
  width: auto;
}

.stack {
  display: grid;
  gap: 10px;
}

.stack > * {
  min-width: 0;
}

.muted {
  color: var(--muted);
}

.tiny {
  font-size: 0.8rem;
}

a {
  color: var(--green);
  font-weight: 700;
  text-decoration: none;
}

a:hover {
  text-decoration: none;
}

.plain-link {
  color: var(--green);
  font-weight: 700;
  text-decoration: none;
}

.notice {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fcfffd;
}

.sidebar-backdrop,
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 8, 23, 0.42);
  z-index: 20;
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.modal {
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  border-radius: 16px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
  pointer-events: auto;
}

.modal-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
}

.modal-body {
  padding: 14px;
}

.hidden {
  display: none !important;
}

.error {
  color: var(--danger);
}

.table-tips {
  min-width: 980px;
  table-layout: fixed;
}

.table-tips th:nth-child(1),
.table-tips td:nth-child(1) {
  width: 96px;
}

.table-tips th:nth-child(2),
.table-tips td:nth-child(2) {
  width: 180px;
}

.table-tips th:nth-child(3),
.table-tips td:nth-child(3) {
  width: 340px;
}

.table-tips th:nth-child(4),
.table-tips td:nth-child(4) {
  width: 128px;
}

.table-tips th:nth-child(5),
.table-tips td:nth-child(5) {
  width: 76px;
}

.table-tips th:nth-child(6),
.table-tips td:nth-child(6) {
  width: 90px;
}

.table-tips th:nth-child(7),
.table-tips td:nth-child(7) {
  width: 72px;
  text-align: center;
}

.truncate-text {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: top;
}

.truncate-text.wide {
  max-width: 320px;
}

@media (max-width: 1150px) {
  .topbar {
    align-items: flex-start;
  }
  .topbar-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }
}

@media (max-width: 980px) {
  .layout,
  .layout.collapsed {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(84vw, 320px);
    height: 100vh;
    border-radius: 0 14px 14px 0;
    transform: translateX(-105%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .menu-toggle {
    display: inline-flex;
  }
  .auth-wrap {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: center;
    flex-wrap: nowrap;
  }
  .topbar > div {
    flex: 1 1 auto;
    min-width: 0;
  }
  .topbar-actions {
    width: auto;
    margin-left: auto;
    justify-content: flex-end;
    flex-wrap: nowrap;
    flex-shrink: 0;
  }
  .main {
    padding: 12px;
  }
  .panel,
  .card {
    padding: 12px;
  }
  .toolbar {
    grid-template-columns: 1fr;
  }
  table {
    min-width: 520px;
  }
  .two-col {
    grid-template-columns: 1fr;
  }
  .content-tabs {
    width: 100%;
  }
  .report-period-tabs {
    width: 100%;
  }
  .report-period-btn {
    flex: 1;
    justify-content: center;
  }
  .content-tab-btn {
    flex: 1;
    justify-content: center;
  }
  .topbar-actions .btn span:not(.material-symbols-rounded) {
    display: none;
  }
  #panel-title {
    font-size: clamp(1rem, 3.9vw, 1.2rem);
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .kicker {
    font-size: 0.72rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .panel h3,
  .panel h4,
  .card h3,
  .card h4,
  .card h5 {
    font-size: clamp(0.98rem, 4.1vw, 1.12rem);
    line-height: 1.2;
  }
  .panel h3,
  .panel h4,
  .card h3,
  .card h4,
  .card h5 {
    overflow-wrap: normal;
    word-break: normal;
  }
  .health-grid,
  .batch-meta {
    grid-template-columns: 1fr;
  }
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .report-header-row {
    align-items: flex-start;
  }
  .table-customer-directory {
    min-width: 900px;
  }
  .table-tips {
    min-width: 900px;
  }
  .table-report {
    min-width: 760px;
  }
  th,
  td {
    font-size: 0.84rem;
    padding: 8px 10px;
  }
  .status-pill {
    font-size: 0.68rem;
    padding: 3px 7px;
  }
  .kpi .value {
    font-size: 1.08rem;
  }
  .monitor-export-row {
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }
  .monitor-export-row .btn {
    flex: 0 0 auto;
  }
}
