:root {
  --bg: #0f1419;
  --bg-elevated: #171d25;
  --surface: #1e2630;
  --surface-hover: #252f3c;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8edf4;
  --text-muted: #8b98a8;
  --accent: #3d9a6a;
  --accent-hover: #47b07a;
  --accent-soft: rgba(61, 154, 106, 0.15);
  --gold: #d4a853;
  --danger: #e05d5d;
  --shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --font: 'Noto Sans SC', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Courier New', monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(61, 154, 106, 0.18), transparent),
    radial-gradient(ellipse 60% 40% at 90% 10%, rgba(212, 168, 83, 0.08), transparent),
    var(--bg);
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  background: rgba(15, 20, 25, 0.85);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  font-size: 24px;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(380px, 1fr) minmax(320px, 420px);
  gap: 0;
  min-height: 0;
}

.editor-panel {
  padding: 24px 28px 40px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}

.preview-panel {
  padding: 24px 28px 40px;
  background: rgba(0, 0, 0, 0.2);
  overflow-y: auto;
}

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

.panel-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.badge {
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  border: 1px solid rgba(61, 154, 106, 0.25);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}

.toggle input {
  accent-color: var(--accent);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.card h3, .card h4 {
  margin: 0 0 14px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

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

.card-head-row h3, .card-head-row h4 {
  margin: 0;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.field-highlight input {
  border-color: rgba(212, 168, 83, 0.45);
  background: rgba(212, 168, 83, 0.08);
  font-weight: 600;
  font-size: 1.05rem;
}

.field span {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.field input,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: rgba(61, 154, 106, 0.5);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.items-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  position: relative;
}

.item-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.item-index {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-hover);
  letter-spacing: 0.04em;
}

.item-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.expenses-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.expense-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
}

.expenses-block {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s, border-color 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #2d7a52);
  color: #fff;
  box-shadow: 0 4px 16px rgba(61, 154, 106, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), #359466);
}

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

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-accent {
  background: var(--accent-soft);
  color: var(--accent-hover);
  border-color: rgba(61, 154, 106, 0.25);
}

.btn-accent:hover {
  background: rgba(61, 154, 106, 0.25);
}

.btn-danger {
  background: transparent;
  border: none;
  color: var(--danger);
  padding: 4px 8px;
  font-size: 0.8rem;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.preview-stage {
  display: flex;
  justify-content: center;
  padding: 12px 0 20px;
}

.receipt {
  width: 280px;
  min-height: 480px;
  background: #faf8f4;
  color: #1a1a1a;
  padding: 18px 14px 28px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.55;
  box-shadow: var(--shadow), 0 0 0 1px rgba(0, 0, 0, 0.06);
  border-radius: 2px;
  white-space: pre-wrap;
  word-break: break-all;
}

.receipt .title {
  text-align: center;
  font-weight: 700;
  font-size: 12px;
  margin-bottom: 8px;
  line-height: 1.4;
}

.receipt .section {
  text-align: center;
  margin: 6px 0;
  color: #444;
}

.receipt .row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.receipt .row-left {
  flex: 1;
}

.receipt .row-right {
  text-align: right;
  flex-shrink: 0;
}

.receipt .settlement {
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  margin: 10px 0;
}

.receipt .divider {
  border-top: 1px dashed #999;
  margin: 6px 0;
}

.preview-tip {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0;
}

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  z-index: 100;
  animation: slideUp 0.25s ease;
}

.toast.success {
  border-color: rgba(61, 154, 106, 0.4);
  color: var(--accent-hover);
}

.toast.error {
  border-color: rgba(224, 93, 93, 0.4);
  color: #f08888;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translate(-50%, 12px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .editor-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

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

@media print {
  body * {
    visibility: hidden;
  }

  .receipt, .receipt * {
    visibility: visible;
  }

  .receipt {
    position: absolute;
    left: 0;
    top: 0;
    box-shadow: none;
  }
}
