:root {
  --bg: #f8fafc;
  --bg-panel: #ffffff;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --text: #1e293b;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --good: #16a34a;
  --bad: #dc2626;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", "Noto Sans TC", sans-serif;
  color: var(--text);
  background-color: var(--bg);
  line-height: 1.5;
}

.app {
  width: min(94vw, 800px);
  margin: 20px auto 60px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hero {
  padding: 24px;
  text-align: center;
  background: white;
  border-radius: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}

.hero h1 {
  margin: 0 0 8px;
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
}

.sub {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.panel {
  padding: 20px;
  background: var(--bg-panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  animation: fade-up 0.4s ease-out;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

/* Room Bar */
.room-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.room-bar label {
  flex: 1;
  min-width: 150px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

/* Form Elements */
input[type="text"],
input[type="number"],
input[type="date"],
select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 15px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid var(--line-strong);
  background: white;
  color: var(--text);
  min-height: 42px;
}

.btn:hover:not(:disabled) {
  background: #f1f5f9;
  border-color: var(--line-strong);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--primary);
  color: white;
  border: none;
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn.danger {
  color: var(--bad);
}

.btn.ghost {
  border: none;
  background: transparent;
  color: var(--primary);
  padding: 6px 12px;
}

.btn.ghost:hover {
  background: #eff6ff;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: #f1f5f9;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 18px;
}

.btn-icon:hover {
  background: #e2e8f0;
}

.btn-icon.danger {
  color: var(--bad);
  background: #fef2f2;
}

.btn-icon.danger:hover {
  background: #fee2e2;
}

/* Member List */
.member-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: #f8fafc;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.member-item input {
  margin: 0;
  padding: 6px 8px;
  font-size: 14px;
  border-color: transparent;
  background: transparent;
}

.member-item input:focus {
  background: white;
  border-color: var(--line);
}

/* Expense Form */
.expense-form {
  display: grid;
  gap: 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mode-switch {
  display: flex;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 12px;
  gap: 4px;
}

.mode-switch label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s;
}

.mode-switch input {
  display: none;
}

.mode-switch label:has(input:checked) {
  background: white;
  color: var(--primary);
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* Split List */
.split-list {
  display: grid;
  gap: 8px;
}

.split-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #f8fafc;
  border-radius: 10px;
}

.split-item span {
  flex: 1;
  font-weight: 500;
}

.split-item .exact-amount {
  width: 100px;
  margin: 0;
  padding: 6px 10px;
}

/* Expense Log */
.expense-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.expense-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.expense-info {
  flex: 1;
}

.expense-item-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.expense-item-title strong {
  font-size: 16px;
}

.expense-item-title .amount {
  color: var(--primary);
  font-weight: 700;
}

.expense-item-meta {
  font-size: 13px;
  color: var(--muted);
}

.expense-actions {
  display: flex;
  gap: 8px;
}

/* Result Panel */
.balance-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.balance-item {
  padding: 16px;
  border-radius: 12px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.balance-item span:first-child {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.balance-item span:last-child {
  font-size: 18px;
  font-weight: 800;
}

.balance-item.pos span:last-child { color: var(--good); }
.balance-item.neg span:last-child { color: var(--bad); }

.transactions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tx-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: #f0fdf4;
  border-radius: 12px;
  border: 1px solid #dcfce7;
  font-weight: 600;
}

.tx-arrow {
  color: var(--muted);
}

.tx-amount {
  margin-left: auto;
  color: var(--good);
}

/* Status Classes */
.success { color: var(--good); }
.error { color: var(--bad); }

#member-panel.collapsed .member-list {
  display: none;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
  .hero h1 { font-size: 28px; }
  .grid-2 { grid-template-columns: 1fr; }
  .room-bar label { min-width: 100%; }
  .expense-item { flex-direction: column; align-items: flex-start; gap: 12px; }
  .expense-actions { width: 100%; justify-content: flex-end; }
}
