:root {
  --bg-1: #fff3fb;
  --bg-2: #f4f8ff;
  --bg-3: #fff8e8;
  --card: rgba(255, 255, 255, 0.78);
  --card-strong: rgba(255, 255, 255, 0.92);
  --line: rgba(151, 119, 179, 0.18);
  --text: #2d2234;
  --muted: #e91e63a1;
  --shadow: 0 18px 50px rgba(180, 140, 196, 0.18);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --pink: #ffd8e9;
  --pink-2: #ffe8f1;
  --blue: #dff0ff;
  --purple: #eee0ff;
  --yellow: #fff3c9;
  --mint: #ddf6ef;
  --dark: #2d2234;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family:
    ui-sans-serif,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "Noto Sans TC",
    "Microsoft JhengHei",
    sans-serif;
  color: var(--text);
  background-color: #ffdbeae6;
}

img,
canvas,
table {
  max-width: 100%;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: 100%;
  padding: 18px 14px 40px;
}

.topbar,
.dashboard {
  width: min(1280px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.brand-badge {
  width: 66px;
  height: 63px;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  font-size: 1.45rem;
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.45rem, 2.7vw, 2.1rem);
  line-height: 1.1;
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}


.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.auth-state,
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--line);
  color: var(--muted);
  box-shadow: 0 10px 26px rgba(180, 140, 196, 0.08);
  white-space: nowrap;
}

.dashboard {
  display: grid;
  gap: 20px;
}

.top-grid {
  display: grid;
  gap: 20px;
}

.side-stack {
  display: grid;
  gap: 20px;

  /* ✅ 高度隨內容 */
  grid-template-rows: auto auto;
}

.card {
  min-width: 0;
  overflow: hidden;
  border-radius: var(--radius-xl);
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding: 20px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}

.card-head h2,
.chart-card h3,
.category-list-wrap h3 {
  margin: 0;
}

.card-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.detail-head {
  margin-bottom: 14px;
}

.card-add {
  height: 100%;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.84),
      rgba(255, 255, 255, 0.74)
    ),
    linear-gradient(
      135deg,
      rgba(255, 216, 233, 0.34),
      rgba(223, 240, 255, 0.28)
    );
}

.card-summary {
  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.84),
      rgba(255, 255, 255, 0.72)
    ),
    linear-gradient(
      135deg,
      rgba(238, 224, 255, 0.34),
      rgba(255, 243, 201, 0.22)
    );
}

.card-credit {
  height: auto;
  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.84),
      rgba(255, 255, 255, 0.72)
    ),
    linear-gradient(135deg, rgba(221, 246, 239, 0.3), rgba(255, 232, 241, 0.22));
}

.card-detail {
  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.88),
      rgba(255, 255, 255, 0.78)
    ),
    linear-gradient(
      135deg,
      rgba(255, 243, 201, 0.18),
      rgba(223, 240, 255, 0.16)
    );
}

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

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--dark);
  font-weight: 700;
  min-width: 0;
}

label span {
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 600;
}

.full {
  grid-column: 1 / -1;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(168, 133, 191, 0.22);
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  border-radius: 16px;
  padding: 0.92rem 1rem;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(151, 119, 179, 0.55);
  box-shadow: 0 0 0 4px rgba(233, 208, 250, 0.45);
}

textarea {
  resize: vertical;
  min-height: 104px;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #59425f 50%),
    linear-gradient(135deg, #59425f 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(1em + 3px),
    calc(100% - 12px) calc(1em + 3px);
  background-size:
    6px 6px,
    6px 6px;
  background-repeat: no-repeat;
  padding-right: 2.4rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 0.86rem 1.1rem;
  font-weight: 800;
  color: var(--dark);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 10px 25px rgba(180, 140, 196, 0.14);
  transition:
    transform 0.16s ease,
    box-shadow 0.16s ease,
    opacity 0.16s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(180, 140, 196, 0.18);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, #ffd8e9, #dff0ff);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.76);
}

.btn-wide {
  min-width: 120px;
}

.month-filter {
  min-width: 140px;
  max-width: 170px;
}

.month-filter span {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.month-filter select {
  padding: 0.8rem 0.9rem;
}

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

.kpi {
  border-radius: 22px;
  padding: 14px;
  background: var(--card-strong);
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.kpi span {
  display: block;
  font-size: 0.86rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.kpi strong {
  display: block;
  font-size: clamp(1.2rem, 2vw, 1.7rem);
  line-height: 1.1;
}

.kpi-income {
  background: linear-gradient(
    135deg,
    rgba(223, 240, 255, 0.98),
    rgba(255, 255, 255, 0.96)
  );
}
.kpi-expense {
  background: linear-gradient(
    135deg,
    rgba(255, 232, 241, 0.98),
    rgba(255, 255, 255, 0.96)
  );
}
.kpi-remaining {
  background: linear-gradient(
    135deg,
    rgba(255, 243, 201, 0.98),
    rgba(255, 255, 255, 0.96)
  );
}

.chart-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
  margin-bottom: 10px;
}

.chart-card {
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 24px;
  padding: 14px;
  min-width: 0;
  max-height: 300px;
  aspect-ratio: 10 / 10;
}

.chart-card h3 {
  font-size: 1rem;
  margin-bottom: 10px;
}

.category-list-wrap {
  margin-top: 3em;
}

.category-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.category-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 0.68rem 0.9rem;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(168, 133, 191, 0.18);
  color: var(--dark);
  font-weight: 700;
}

.category-chip small {
  color: var(--muted);
  font-weight: 700;
}

.table-wrap {
  width: 100%;
  min-width: 0;
  height: auto;
}

.table-wrap.compact {
  margin-top: 4px;
}

.detail-table,
.mini-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 10px;
}

.detail-table thead th,
.mini-table thead th {
  text-align: left;
  /* padding: 0 10px 4px; */
  color: var(--muted);
  font-weight: 800;
  background-color: mistyrose;
  padding: 0.5em;
  font-size: 1.2em;
}

.detail-table tbody tr,
.mini-table tbody tr {
  background: rgba(255, 255, 255, 0.9);
}

.detail-table tbody td,
.mini-table tbody td {
  padding: 12px 10px;
  vertical-align: top;
  border-top: 1px solid rgba(255, 255, 255, 0.5);
  border-bottom: 1px solid rgba(255, 255, 255, 0.5);
  min-width: 0;
  overflow-wrap: anywhere;
}

.detail-table tbody td:first-child,
.mini-table tbody td:first-child {
  border-left: 1px solid rgba(255, 255, 255, 0.5);
  border-top-left-radius: 18px;
  border-bottom-left-radius: 18px;
}

.detail-table tbody td:last-child,
.mini-table tbody td:last-child {
  border-right: 1px solid rgba(255, 255, 255, 0.5);
  border-top-right-radius: 18px;
  border-bottom-right-radius: 18px;
}

/* ✅ 偶數列淡底色 */
.detail-table tbody tr:nth-child(even),
.mini-table tbody tr:nth-child(even) {
  background: rgb(255 228 225); /* 淡粉色 */
}

/* ✅ hover 動畫準備 */
.detail-table tbody tr,
.mini-table tbody tr {
  transition: 
    background 0.25s ease,
    transform 0.18s ease,
    box-shadow 0.18s ease;
}

/* ✅ hover 效果（重點✨） */
.detail-table tbody tr:hover,
.mini-table tbody tr:hover {
  background-color: lightcyan;
  transform: translateY(-2px);
}

/* ✅ 讓整列 hover 更明顯（文字加深） */
.detail-table tbody tr:hover td,
.mini-table tbody tr:hover td {
  color: #2d2234;
  font-weight: 600;
}

.detail-table tbody td.amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.empty-row {
  text-align: center;
  color: var(--muted);
  padding: 20px 10px !important;
}

.success {
  color: #186a4f;
}

.warning {
  color: #8a5c00;
}

.danger {
  color: #a11d4f;
}

@media (min-width: 768px) {
  .app-shell {
    padding: 24px 22px 48px;
  }

  .top-grid {
    grid-template-columns: minmax(0, 1.06fr) minmax(0, 0.94fr);
    align-items: stretch;
  }

  .side-stack {
    grid-template-rows: 1fr 0.6fr;
    height: 100%;
  }

  .card-summary,
  .card-credit {
    height: 100%;
  }

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

  .chart-card {
    max-height: 300px;
    aspect-ratio: 10 / 10;
  }

  .detail-table tbody td {
    padding: 14px 12px;
  }
}

@media (min-width: 1024px) {
  .card {
    padding: 24px;
  }

  .form-grid {
    gap: 14px;
  }

  .chart-card {
    padding: 16px;
    max-height: 300px;
    aspect-ratio: 10 / 10;
  }
}

/* mobile table fallback: no horizontal scroll */
@media (max-width: 767px) {
  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

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

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

  .detail-table,
  .detail-table thead,
  .detail-table tbody,
  .detail-table tr,
  .detail-table td {
    display: block;
    width: 100%;
  }

  .detail-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .detail-table tbody tr {
    margin-bottom: 12px;
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.75);
  }

  .detail-table tbody td {
    display: grid;
    grid-template-columns: 92px 1fr;
    gap: 10px;
    align-items: start;
    border: 0 !important;
    padding: 10px 12px;
    text-align: left;
  }

  .detail-table tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 800;
  }

  .detail-table tbody td.amount {
    text-align: left;
  }

  .detail-table tbody td.amount::before {
    content: attr(data-label);
  }

  .mini-table tbody td {
    padding: 10px 8px;
  }
}
