:root {
  --bg: #f5f5f7;
  --surface: rgba(255, 255, 255, 0.82);
  --card: rgba(255, 255, 255, 0.75);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #0071e3;
  --accent-soft: #e8f2ff;
  --border: rgba(0, 0, 0, 0.08);
  --danger: #d70015;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(circle at top, #fcfcfd, #f2f2f5 45%, #ececf1 100%);
  color: var(--text);
  position: relative;
  overflow-x: hidden;
}

.bg-orb { position: fixed; border-radius: 999px; filter: blur(35px); opacity: 0.35; pointer-events: none; }
.orb-1 { width: 280px; height: 280px; background: #cfe7ff; top: -80px; left: -70px; }
.orb-2 { width: 260px; height: 260px; background: #e8d9ff; right: -60px; top: 120px; }

header, main { max-width: 1200px; margin: 0 auto; padding: 18px; position: relative; z-index: 2; }
header { display: flex; flex-direction: column; gap: 8px; }
header h1 { margin: 0; font-size: 34px; letter-spacing: -0.02em; }
header p { margin: 6px 0 0 0; color: var(--muted); }

.header-top {
  display: block;
}

.header-title-wrap {
  min-width: 0;
  padding-right: 360px;
}

.auth-top-right {
  position: absolute;
  top: 18px;
  right: 18px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.75);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 10px;
  min-height: 44px;
}

#userBadge {
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}

#googleSignIn {
  display: inline-flex;
  align-items: center;
}

@media (max-width: 900px) {
  .header-title-wrap { padding-right: 0; }

  .auth-top-right {
    position: static;
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  #userBadge {
    max-width: 100%;
  }
}

.layout { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: start; width: 100%; }
.content { min-width: 0; width: 100%; }

body.signed-out #appMain {
  display: none !important;
}

body.signed-out #signedOutPlaceholder {
  display: block !important;
}

.signed-out-placeholder {
  max-width: 1200px;
  margin: 0 auto 12px auto;
  text-align: center;
  padding: 42px 20px;
}

.intro-illustration {
  width: min(680px, 100%);
  border-radius: 18px;
  border: 1px solid var(--border);
  margin-bottom: 18px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.05);
}

.card {
  background: var(--card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.04);
}
.card h2 { margin-top: 0; letter-spacing: -0.01em; }

.rank-inline {
  display: inline-flex;
  align-items: center;
}

.rank-inline select {
  min-width: 190px;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 10px;
  line-height: 1.1;
}

.sidebar { position: sticky; top: 18px; padding: 10px; }
.nav-btn {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.75);
  color: #303135;
  text-align: left;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 14px;
  cursor: pointer;
}
.nav-btn.active {
  background: var(--accent-soft);
  border-color: #bfdcff;
  color: #0058b5;
  font-weight: 600;
}

#dashboard { position: static !important; top: auto !important; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

input, select, button {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.9);
  color: var(--text);
  padding: 10px 11px;
  font-size: 14px;
}
input:focus, select:focus { outline: none; border-color: #9cc6ff; box-shadow: 0 0 0 4px var(--accent-soft); }
button { cursor: pointer; font-weight: 600; background: var(--accent); color: white; border-color: transparent; }
button:hover { filter: brightness(1.02); }

.btn-secondary { background: #f4f4f6; color: #2e2e30; border: 1px solid var(--border); }
.btn-xs { padding: 4px 7px !important; font-size: 11px !important; border-radius: 9px; }
.btn-danger { background: #fff1f2; color: var(--danger); border: 1px solid #ffd6db; }

.muted { color: var(--muted); font-size: 13px; }
.kpi { display: inline-flex; flex-direction: column; min-width: 120px; margin-right: 10px; margin-bottom: 8px; padding: 8px 11px; background: rgba(255,255,255,0.85); border: 1px solid var(--border); border-radius: 13px; }
.kpi-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 20px; font-weight: 700; line-height: 1.1; }
.dash-panels { display:grid; grid-template-columns: 1fr; gap:10px; margin-bottom:10px; }
.dash-panel { background: var(--surface); border:1px solid var(--border); border-radius:12px; padding:8px 10px; }
.dash-panel h3 { margin:0 0 6px 0; font-size:13px; }
.dash-panel-head { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.decision-row { display:flex; justify-content:space-between; gap:8px; align-items:center; margin:4px 0; font-size:12px; }
.fee-alert-row { border-left: 3px solid var(--danger); padding-left: 8px; }
.fee-alert-row .badge { border-color: #ffd6db; background: #fff1f2; }
.dash-grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap:10px; }
.dash-card-tile { background: var(--surface); border:1px solid var(--border); border-radius:12px; padding:10px; }
.dash-card-top { display:flex; gap:10px; align-items:center; }
.dash-card-img-wrap { position:relative; width:86px; height:54px; border-radius:8px; overflow:visible; border:1px solid var(--border); background:#f1f4f8; display:flex; align-items:center; justify-content:center; text-decoration:none; }
.dash-card-img { width:78px; height:48px; object-fit:contain; display:block; }
.benefit-left-bubble { position:absolute; top:-10px; right:-10px; background:#111827; color:#fff; border-radius:999px; min-width:22px; height:22px; padding:0 6px; display:flex; align-items:center; justify-content:center; font-size:12px; font-weight:700; border:2px solid #fff; z-index:2; }
.dash-card-name { font-weight:700; font-size:14px; }
.progress { height: 9px; background: #e9e9ee; border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, #2ea8ff, #33c759); }
.row { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.badge { font-size: 12px; border: 1px solid #d8d8de; border-radius: 999px; padding: 3px 9px; color: #606268; background: rgba(255,255,255,0.8); }
.redeemed-num { color: #198754; font-weight: 700; }
.allowance-num { font-weight: 700; }
.danger { color: var(--danger); }
ul { margin: 8px 0; padding-left: 18px; }

.card-item { margin-bottom: 14px; padding: 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.card-shell { display: grid; grid-template-columns: 140px 1fr; gap: 14px; align-items: center; margin-bottom: 8px; }
.card-art-wrap { width: 140px; height: 88px; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: #f0f3f7; display:flex; align-items:center; justify-content:center; text-decoration:none; }
.card-art-wrap:hover { box-shadow: 0 0 0 3px var(--accent-soft); }
.card-art { width: 132px; height: 80px; object-fit: contain; display:block; }
.card-art-fallback { font-size: 28px; opacity: 0.7; }
.benefit-item { margin: 10px 0; padding: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.quick-log-row { margin-top: 8px; display: grid; grid-template-columns: 110px 150px auto auto; gap: 6px; align-items: center; }
.quick-log-row input { padding: 7px 8px; font-size: 12px; }
.quick-log-row button { padding: 7px 9px; font-size: 12px; }
.manage-row { display:grid; grid-template-columns: 1.2fr 1fr 0.7fr 1.5fr auto auto; gap:8px; margin:8px 0; align-items:center; }
.usage-row { display:grid; grid-template-columns: minmax(130px,1fr) minmax(130px,1fr) 120px 100px minmax(110px,1fr) minmax(120px,1fr) 70px 70px; gap:6px; margin:8px 0; align-items:center; }
.readonly-field { background:#f7f8fa !important; color:#1d1d1f !important; font-weight:600; }
.manage-row input, .manage-row select, .usage-row input { padding:8px 9px; font-size:13px; min-width:0; }
.manage-row button, .usage-row button { padding:8px 8px; font-size:12px; min-width:0; }
.period-grid { margin-top: 8px; display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.period-grid.period-monthly { grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; }
.period-grid.period-monthly .period-item { padding: 4px; }
.period-grid.period-monthly .period-label { font-size: 10px; margin-bottom: 2px; }
.period-grid.period-monthly .period-amount { font-size: 9px; margin-top: 2px; }
.period-item { background: rgba(255,255,255,0.72); border: 1px solid var(--border); border-radius: 10px; padding: 6px; }
.period-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.period-amount { margin-top: 4px; font-size: 11px; color: #53545a; }
.card-actions { display: flex; gap: 8px; align-items:center; }
.card-actions button { padding: 7px 10px; font-size: 13px; }
a { color: #0066cc; text-decoration: none; }
a:hover { text-decoration: underline; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 8px;
    z-index: 5;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 6px;
  }
  .nav-btn { margin: 0; min-width: 150px; padding: 9px 10px; }
  .card-shell { grid-template-columns: 1fr; }
  .card-art-wrap { width: 100%; height: 140px; }
  .quick-log-row { grid-template-columns: 1fr 1fr; }
  .manage-row, .usage-row { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  header, main { padding: 12px; }
  header h1 { font-size: 27px; }
  .card { padding: 12px; border-radius: 14px; }

  .kpi {
    min-width: 0;
    width: calc(50% - 8px);
    margin-right: 6px;
    padding: 8px 9px;
  }
  .kpi-value { font-size: 18px; }

  .dash-panel-head {
    align-items: flex-start;
    flex-direction: column;
  }
  .rank-inline,
  .rank-inline select {
    width: 100%;
  }

  .dash-card-top {
    gap: 8px;
    align-items: flex-start;
  }
  .dash-card-img-wrap {
    width: 72px;
    height: 46px;
  }
  .dash-card-img {
    width: 66px;
    height: 40px;
  }

  .card-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .period-grid.period-monthly {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
  }

  .quick-log-row {
    grid-template-columns: 1fr;
  }

  .decision-row {
    align-items: flex-start;
    flex-direction: column;
  }
}

.ghost-btn {
  background: #f4f4f6;
  color: #2e2e30;
  border: 1px solid var(--border);
}
