* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; background: #f4f6fa; color: #1d2433; }
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Nav */
.nav { background: linear-gradient(135deg,#1e3a8a 0%, #2563eb 100%); color: #fff; padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 2px 8px rgba(37,99,235,0.2); }
.nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: 0.3px; }
.install-app { border: 1px solid rgba(255,255,255,.45); border-radius: 999px; padding: 6px 12px; background: rgba(255,255,255,.12); color: #fff; font: inherit; font-size: 13px; cursor: pointer; }
.install-app:hover { background: rgba(255,255,255,.24); }
.nav-account { display: flex; align-items: center; }
.nav .menu a { color: #e0e7ff; margin-left: 18px; font-size: 14px; padding: 6px 10px; border-radius: 6px; }
.nav .menu a:hover { background: rgba(255,255,255,0.12); color: #fff; text-decoration: none; }
.nav .menu a.active { background: rgba(255,255,255,0.2); color: #fff; }
.nav .user { font-size: 13px; color: #c7d2fe; margin-right: 10px; }

.container { max-width: 1200px; margin: 24px auto; padding: 0 20px; }
.category-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.table-scroll { overflow-x: auto; }

/* Cards */
.card { background: #fff; border-radius: 12px; padding: 20px 22px; box-shadow: 0 1px 3px rgba(20,30,60,0.06); margin-bottom: 18px; }
.card h2 { margin: 0 0 14px 0; font-size: 17px; color: #0f172a; display: flex; align-items: center; justify-content: space-between; }
.card h2 .hint { font-size: 12px; font-weight: 500; color: #64748b; }

/* Stats grid */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border-radius: 12px; padding: 18px 20px; box-shadow: 0 1px 3px rgba(20,30,60,0.06); border-left: 4px solid #2563eb; }
.stat.income { border-left-color: #059669; }
.stat.expense { border-left-color: #dc2626; }
.stat.balance { border-left-color: #0891b2; }
.stat.ucoin { border-left-color: #d97706; }
.stat .label { font-size: 13px; color: #64748b; margin-bottom: 6px; }
.stat .value { font-size: 22px; font-weight: 700; color: #0f172a; }
.stat .sub { font-size: 12px; color: #94a3b8; margin-top: 4px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #eef1f6; }
th { background: #f8fafc; color: #475569; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
tr:hover td { background: #f8fafc; }
.num { text-align: right; font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.pos { color: #059669; }
.neg { color: #dc2626; }

/* Forms */
label { display: block; font-size: 13px; color: #475569; margin: 10px 0 6px; font-weight: 500; }
input[type=text], input[type=number], input[type=password], input[type=datetime-local], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 14px; background: #fff; transition: all 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* Buttons */
.btn { display: inline-block; padding: 9px 16px; border-radius: 8px; font-size: 14px; font-weight: 500;
       border: none; cursor: pointer; background: #2563eb; color: #fff; transition: all 0.15s; }
.btn:hover { background: #1d4ed8; text-decoration: none; color: #fff; }
.btn.secondary { background: #e2e8f0; color: #334155; }
.btn.secondary:hover { background: #cbd5e1; color: #0f172a; }
.btn.danger { background: #dc2626; }
.btn.danger:hover { background: #b91c1c; }
.btn.success { background: #059669; }
.btn.success:hover { background: #047857; }
.btn.sm { padding: 6px 12px; font-size: 13px; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg,#1e3a8a 0%, #2563eb 50%, #0891b2 100%); padding: 20px; }
.login-card { background: #fff; border-radius: 16px; padding: 36px 34px; width: 100%; max-width: 400px;
  box-shadow: 0 20px 50px rgba(15,23,42,0.3); }
.login-card h1 { margin: 0 0 6px; font-size: 22px; color: #0f172a; }
.login-card .sub { color: #64748b; font-size: 13px; margin-bottom: 22px; }
.login-card .err { background: #fef2f2; color: #b91c1c; padding: 10px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 14px; border: 1px solid #fecaca; }
.login-card .btn { width: 100%; padding: 12px; font-size: 15px; margin-top: 8px; }
.login-card .hint { margin-top: 14px; font-size: 12px; color: #94a3b8; text-align: center; }

/* Alerts */
.msg, .err-msg { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.msg { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.err-msg { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* Small helper */
.muted { color: #64748b; }
.flex { display: flex; gap: 8px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.mb-0 { margin-bottom: 0; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.pill.income { background: #d1fae5; color: #065f46; }
.pill.expense { background: #fee2e2; color: #991b1b; }
.pill.u { background: #fef3c7; color: #92400e; }
.pill.cash { background: #cffafe; color: #155e75; }

/* Responsive */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .nav { position: sticky; top: 0; z-index: 20; min-height: 58px; padding: 10px 16px; }
  .nav .brand { font-size: 16px; }
  .nav-account { display: contents; }
  .nav .user { margin: 0; position: absolute; right: 16px; top: 13px; max-width: 32%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav .menu { position: fixed; z-index: 30; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; padding: 8px 4px calc(8px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.97); border-top: 1px solid #e2e8f0; box-shadow: 0 -4px 18px rgba(15,23,42,.08); }
  .nav .menu a { display: flex; justify-content: center; align-items: center; min-height: 42px; margin: 0; padding: 6px 2px; border-radius: 8px; color: #475569; font-size: 12px; white-space: nowrap; }
  .nav .menu a.active { background: #eff6ff; color: #1d4ed8; }
  .nav .menu a:nth-child(4) { display: none; }
  body.has-app-nav { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  table { font-size: 13px; }
  th, td { padding: 8px 6px; }
  .container { margin: 16px auto; }
  .stat { min-width: 0; padding: 14px; }
  .stat .value { font-size: clamp(17px, 5vw, 22px); overflow-wrap: anywhere; }
  .card h2 { gap: 8px; }
  .flex-between { gap: 12px; }
  .flex-between > div:last-child { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
  .btn { min-height: 40px; }
  input[type=text], input[type=number], input[type=password], input[type=datetime-local], select, textarea { min-height: 44px; font-size: 16px; }
}
@media (max-width: 500px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .container { padding: 0 12px; }
  .card { padding: 14px 14px; }
  .nav { padding-right: 12px; padding-left: 12px; }
  .nav .brand { font-size: 14px; }
  .nav .user { display: none; }
  .install-app { padding: 5px 9px; font-size: 12px; }
  .stat { padding: 12px 10px; border-left-width: 3px; }
  .stat .label { font-size: 11px; line-height: 1.35; }
  .stat .value { font-size: clamp(16px, 5vw, 20px); }
  .stat .sub { font-size: 11px; }
  .login-card { padding: 28px 22px; }
  .category-grid { grid-template-columns: minmax(0, 1fr); }
}
