:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --border: #e5eaf2;
  --text: #172033;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warning: #b45309;
  --warning-soft: #fff7ed;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
}

.brand h1 span {
  color: var(--accent);
}

.brand-subtitle {
  color: var(--muted);
  font-size: 0.84rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-balance-card {
  min-width: 180px;
  width: fit-content;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 10px;
}

.header-balance-value {
  margin-top: 4px;
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.22);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.08);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.page {
  flex: 1 1 auto;
  min-height: 0;
  padding: 24px 28px 28px;
}

.page-scroll {
  overflow: auto;
}

.page-grid {
  display: grid;
  gap: 20px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.card-hd h2,
.card-hd h3 {
  margin: 0;
  font-size: 0.98rem;
}

.card-bd {
  padding: 18px 20px;
}

.muted {
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
}

.pill.success {
  background: var(--success-soft);
  color: var(--success);
}

.pill.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.pill.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.pill.subtle {
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.68rem;
  padding: 4px 8px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

.field textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.6;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent);
}

.empty-state {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
  line-height: 1.8;
}

.drawer-mask,
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 90;
}

.drawer-mask.show,
.modal-mask.show {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(520px, calc(100vw - 20px));
  height: 100vh;
  background: var(--card);
  box-shadow: -10px 0 30px rgba(15, 23, 42, 0.18);
  transform: translateX(100%);
  transition: transform 0.22s ease;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.drawer.show {
  transform: translateX(0);
}

.drawer-hd,
.modal-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.drawer-hd h3,
.modal-hd h3 {
  margin: 0;
  font-size: 1rem;
}

.drawer-bd,
.modal-bd {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 18px 20px;
}

.drawer-ft,
.modal-ft {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 100;
}

.modal-content {
  width: min(820px, calc(100vw - 24px));
  max-height: min(88vh, 920px);
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  transform: translateY(24px);
  opacity: 0;
  transition: transform 0.18s ease, opacity 0.18s ease;
  display: flex;
  flex-direction: column;
}

.modal.show {
  pointer-events: auto;
}

.modal.show .modal-content {
  transform: translateY(0);
  opacity: 1;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 120;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(23, 32, 51, 0.95);
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease, background 0.2s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.toast-danger {
  background: var(--danger);
}

.toast.toast-warning {
  background: var(--warning);
}

@media (max-width: 900px) {
  .page {
    padding: 16px 14px 20px;
  }

  .app-header {
    padding: 16px 14px;
    align-items: flex-start;
    flex-direction: column;
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }
}
