/* ============================================================
   Yingming Ledger - blue light theme
   ============================================================ */

:root {
  --bg: #e9f0fc;
  --surface: #ffffff;
  --surface-2: #f3f8ff;
  --surface-3: #dce9ff;
  --line: #d3e2fb;
  --line-2: #aec7ef;
  --ink: #16264a;
  --ink-2: #51658a;
  --ink-3: #8799bd;
  --blue: #3b82f6;
  --blue-light: #60a5fa;
  --blue-strong: #2563eb;
  --blue-deep: #1d4ed8;
  --blue-soft: rgba(59, 130, 246, 0.12);
  --blue-faint: rgba(59, 130, 246, 0.06);
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.12);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.12);
  --amber: #e8930c;
  --amber-soft: rgba(232, 147, 12, 0.14);
  --shadow: 0 8px 24px rgba(29, 78, 216, 0.10);
  --shadow-lg: 0 20px 50px rgba(29, 78, 216, 0.22);
  --grad: linear-gradient(135deg, #60a5fa, #3b82f6 60%, #2563eb);
  --grad-soft: linear-gradient(135deg, #dce9ff, #eef5ff);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(1000px 520px at 88% -12%, rgba(96, 165, 250, 0.35), transparent 62%),
    radial-gradient(860px 480px at -12% 112%, rgba(59, 130, 246, 0.28), transparent 58%),
    var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

/* ---------------- topbar ---------------- */

.topbar {
  flex: none;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: linear-gradient(90deg, #1d4ed8, #3b82f6 55%, #60a5fa);
  box-shadow: 0 4px 18px rgba(29, 78, 216, 0.35);
}

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

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  object-fit: cover;
  background: #ffffff;
  padding: 3px;
  box-shadow: 0 2px 8px rgba(13, 48, 132, 0.35);
}

.brand-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #ffffff;
  text-shadow: 0 1px 4px rgba(13, 48, 132, 0.35);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.user-name {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.92);
  font-weight: 500;
}

.sync-state {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.88);
}

.sync-state .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6ee7b7;
  box-shadow: 0 0 6px rgba(110, 231, 183, 0.8);
}

.sync-state.syncing .dot {
  background: #ffffff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.9);
  animation: pulse 0.9s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--surface-3);
  color: var(--blue-strong);
}

.icon-btn-outline {
  border: 1px solid var(--line-2);
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* topbar logout button on gradient */
.topbar .icon-btn {
  color: rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.14);
  border-radius: 10px;
}

.topbar .icon-btn:hover {
  background: rgba(255, 255, 255, 0.28);
  color: #ffffff;
}

/* ---------------- page shell ---------------- */

.page {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  height: calc(100vh - 58px);
  padding: 16px 16px 20px;
  display: flex;
  flex-direction: column;
}

/* ---------------- stats ---------------- */

.stats {
  flex: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--grad);
}

.card-label {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 10px;
  border-radius: 11px;
  background: var(--blue-faint);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--blue-strong);
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.card-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.card-note {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 8px;
}

.value-accent {
  color: var(--blue-strong);
}

.value-amber {
  color: var(--amber);
}

.card-balance .card-value {
  font-size: 32px;
  letter-spacing: 0.5px;
}

.card-loan {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(135deg, #ffffff, #f0f6ff);
}

.card-loan::before {
  background: linear-gradient(90deg, #e8930c, #f6b84c);
}

.card-loan .card-label {
  margin: 0;
  background: var(--amber-soft);
  border-color: rgba(232, 147, 12, 0.25);
  color: var(--amber);
}

.card-loan .card-value {
  font-size: 24px;
}

.card-loan .card-note {
  margin: 0;
  flex: 1;
  text-align: right;
  margin-left: 12px;
}

.save-bar {
  height: 10px;
  border-radius: 6px;
  background: var(--surface-3);
  overflow: hidden;
  margin-top: 12px;
  box-shadow: inset 0 1px 2px rgba(29, 78, 216, 0.12);
}

.save-bar i {
  display: block;
  height: 100%;
  border-radius: 6px;
  background: var(--grad);
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.45);
  transition: width 0.4s ease;
}

/* ---------------- actions ---------------- */

.actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 22px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s, box-shadow 0.15s;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--grad);
  color: #ffffff;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.38);
}

.btn-primary:hover {
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.5);
  filter: brightness(1.05);
}

.btn-ghost {
  background: var(--blue-faint);
  border-color: var(--line-2);
  color: var(--blue-strong);
}

.btn-ghost:hover {
  background: var(--surface-3);
  border-color: var(--blue);
}

.btn-block {
  width: 100%;
}

.actions .btn-ghost {
  padding: 0 16px;
}

.actions .btn-refresh {
  margin-left: auto;
}

/* ---------------- records ---------------- */

.records {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.records-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(135deg, #eaf2ff, #f6faff);
}

.rh-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--blue-deep);
  letter-spacing: 0.5px;
}

.rh-count {
  font-size: 12px;
  color: var(--ink-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 2px 10px;
}

.records-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 0;
}

.records-body::-webkit-scrollbar {
  width: 8px;
}

.records-body::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: 4px;
}

.records-body::-webkit-scrollbar-track {
  background: transparent;
}

.records-empty {
  padding: 60px 16px;
  text-align: center;
  color: var(--ink-3);
  font-size: 14px;
}

.rec-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  transition: background 0.12s;
  position: relative;
}

.rec-row:last-child {
  border-bottom: none;
}

.rec-row:hover {
  background: var(--blue-faint);
}

.rec-row::before {
  content: "";
  flex: none;
  width: 4px;
  height: 30px;
  border-radius: 3px;
  background: var(--line-2);
}

.rec-row[data-type="income"]::before { background: var(--green); }
.rec-row[data-type="expense"]::before { background: var(--red); }
.rec-row[data-type="borrow"]::before { background: var(--blue); }
.rec-row[data-type="repay"]::before { background: var(--amber); }

.rec-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.rec-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rec-meta {
  font-size: 12px;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  gap: 6px;
}

.rec-tag {
  font-style: normal;
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 6px;
  font-weight: 600;
  flex: none;
}

.tag-income { background: var(--green-soft); color: var(--green); }
.tag-expense { background: var(--red-soft); color: var(--red); }
.tag-borrow { background: var(--blue-soft); color: var(--blue-strong); }
.tag-repay { background: var(--amber-soft); color: var(--amber); }

.rec-nums {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  flex: none;
}

.rec-amount {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.rec-after {
  font-size: 11px;
  color: var(--ink-3);
}

.amount-up { color: var(--green); }
.amount-down { color: var(--red); }
.amount-neutral { color: var(--blue); }

.rec-del {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.rec-del:hover {
  background: var(--red-soft);
  color: var(--red);
}

/* ---------------- login ---------------- */

.login-page {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(900px 560px at 82% -10%, rgba(96, 165, 250, 0.5), transparent 60%),
    radial-gradient(760px 520px at -8% 115%, rgba(29, 78, 216, 0.42), transparent 58%),
    linear-gradient(150deg, #2563eb, #3b82f6 52%, #60a5fa);
}

.login-card {
  width: min(410px, 94vw);
  background: var(--surface);
  border-radius: 22px;
  padding: 38px 34px 32px;
  box-shadow: 0 24px 60px rgba(13, 48, 132, 0.45);
}

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}

.login-brand .brand-logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  margin-bottom: 14px;
  padding: 4px;
}

.login-brand h1 {
  font-size: 23px;
  letter-spacing: 3px;
  color: var(--blue-deep);
}

.login-brand p {
  font-size: 13px;
  color: var(--ink-3);
  margin-top: 8px;
  letter-spacing: 1px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.login-opts {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px;
}

.opt {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
}

.opt input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--blue);
  cursor: pointer;
}

/* ---------------- fields ---------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 13px;
  color: var(--ink-2);
  font-weight: 600;
}

.field input {
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 15px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-soft);
  background: var(--surface);
}

.field input::placeholder {
  color: var(--ink-3);
}

.form-error {
  font-size: 13px;
  color: var(--red);
  padding: 9px 12px;
  background: var(--red-soft);
  border-radius: 10px;
  border: 1px solid rgba(239, 68, 68, 0.25);
}

/* ---------------- segmented control ---------------- */

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-3);
  border-radius: 12px;
}

.seg-item {
  height: 38px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.seg-item.active {
  background: var(--grad);
  color: #ffffff;
  box-shadow: 0 3px 8px rgba(37, 99, 235, 0.35);
}

/* ---------------- modal ---------------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(22, 38, 74, 0.5);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  width: min(420px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  background: linear-gradient(135deg, #eaf2ff, #f8fbff);
  border-bottom: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
}

.modal-head h3 {
  font-size: 17px;
  color: var(--blue-deep);
}

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 4px 20px 20px;
}

/* ---------------- toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  top: 72px;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-left: 4px solid var(--blue);
  border-radius: 12px;
  padding: 12px 22px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  max-width: 86vw;
  animation: toast-drop 0.28s ease-out;
}

@keyframes toast-drop {
  from {
    transform: translate(-50%, -18px);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

.toast.error {
  border-left-color: var(--red);
}

/* ---------------- responsive ---------------- */

@media (max-width: 640px) {
  .page {
    padding: 12px 12px 16px;
  }

  .stats {
    gap: 10px;
  }

  .card {
    padding: 13px 14px;
  }

  .card-value {
    font-size: 22px;
  }

  .card-balance .card-value {
    font-size: 27px;
  }

  .card-loan .card-value {
    font-size: 21px;
  }

  .actions .btn {
    padding: 0 14px;
    font-size: 13px;
  }

  .user-name {
    display: none;
  }

  .brand-name {
    font-size: 15px;
  }
}
