:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #dbe3ef;
  --text: #172033;
  --muted: #68738a;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b91c1c;
  --soft-blue: #eaf1ff;
  --soft-green: #eaf7ef;
  --soft-red: #fdecec;
  --soft-yellow: #fff6dd;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
}

.inline-check input {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 18px;
}

.hidden {
  display: none !important;
}

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

.eyebrow {
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.error {
  min-height: 20px;
  color: var(--danger);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(460px, 100%);
  display: grid;
  gap: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(23, 32, 51, 0.08);
}

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

.primary,
.secondary,
.ghost,
.danger {
  min-height: 36px;
  border-radius: 6px;
  padding: 8px 12px;
  white-space: nowrap;
}

.primary {
  background: var(--primary);
  color: #fff;
}

.primary:hover {
  background: var(--primary-dark);
}

.secondary {
  background: #eef2f7;
  color: var(--text);
}

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.danger {
  background: var(--soft-red);
  color: var(--danger);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 28px;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: #fff;
}

.tabs {
  display: grid;
  gap: 8px;
  align-content: start;
}

.tabs button {
  min-height: 40px;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  color: var(--muted);
}

.tabs button.active {
  background: var(--soft-blue);
  color: var(--primary);
  font-weight: 700;
}

.workspace {
  display: grid;
  gap: 18px;
  align-content: start;
  padding: 24px;
}

.topbar,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.top-actions,
.form-actions,
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.filters input {
  max-width: 360px;
}

.notice {
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  background: #fff;
  border-radius: 6px;
  padding: 12px 14px;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.compact-stats {
  margin-bottom: 0;
}

.stat {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 16px;
}

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

.section-band {
  display: grid;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.split {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(420px, 1.4fr);
  gap: 16px;
}

.vertical-stack {
  display: grid;
  gap: 16px;
}

.compact-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
}

.wide {
  grid-column: 1 / -1;
}

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

.item {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

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

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

.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding-top: 4px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
}

.modal-panel {
  position: relative;
  width: min(760px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  display: grid;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.24);
}

.modal-panel-wide {
  width: min(920px, 100%);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 700;
}

.badge.wait {
  background: #eef2f7;
  color: #475569;
}

.badge.running {
  background: var(--soft-blue);
  color: var(--primary);
}

.badge.issue {
  background: var(--soft-red);
  color: var(--danger);
}

.badge.done {
  background: var(--soft-green);
  color: var(--success);
}

.settings {
  display: grid;
  gap: 8px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.result {
  min-height: 120px;
  overflow: auto;
  background: #0f172a;
  color: #dbeafe;
  border-radius: 8px;
  padding: 12px;
  white-space: pre-wrap;
}

.amount-positive {
  color: var(--success);
  font-weight: 700;
}

.amount-negative {
  color: var(--danger);
  font-weight: 700;
}

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

  .sidebar {
    position: sticky;
    z-index: 10;
    top: 0;
    height: auto;
    grid-template-columns: minmax(110px, auto) 1fr auto;
    grid-template-rows: auto;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar h2 {
    font-size: 16px;
  }

  .tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .tabs::-webkit-scrollbar {
    display: none;
  }

  .tabs button {
    flex: 0 0 auto;
    min-width: 58px;
    min-height: 36px;
    padding: 8px 12px;
    text-align: center;
  }

  #logoutBtn {
    min-height: 36px;
    padding: 8px 10px;
  }

  .topbar,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .workspace {
    gap: 12px;
    padding: 12px;
  }

  .topbar h1 {
    font-size: 22px;
  }

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

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
  }

  .stat {
    min-width: 0;
    padding: 12px;
  }

  .stat strong {
    overflow-wrap: anywhere;
    font-size: 22px;
  }

  .section-band {
    gap: 12px;
    padding: 12px;
  }

  .compact-form {
    grid-template-columns: 1fr;
  }

  .filters,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .filters input {
    max-width: none;
  }

  .primary,
  .secondary,
  .ghost,
  .danger {
    min-height: 40px;
  }

  .item-row,
  .setting-row {
    align-items: stretch;
    flex-direction: column;
  }

  .item-actions {
    gap: 6px;
  }

  .item-actions button {
    flex: 1 1 auto;
  }

  .pager {
    flex-wrap: wrap;
  }

  .modal {
    align-items: end;
    padding: 0;
  }

  .modal-panel {
    width: 100%;
    max-height: min(86vh, calc(100vh - 40px));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 8px 8px 0 0;
    padding: 14px;
  }

  table {
    min-width: 680px;
  }

  th,
  td {
    padding: 8px;
  }
}

@media (max-width: 560px) {
  .login-shell {
    padding: 14px;
  }

  .login-panel {
    padding: 20px;
  }

  .sidebar {
    grid-template-columns: 1fr auto;
  }

  .sidebar .tabs {
    grid-column: 1 / -1;
    order: 3;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .section-head h2 {
    font-size: 17px;
  }

  .topbar .muted {
    font-size: 13px;
  }

  .modal-panel {
    max-height: 92vh;
  }

  .form-grid {
    gap: 10px;
  }

  .result {
    font-size: 12px;
  }
}
