:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #eef2f3;
  --text: #172026;
  --muted: #64727d;
  --line: #d9e0e4;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --blue: #2563eb;
  --orange: #d97706;
  --red: #dc2626;
  --green: #15803d;
  --shadow: 0 10px 30px rgba(17, 24, 39, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-width: 320px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.login-page {
  min-height: 100dvh;
  display: grid;
  align-items: center;
  padding: 24px;
}

.login-panel {
  width: min(100%, 420px);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.avatar {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: cover;
  background: #e8f3f1;
  color: var(--brand-dark);
  border: 1px solid var(--line);
  font-weight: 900;
}

.topbar-avatar {
  width: 36px;
  height: 36px;
  margin-left: auto;
}

.profile-avatar {
  width: 64px;
  height: 64px;
}

.brand-row h1 {
  font-size: 22px;
  line-height: 1.2;
  margin: 0;
}

.brand-row p,
.mini-copy {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.field label {
  color: #34424d;
  font-size: 14px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

.field textarea {
  min-height: 88px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.primary-button,
.secondary-button,
.danger-button,
.plain-button {
  min-height: 40px;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0;
}

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

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

.secondary-button {
  background: #e8f3f1;
  color: var(--brand-dark);
}

.danger-button {
  background: #fee2e2;
  color: #991b1b;
}

.plain-button {
  background: var(--surface-2);
  color: #26343d;
}

.user-link {
  display: inline;
  min-height: 0;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--brand-dark);
  cursor: pointer;
  font-weight: 900;
  line-height: inherit;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.user-link:hover {
  color: var(--brand);
}

.button-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.quick-logins {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(245, 247, 248, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 16px;
}

.topbar-title {
  min-width: 0;
}

.topbar-title h1 {
  font-size: 20px;
  margin: 0;
  line-height: 1.2;
}

.topbar-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.role-pill {
  flex: 0 0 auto;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 12px;
  background: #fff;
  border: 1px solid var(--line);
  color: #34424d;
  font-size: 13px;
  font-weight: 800;
}

.profile-card,
.account-row,
.member-profile-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
}

.profile-card strong,
.account-row strong,
.member-profile-card strong {
  display: block;
  font-size: 16px;
}

.profile-card span,
.account-row span,
.member-profile-card span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.member-profile-card {
  margin-bottom: 12px;
}

.layout {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: 16px 16px 92px;
}

.desktop-nav {
  display: none;
}

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

.mobile-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.nav-button {
  min-height: 48px;
  border-radius: 8px;
  background: transparent;
  color: #53626d;
  cursor: pointer;
  display: grid;
  place-items: center;
  gap: 2px;
  font-size: 12px;
  font-weight: 800;
}

.nav-button span:first-child {
  font-size: 18px;
  line-height: 1;
}

.nav-button.active {
  background: #e8f3f1;
  color: var(--brand-dark);
}

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

.metric,
.panel,
.record-row,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(17, 24, 39, 0.05);
}

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

.metric small {
  color: var(--muted);
  font-weight: 800;
}

.metric strong {
  font-size: clamp(22px, 7vw, 30px);
  line-height: 1.1;
}

.metric.income strong {
  color: var(--green);
}

.metric.performance strong,
.metric.commission strong {
  color: var(--blue);
}

.metric.payout strong {
  color: var(--orange);
}

.metric.expense strong {
  color: var(--red);
}

.metric.pending strong {
  color: var(--orange);
}

.metric.count strong {
  color: var(--blue);
}

.panel {
  padding: 14px;
}

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

.dashboard-hero h2 {
  margin: 4px 0 0;
  font-size: 20px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-header h2 {
  font-size: 16px;
  line-height: 1.2;
  margin: 0;
}

.panel-header select {
  width: auto;
  max-width: 170px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 7px 10px;
}

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

.record-row {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.record-main {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
}

.record-title {
  min-width: 0;
}

.record-title strong {
  display: block;
  font-size: 16px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.record-title span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.amount {
  font-weight: 900;
  white-space: nowrap;
}

.amount.income {
  color: var(--green);
}

.amount.performance,
.amount.commission {
  color: var(--blue);
}

.amount.expense,
.amount.reimbursement,
.amount.payout {
  color: var(--red);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--surface-2);
  color: #43515b;
  font-size: 12px;
  font-weight: 800;
}

.tag.approved,
.tag.paid {
  background: #dcfce7;
  color: #166534;
}

.tag.submitted {
  background: #ffedd5;
  color: #9a3412;
}

.tag.rejected {
  background: #fee2e2;
  color: #991b1b;
}

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

.form-grid {
  display: grid;
  gap: 12px;
}

.sub-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  padding: 12px;
}

.formula-preview {
  display: grid;
  gap: 6px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  padding: 12px;
  color: #1e3a8a;
}

.formula-preview span,
.formula-preview em {
  font-size: 13px;
  font-style: normal;
}

.preview-schedule {
  display: grid;
  gap: 4px;
  margin-top: 4px;
}

.hidden {
  display: none !important;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.empty-state {
  min-height: 150px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
}

.grant-row,
.audit-row,
.profile-line,
.account-row {
  display: grid;
  gap: 6px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.profile-button {
  width: 100%;
  text-align: left;
  background: transparent;
  cursor: pointer;
}

.profile-button:hover {
  color: var(--brand-dark);
}

.grant-row:last-child,
.audit-row:last-child,
.profile-line:last-child,
.account-row:last-child {
  border-bottom: 0;
}

.grant-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.audit-row time,
.profile-line span {
  color: var(--muted);
  font-size: 13px;
}

.stat-table,
.schedule-table,
.detail-grid,
.member-grid,
.dashboard-strip,
.performance-grid,
.access-grid,
.payout-table {
  display: grid;
  gap: 8px;
}

.dashboard-strip {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dashboard-cell {
  min-height: 76px;
  display: grid;
  align-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

.dashboard-cell span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.dashboard-cell strong {
  font-size: 18px;
  overflow-wrap: anywhere;
}

.stat-row,
.schedule-row,
.detail-line {
  min-height: 42px;
  display: grid;
  grid-template-columns: minmax(90px, 1fr) auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.stat-row:last-child,
.schedule-row:last-child,
.detail-line:last-child {
  border-bottom: 0;
}

.stat-row span,
.schedule-row span,
.detail-line span {
  color: var(--muted);
  font-size: 13px;
}

.stat-row strong,
.schedule-row strong,
.detail-line strong {
  text-align: right;
  overflow-wrap: anywhere;
}

.stat-table {
  overflow-x: auto;
}

.stat-row.wide {
  min-width: 760px;
  grid-template-columns: 1.4fr 100px repeat(5, minmax(92px, 1fr));
}

.stat-row.wide span {
  overflow-wrap: anywhere;
}

.schedule-row {
  grid-template-columns: 72px 1fr 72px auto 72px;
}

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

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

.performance-lines {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.member-card {
  width: 100%;
  display: grid;
  gap: 8px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  cursor: pointer;
}

.member-card:hover {
  border-color: #a7d9d3;
}

.member-card > strong {
  font-size: 16px;
}

.member-card > span,
.member-numbers {
  color: var(--muted);
  font-size: 13px;
}

.member-numbers {
  display: grid;
  gap: 4px;
}

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

.access-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
}

.access-head strong,
.access-head span {
  display: block;
}

.access-head span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.access-head select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 7px 10px;
}

.access-columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.access-columns > div {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: start;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.access-columns em {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
}

.grant-chip {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: #34424d;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
}

.grant-chip > button[data-delete-grant] {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  color: #991b1b;
  cursor: pointer;
  font-weight: 900;
}

.payout-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.payout-row.overdue {
  border-color: #fdba74;
  background: #fff7ed;
}

.payout-row strong,
.payout-row span {
  display: block;
}

.payout-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.payout-amount {
  text-align: left;
}

.payout-amount strong {
  color: var(--orange);
  font-size: 18px;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
}

.progress-track span {
  height: 100%;
  margin: 0;
  border-radius: inherit;
  background: var(--brand);
}

.password-reset {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
}

.password-reset input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  align-items: end;
  background: rgba(15, 23, 42, 0.42);
  padding: 20px 10px 0;
}

.modal {
  width: min(100%, 760px);
  max-height: calc(100dvh - 40px);
  margin: 0 auto;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px 8px 0 0;
  padding: 14px;
  box-shadow: var(--shadow);
}

.detail-section {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

.plain-link,
.attachment-file {
  color: var(--brand-dark);
  font-weight: 800;
  text-decoration: none;
}

.attachment-preview {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.attachment-file {
  display: block;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-2);
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  z-index: 50;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  background: #172026;
  color: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 720px) {
  .layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 20px;
    padding-bottom: 28px;
  }

  .desktop-nav {
    display: grid;
    align-content: start;
    gap: 8px;
    position: sticky;
    top: 84px;
  }

  .desktop-nav .nav-button {
    grid-template-columns: 24px 1fr;
    justify-items: start;
    padding: 0 12px;
    background: #fff;
    border: 1px solid var(--line);
  }

  .desktop-nav .nav-button.active {
    border-color: #a7d9d3;
  }

  .mobile-nav {
    display: none;
  }

  .metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .two-col {
    grid-template-columns: 1fr 1fr;
  }

  .member-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .performance-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .access-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .payout-row {
    grid-template-columns: 1fr 150px;
    align-items: center;
  }

  .payout-row .progress-track,
  .payout-row .record-actions {
    grid-column: 1 / -1;
  }

  .payout-amount {
    text-align: right;
  }

  .modal-backdrop {
    align-items: center;
    padding: 24px;
  }

  .modal {
    border-radius: 8px;
  }

  .content {
    gap: 16px;
  }
}

@media (max-width: 380px) {
  .topbar-inner {
    padding-inline: 12px;
  }

  .role-pill {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .metric {
    padding: 12px;
  }
}
