:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --panel: #ffffff;
  --panel-soft: #fbfbf7;
  --ink: #161616;
  --muted: #71717a;
  --faint: #a1a1aa;
  --line: #e7e5df;
  --line-strong: #d8d5ca;
  --good: #15803d;
  --good-soft: #dcfce7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --violet: #6d28d9;
  --violet-soft: #ede9fe;
  --shadow: 0 12px 30px rgba(35, 34, 30, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #737373;
  box-shadow: 0 0 0 3px rgba(115, 115, 115, 0.12);
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

#app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 18px 80px;
}

.boot {
  min-height: 70vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  color: var(--muted);
}

.app-shell {
  display: grid;
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0 2px;
}

.title {
  margin: 0;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.08;
  letter-spacing: 0;
}

.subline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  white-space: nowrap;
}

.status-pill.ok {
  border-color: #bbf7d0;
  color: var(--good);
  background: #f0fdf4;
}

.status-pill.warn,
.status-pill.saving {
  border-color: #fde68a;
  color: var(--warn);
  background: #fffbeb;
}

.status-pill.error {
  border-color: #fecaca;
  color: var(--bad);
  background: #fff1f2;
}

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

.btn {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s, color 0.15s, transform 0.15s;
}

.btn:hover {
  border-color: var(--line-strong);
}

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

.btn.primary {
  border-color: #111;
  background: #111;
  color: #fff;
}

.btn.danger {
  border-color: #fecaca;
  color: var(--bad);
  background: #fff;
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.tabbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(247, 247, 244, 0.92);
  backdrop-filter: blur(14px);
}

.tab {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.tab.active {
  background: #111;
  color: #fff;
}

.grid {
  display: grid;
  gap: 14px;
}

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

.grid.sidebar {
  grid-template-columns: minmax(280px, 0.95fr) minmax(0, 1.35fr);
  align-items: start;
}

.metric {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.metric-value {
  margin-top: 7px;
  font-size: clamp(24px, 4vw, 38px);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: 0;
}

.section-title {
  margin: 8px 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stack {
  display: grid;
  gap: 10px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 20px rgba(35, 34, 30, 0.05);
}

.member-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 14px;
}

.member-card.low {
  border-color: #fecaca;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  font-weight: 850;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.row.wrap {
  flex-wrap: wrap;
}

.name {
  min-width: 0;
  font-size: 15px;
  font-weight: 760;
}

.amount {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 830;
}

.amount.pos {
  color: var(--good);
}

.amount.neg {
  color: var(--bad);
}

.note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.gauge {
  position: relative;
  height: 8px;
  margin-top: 9px;
  border-radius: 999px;
  background: #eeeeea;
  overflow: hidden;
}

.gauge > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #86efac, #22c55e);
}

.gauge.low > span {
  background: linear-gradient(90deg, #fecaca, #ef4444);
}

.threshold {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  border-radius: 2px;
  background: var(--warn);
}

.alert-list {
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.alert-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid #fff1f2;
}

.alert-item:last-child {
  border-bottom: 0;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.chip.active {
  border-color: #111;
  background: #111;
  color: #fff;
}

.form-panel {
  display: grid;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.field {
  display: grid;
  gap: 8px;
}

.field label,
.field-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.04em;
}

.input-money {
  position: relative;
}

.input-money input {
  padding-right: 34px;
  font-size: 20px;
  font-weight: 780;
}

.input-money span {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.mini-grid {
  display: grid;
  gap: 8px;
}

.member-input-row {
  display: grid;
  grid-template-columns: auto minmax(72px, 90px) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.preview {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.history-item {
  padding: 13px;
}

.history-head {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

.type-badge {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 900;
}

.history-title {
  min-width: 0;
  font-weight: 780;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.detail-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 6px 0;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.error-box {
  padding: 16px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff1f2;
  color: var(--bad);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(24, 24, 27, 0.45);
}

.modal {
  width: min(420px, 100%);
  padding: 20px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
}

.modal.edit-modal {
  width: min(680px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.modal p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #d4d4d8;
  border-top-color: #111;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.saving-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.restaurant-layout {
  display: grid;
  grid-template-columns: minmax(360px, 1.15fr) minmax(280px, 0.85fr);
  gap: 14px;
  align-items: start;
}

.restaurant-map-card {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.restaurant-map {
  width: 100%;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ecebe4;
  overflow: hidden;
}

.restaurant-map.map-error {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.restaurant-results {
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
}

.restaurant-result {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.restaurant-result span,
.selected-restaurant span {
  color: var(--muted);
  font-size: 12px;
}

.selected-restaurant {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.selected-restaurant a {
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
}

.restaurant-list {
  display: grid;
  gap: 10px;
}

.restaurant-card {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.restaurant-card.selected {
  border-color: #111;
}

.restaurant-card-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.restaurant-name {
  font-size: 16px;
}

.rating-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 12px;
  font-weight: 800;
}

.review-stack {
  display: grid;
  gap: 8px;
}

.review-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.stars {
  color: var(--warn);
  font-size: 13px;
  font-weight: 900;
}

.review-comment {
  margin-top: 5px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 760px) {
  #app {
    padding: 14px 12px 70px;
  }

  .topbar {
    display: grid;
  }

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

  .grid.two,
  .grid.sidebar,
  .restaurant-layout {
    grid-template-columns: 1fr;
  }

  .tabbar {
    gap: 4px;
  }

  .tab {
    min-height: 40px;
    font-size: 12px;
  }

  .history-head {
    grid-template-columns: 38px minmax(0, 1fr) auto;
  }

  .history-head .btn.danger {
    grid-column: 2 / 4;
    justify-self: end;
  }

  .member-input-row {
    grid-template-columns: auto minmax(66px, 84px) minmax(0, 1fr);
  }

  .restaurant-map {
    min-height: 320px;
  }

  .restaurant-card-head,
  .review-item,
  .search-row {
    grid-template-columns: 1fr;
  }
}
