:root {
  --bg: #eceff3;
  --surface: #ffffff;
  --surface-soft: #f8f9fb;
  --line: #e2e5ea;
  --ink: #2b313b;
  --muted: #7f8a98;
  --accent: #ff9f40;
  --accent-blue: #3b66f0;
  --accent-green: #1cdca8;
  --accent-pink: #ff5f9d;
  --danger: #c3424a;
  --paid: #12c98c;
  --open: #3b66f0;
  --radius-lg: 12px;
  --radius-md: 10px;
  --shadow: 0 6px 18px rgba(18, 23, 31, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Nunito Sans', 'Segoe UI', sans-serif;
}

.app-shell {
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: 8px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.page-head {
  padding: 4px 2px 12px;
}

.page-head h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2.2vw, 1.6rem);
  letter-spacing: 0.01em;
}

.page-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.dashboard-main {
  display: grid;
  gap: 12px;
}

.view {
  display: grid;
  gap: 12px;
}

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

.dashboard-card {
  padding: 14px;
  min-height: 300px;
}

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

.card h2,
.card h3 {
  margin: 0;
  font-size: 1.02rem;
}

.dots {
  border: 0;
  background: transparent;
  color: #9ca6b2;
  font-size: 1.15rem;
  line-height: 1;
  cursor: default;
}

.upload-box {
  border: 1.5px dashed #d4dae3;
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  padding: 12px;
  margin-bottom: 10px;
}

.upload-title {
  display: block;
  font-weight: 800;
  font-size: 0.92rem;
}

.upload-hint {
  display: block;
  margin-top: 4px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.84rem;
}

.upload-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.upload-action {
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.visually-hidden-file {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.btn {
  width: 100%;
  border: 0;
  border-radius: 999px;
  padding: 11px 14px;
  min-height: 44px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

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

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

.btn.primary {
  background: linear-gradient(135deg, #ff9b3d, #ff7f2f);
  color: #fff;
  margin-top: 10px;
}

.btn.secondary {
  background: linear-gradient(135deg, #1bd6a5, #23b9f8);
  color: #fff;
}

.btn.ghost {
  background: #e8edf9;
  color: #4960b8;
}

.preview h3,
.positions h3,
.payment-area h3 {
  margin: 8px 0;
  font-size: 0.93rem;
}

.preview img {
  width: 100%;
  max-height: 250px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.pdf-preview {
  background: #f6f8fc;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px;
}

.pdf-preview p {
  margin: 0;
}

.pdf-preview p:first-child {
  margin-bottom: 6px;
  color: var(--muted);
}

.pdf-preview p:last-child {
  font-weight: 700;
  word-break: break-all;
}

.result-header {
  align-items: flex-start;
}

.chip {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
  color: #2e6698;
  background: #e6f3ff;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 8px;
}

.label {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.value {
  margin: 4px 0 0;
  font-size: 1.02rem;
  font-weight: 800;
}

.positions ul,
#positionsList {
  list-style: none;
  margin: 0;
  padding: 0;
}

.position-item {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcff;
  margin-bottom: 8px;
}

.position-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.position-line small {
  color: var(--muted);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.payment-status {
  margin: 9px 0 0;
  font-weight: 800;
}

.payment-status.paid {
  color: var(--paid);
}

.payment-status.unpaid {
  color: #5268d5;
}

.snapshot-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.snapshot-ring {
  --ring-value: 0;
  width: min(220px, 100%);
  aspect-ratio: 1;
  margin: 2px auto 10px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
  background: conic-gradient(#ff9248 calc(var(--ring-value) * 1%), #2fd6a9 0 66%, #6d88ff 0);
  box-shadow: 0 10px 20px rgba(51, 93, 209, 0.18);
}

.snapshot-ring::after {
  content: '';
  position: absolute;
  inset: 22px;
  background: #fff;
  border-radius: 50%;
}

.snapshot-ring div {
  position: relative;
  z-index: 1;
  text-align: center;
}

.snapshot-ring strong {
  display: block;
  font-size: 1.35rem;
}

.snapshot-ring span {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.snapshot-stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.summary-main-card {
  padding: 14px;
}

.summary-subtitle {
  margin: 0 0 12px;
  color: var(--muted);
}

.summary-charts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.ring-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px;
  display: grid;
  place-items: center;
  background: #fbfcff;
}

.ring {
  --ring-value: 0;
  --ring-color: #2fd6a9;
  --ring-track: #e6ebf2;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  position: relative;
  background: conic-gradient(var(--ring-color) calc(var(--ring-value) * 1%), var(--ring-track) 0);
}

.ring::after {
  content: '';
  position: absolute;
  inset: 10px;
  background: #fff;
  border-radius: 50%;
}

.ring span {
  position: relative;
  z-index: 1;
  font-weight: 800;
}

.ring-paid {
  --ring-color: #20d8a2;
}

.ring-open {
  --ring-color: #4e74ef;
}

.ring-label {
  margin: 6px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 700;
}

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

.summary-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px;
}

.summary-item-paid {
  background: #effcf7;
}

.summary-item-open {
  background: #f2f5ff;
}

.summary-value {
  margin: 4px 0 0;
  font-size: 1.28rem;
  font-weight: 800;
}

.metric-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.metric-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px;
  background: #fcfdff;
}

.summary-status {
  margin: 10px 0 0;
  font-weight: 800;
}

.summary-meta {
  margin: 8px 0 10px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
}

.sticky-cta {
  position: sticky;
  bottom: 0;
  z-index: 6;
  padding-top: 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0), var(--surface) 28%);
}

.sticky-cta .btn.primary {
  margin-top: 0;
}

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

.list-card {
  padding: 12px;
}

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

.receipt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.receipt-table th,
.receipt-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
}

.receipt-table th {
  color: #5d6777;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.72rem;
  font-weight: 800;
}

.status-pill.paid {
  background: #e8fbf4;
  color: #0aa26d;
}

.status-pill.unpaid {
  background: #ebf0ff;
  color: #4663d7;
}

.activity-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.activity-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

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

.activity-main {
  min-width: 0;
}

.activity-main strong {
  display: block;
  font-size: 0.89rem;
}

.activity-main span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.activity-time {
  color: #8a96a7;
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.error-message {
  margin: 8px 0 0;
  color: var(--danger);
  font-weight: 700;
}

.status-message {
  margin: 8px 0 0;
  color: #3666c7;
  font-weight: 700;
}

.btn.selected {
  outline: 2px solid #223567;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 23, 31, 0.35);
  display: grid;
  place-items: center;
  padding: 12px;
  z-index: 100;
}

.loader-card {
  width: min(280px, 100%);
  background: #fff;
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #dfebfb;
  border-top-color: #4d78ef;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.8s linear infinite;
}

.hidden {
  display: none !important;
}

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

@media (min-width: 760px) {
  .app-shell {
    padding: 10px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr 1fr;
  }

  .upload-actions,
  .button-row,
  .summary-charts,
  .summary-grid,
  .snapshot-stats,
  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 1080px) {
  .dashboard-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .summary-bottom-grid {
    grid-template-columns: 2fr 1fr;
  }

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

@media (max-width: 760px) {
  .btn {
    min-height: 52px;
    font-size: 0.98rem;
    padding: 14px 16px;
  }

  .page-head h1 {
    font-size: 1.25rem;
  }

  .page-head p {
    font-size: 0.86rem;
  }

  .receipt-table thead {
    display: none;
  }

  .receipt-table tbody {
    display: grid;
    gap: 8px;
  }

  .receipt-table tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #fbfcff;
    padding: 8px;
  }

  .receipt-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 5px 2px;
    border-bottom: 0;
  }

  .receipt-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
    font-size: 0.75rem;
  }

  .receipt-table td[colspan] {
    display: block;
    text-align: left;
  }

  .receipt-table td[colspan]::before {
    content: none;
  }

  .status-pill {
    min-height: 28px;
  }

  .dashboard-card {
    min-height: auto;
  }
}
