:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-soft: #eef4f1;
  --ink: #1d2724;
  --muted: #66736e;
  --line: #dbe3df;
  --green: #168a62;
  --green-dark: #0d6447;
  --blue: #2868b7;
  --amber: #c47a12;
  --red: #c74343;
  --shadow: 0 18px 50px rgba(29, 39, 36, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
input,
select {
  font: inherit;
}

img {
  max-width: 100%;
}

button {
  cursor: pointer;
}

button[hidden] {
  display: none;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(244, 246, 245, 0.94);
  backdrop-filter: blur(10px);
}

.auth-screen.hidden {
  display: none;
}

.auth-card {
  width: min(440px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-brand {
  margin-bottom: 20px;
  color: var(--ink);
}

.auth-brand .brand span {
  color: var(--muted);
}

.auth-card h1 {
  margin-bottom: 10px;
  font-size: 28px;
}

.auth-card p {
  color: var(--muted);
  line-height: 1.55;
}

.auth-form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.auth-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.auth-form input {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}

.auth-note {
  margin: 14px 0 0;
  font-size: 13px;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 28px 20px;
  background: #16241f;
  color: #f8fbf9;
  overflow-y: auto;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #f2c46d;
  color: #16241f;
  flex: 0 0 auto;
  overflow: hidden;
}

.logo-mark {
  background: #ffffff;
  border: 1px solid rgba(22, 36, 31, 0.16);
}

.logo-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 3px;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 18px;
}

.brand span {
  color: #b7c8c1;
  font-size: 13px;
  margin-top: 2px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #dce8e4;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
}

.store-panel {
  display: grid;
  gap: 7px;
  margin-top: 0;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.store-panel label {
  color: #b7c8c1;
  font-size: 12px;
}

.store-panel input,
.store-panel select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.store-panel input:disabled {
  opacity: 0.55;
}

.content {
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.tool-button,
.primary-button,
.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
}

.tool-button {
  padding: 0 12px;
}

.sync-badge {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.sync-badge[data-tone="ok"] {
  border-color: rgba(22, 138, 98, 0.25);
  background: #e9f7f0;
  color: var(--green-dark);
}

.sync-badge[data-tone="working"] {
  border-color: rgba(196, 122, 18, 0.25);
  background: #fff7e8;
  color: var(--amber);
}

.sync-badge[data-tone="bad"] {
  border-color: rgba(199, 67, 67, 0.25);
  background: #fff0f0;
  color: var(--red);
}

.tool-button.danger {
  color: var(--red);
}

.primary-button {
  padding: 0 16px;
  border-color: var(--green);
  background: var(--green);
  color: #ffffff;
}

.mini-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.mini-button.delete {
  color: var(--red);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

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

.metric {
  display: grid;
  gap: 7px;
  min-height: 132px;
  padding: 18px;
}

.metric span,
.metric small,
.panel-head p,
.settlement-list dt,
.bar-row span,
.recent-item span {
  color: var(--muted);
}

.metric strong {
  font-size: 26px;
  letter-spacing: 0;
}

.dashboard-grid,
.settlement-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 16px;
}

.panel {
  padding: 18px;
}

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

.panel-head p {
  margin-bottom: 0;
  font-size: 13px;
}

.payment-bars {
  display: grid;
  gap: 14px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.bar-track {
  height: 11px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1ef;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.recent-list,
.app-summary {
  display: grid;
  gap: 10px;
}

.recent-item,
.app-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.recent-item strong,
.app-card strong {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.entry-form {
  margin-bottom: 16px;
}

.form-panel {
  background: linear-gradient(180deg, #ffffff 0%, #fbfdfc 100%);
}

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

.form-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.form-grid input,
.form-grid select {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 500;
}

.expense-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 18px;
  align-items: start;
}

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

.wide-field {
  grid-column: 1 / -1;
}

.receipt-box {
  display: grid;
  gap: 10px;
}

.receipt-picker {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 18px;
  border: 1px dashed #9fb3ab;
  border-radius: 8px;
  background: #f5faf7;
  color: var(--green-dark);
  text-align: center;
  cursor: pointer;
}

.receipt-picker strong,
.receipt-picker span {
  display: block;
}

.receipt-picker strong {
  margin-top: 8px;
  color: var(--ink);
}

.receipt-picker span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

#receiptImage {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

#receiptPreview {
  display: none;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

#receiptPreview.show {
  display: block;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child,
th:last-child,
td:last-child {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
}

.actions {
  display: flex;
  gap: 6px;
}

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

.expense-item {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.receipt-thumb {
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
}

button.receipt-thumb {
  padding: 0;
}

.receipt-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.expense-info {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.expense-info strong {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.expense-info span {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.settlement-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.settlement-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.settlement-list div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.settlement-list dd {
  margin: 0;
  font-weight: 800;
}

.empty {
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .nav-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .store-panel {
    margin-top: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .dashboard-grid,
  .settlement-layout,
  .expense-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .content {
    padding: 18px;
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

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

  .nav-list,
  .metric-grid,
  .form-grid,
  .store-panel {
    grid-template-columns: 1fr;
  }

  .expense-item {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .expense-item .actions {
    grid-column: 1 / -1;
  }

  .nav-item {
    min-height: 42px;
  }

  .metric strong {
    font-size: 23px;
  }
}
