:root {
  --bg: #f4efe7;
  --panel: rgba(255, 252, 248, 0.82);
  --panel-strong: rgba(255, 253, 250, 0.94);
  --line: rgba(68, 59, 51, 0.12);
  --text: #171412;
  --muted: #6f655d;
  --accent: #bf4f2d;
  --accent-soft: rgba(191, 79, 45, 0.14);
  --success: #27745e;
  --shadow: 0 22px 60px rgba(77, 57, 42, 0.12);
  --radius: 26px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  position: relative;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 16%, rgba(216, 156, 123, 0.2), transparent 32%),
    radial-gradient(circle at 84% 22%, rgba(103, 148, 139, 0.16), transparent 24%),
    linear-gradient(180deg, #f9f4ed 0%, #f1e8dc 100%);
  color: var(--text);
  font-family: "Noto Sans SC", sans-serif;
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(70px);
  pointer-events: none;
  z-index: 0;
}

.orb-a {
  top: -120px;
  right: -100px;
  width: 340px;
  height: 340px;
  background: rgba(191, 79, 45, 0.14);
}

.orb-b {
  bottom: -130px;
  left: -90px;
  width: 300px;
  height: 300px;
  background: rgba(50, 119, 101, 0.14);
}

.grid-noise {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.28) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.28) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.32), transparent 92%);
  pointer-events: none;
  z-index: 0;
}

.topbar,
.shell {
  position: relative;
  z-index: 1;
}

.topbar {
  padding: 36px 40px 16px;
}

.topbar-main {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 68px);
  line-height: 0.94;
  letter-spacing: -0.04em;
}

.home-link {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(68, 59, 51, 0.1);
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  box-shadow: 0 14px 34px rgba(77, 57, 42, 0.08);
}

.panel-kicker {
  margin: 0 0 10px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.shell,
.top-grid,
.workspace {
  display: grid;
  gap: 18px;
}

.shell {
  gap: 24px;
  padding: 0 28px 28px;
}

.top-grid {
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.upload-panel,
.status-panel,
.reimbursement-panel {
  padding: 22px;
}

.muted,
.hint {
  color: var(--muted);
  line-height: 1.55;
}

.upload-grid {
  display: grid;
  gap: 12px;
}

.dropzone {
  display: grid;
  gap: 4px;
  padding: 18px;
  background: var(--panel-strong);
  border: 1px dashed rgba(191, 79, 45, 0.32);
  border-radius: 20px;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.dropzone:hover,
.dropzone.is-dragging {
  transform: translateY(-1px);
  border-color: rgba(191, 79, 45, 0.62);
  background: rgba(255, 248, 242, 0.96);
}

.dropzone-label {
  font-size: 12px;
  color: var(--muted);
}

.dropzone strong {
  font-size: 20px;
}

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

.dropzone-state {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin-top: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(23, 20, 18, 0.06);
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 600;
}

.dropzone.is-busy .dropzone-state {
  background: rgba(191, 79, 45, 0.12);
  color: var(--accent);
}

.dropzone.is-ready {
  border-color: rgba(39, 116, 94, 0.42);
  background: rgba(247, 255, 251, 0.96);
}

.dropzone.is-ready .dropzone-state {
  background: rgba(39, 116, 94, 0.12);
  color: var(--success);
}

.file-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.file-chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(23, 20, 18, 0.06);
  color: var(--muted);
  font-size: 13px;
}

.file-chip b {
  color: var(--text);
}

.action-group {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.action-group-stretch > * {
  flex: 1 1 auto;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 150ms ease, opacity 150ms ease, background 150ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

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

.primary-btn,
.export-btn {
  padding: 14px 18px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.ghost-btn {
  padding: 14px 18px;
  background: rgba(23, 20, 18, 0.06);
  color: var(--text);
}

.filename-field {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

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

.form-grid .filename-field {
  margin-top: 0;
}

.filename-field span {
  font-size: 13px;
  color: var(--muted);
}

.filename-field input {
  padding: 13px 14px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.panel-section-head h2 {
  margin: 0;
  font-size: 22px;
}

.panel-section-head .muted {
  margin: 8px 0 0;
}

.reimbursement-totals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.reimbursement-metric {
  padding: 16px 18px;
  border-radius: 20px;
  border: 1px solid rgba(68, 59, 51, 0.08);
  background: rgba(255, 255, 255, 0.76);
}

.reimbursement-metric.is-primary {
  background: linear-gradient(180deg, rgba(191, 79, 45, 0.12), rgba(255, 255, 255, 0.9));
}

.reimbursement-metric span {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.reimbursement-metric strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(24px, 2.8vw, 34px);
  line-height: 1;
  letter-spacing: -0.04em;
}

.textarea-field {
  min-height: 112px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  border-radius: 16px;
  resize: vertical;
}

.student-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  margin-bottom: 10px;
}

.student-editor-head span {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.small-btn {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
}

.student-editor {
  display: grid;
  gap: 12px;
}

.student-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid rgba(68, 59, 51, 0.08);
}

.student-row-index {
  width: 46px;
  height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: rgba(191, 79, 45, 0.1);
  color: var(--accent);
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
}

.student-row-fields {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(140px, 0.8fr);
  gap: 12px;
}

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

.student-field span {
  font-size: 12px;
  color: var(--muted);
}

.student-field input {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
}

.student-field input.is-auto-amount {
  font-weight: 700;
  color: var(--accent);
  background: rgba(191, 79, 45, 0.08);
  cursor: default;
}

.student-field input.is-auto-amount:focus {
  outline: none;
  box-shadow: none;
}

.allocation-summary {
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(23, 20, 18, 0.05);
  color: var(--text);
  line-height: 1.6;
}

.reimbursement-message {
  margin: 12px 0 0;
}

.reimbursement-message[data-tone="success"] {
  color: var(--success);
}

.reimbursement-message[data-tone="error"] {
  color: #a33a2b;
}

.reimbursement-message[data-tone="pending"] {
  color: var(--accent);
}

.status-panel .summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.summary-grid div {
  padding: 18px 16px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(68, 59, 51, 0.08);
}

.summary-grid span {
  display: block;
  font-size: 13px;
  color: var(--muted);
}

.summary-grid strong {
  display: block;
  margin-top: 10px;
  font-size: 34px;
  line-height: 1;
  word-break: break-word;
  letter-spacing: -0.04em;
}

#invoiceTotal {
  font-size: 28px;
}

.status-line {
  display: flex;
  gap: 10px;
  align-items: center;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(23, 20, 18, 0.24);
}

.status-dot.is-active {
  background: var(--accent);
  box-shadow: 0 0 0 7px rgba(191, 79, 45, 0.12);
}

.status-dot.is-success {
  background: var(--success);
  box-shadow: 0 0 0 7px rgba(39, 116, 94, 0.12);
}

.workspace {
  min-width: 0;
}

.pair-panel {
  padding: 20px;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
}

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

.panel-head h2,
.panel-head h3 {
  margin: 0;
  font-size: 28px;
}

.preview-head {
  flex: 1;
  margin-bottom: 0;
}

.compact-head {
  margin-bottom: 0;
  align-items: center;
}

.compact-head h2 {
  font-size: 24px;
}

.preview-actions {
  display: flex;
  gap: 12px;
  align-items: end;
  min-width: min(100%, 420px);
}

.preview-file-field {
  flex: 1 1 240px;
  margin-top: 0;
}

.export-btn {
  min-width: 144px;
  min-height: 50px;
  padding: 14px 18px;
  margin-top: 0;
  flex: 0 0 auto;
}

.pair-list {
  display: grid;
  gap: 18px;
  min-height: 420px;
  max-height: none;
  overflow: auto;
  padding-right: 6px;
}

.pair-card {
  display: grid;
  gap: 16px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(68, 59, 51, 0.1);
  border-radius: 28px;
}

.pair-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.pair-meta-left,
.pair-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pair-index {
  min-width: 62px;
  height: 62px;
  padding: 0 16px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: rgba(23, 20, 18, 0.08);
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 22px;
}

.pair-copy strong {
  display: block;
  font-size: 18px;
}

.pair-copy span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.pair-used-orders {
  max-width: 720px;
  line-height: 1.5;
  word-break: break-word;
}

.layout-reset {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(23, 20, 18, 0.06);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.layout-editor {
  position: relative;
  border-radius: 26px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(246, 239, 231, 0.88));
  border: 1px solid rgba(68, 59, 51, 0.08);
  padding: 12px;
}

.layout-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 842 / 595;
  border-radius: 20px;
  background: #f8f3eb;
  touch-action: none;
  cursor: grab;
}

.layout-canvas.is-dragging {
  cursor: grabbing;
}

.layout-legend {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.pair-tag {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(23, 20, 18, 0.06);
  font-size: 13px;
  color: var(--muted);
}

.pair-tag.matched {
  background: rgba(39, 116, 94, 0.12);
  color: var(--success);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 1px dashed rgba(68, 59, 51, 0.14);
  border-radius: 24px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.32);
}

.preview-empty {
  min-height: 480px;
  font-size: 18px;
}

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

  .reimbursement-totals,
  .form-grid,
  .status-panel .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .preview-toolbar {
    display: grid;
  }

  .preview-actions {
    min-width: 0;
  }
}

@media (max-width: 760px) {
  .topbar {
    padding: 28px 18px 14px;
  }

  .topbar-main {
    display: grid;
    gap: 14px;
  }

  .shell {
    padding: 0 12px 18px;
  }

  .action-group {
    flex-direction: column;
  }

  .summary-grid strong {
    font-size: 28px;
  }

  .reimbursement-totals,
  .form-grid,
  .student-editor-head,
  .student-row,
  .student-row-fields,
  .status-panel .summary-grid,
  .preview-actions {
    grid-template-columns: 1fr;
  }

  .preview-actions {
    display: grid;
  }

  .export-btn {
    width: 100%;
  }

  .pair-meta,
  .pair-meta-left,
  .pair-actions {
    align-items: stretch;
  }

  .pair-actions {
    width: 100%;
    justify-content: space-between;
  }
}
