:root {
  --bg: #f6f1e8;
  --ink: #1a1a1a;
  --muted: #5c5c5c;
  --nav: #121827;
  --nav-accent: #f1b36d;
  --accent: #d76743;
  --accent-deep: #2a5d68;
  --card: #fffaf3;
  --card-strong: #ffffff;
  --border: rgba(18, 24, 39, 0.12);
  --shadow: rgba(15, 23, 42, 0.12);
  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --font-sans: "Trebuchet MS", "Gill Sans", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-sans);
  background: radial-gradient(circle at 20% 20%, #fde7cb 0%, transparent 50%),
    radial-gradient(circle at 90% 10%, #e4f0ff 0%, transparent 40%),
    radial-gradient(circle at 70% 80%, #f9d6c2 0%, transparent 50%),
    linear-gradient(120deg, #f4efe7 0%, #f9fbff 100%);
}

h1,
h2,
h3,
.brand-title {
  font-family: var(--font-display);
  margin: 0;
}

a {
  color: inherit;
}

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

.sidebar {
  width: 260px;
  background: linear-gradient(180deg, #0f1724 0%, #141d2f 100%);
  color: #f8f1e8;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, #f3b16a, #d76743);
  color: #1b1b1b;
  font-weight: 700;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  letter-spacing: 0.08em;
}

.brand-title {
  font-size: 1.3rem;
}

.brand-subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  color: rgba(248, 241, 232, 0.7);
}

.nav {
  display: grid;
  gap: 0.6rem;
}

.nav-link {
  text-decoration: none;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  color: rgba(248, 241, 232, 0.8);
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.nav-link:hover,
.nav-link.is-active {
  background: rgba(243, 177, 106, 0.15);
  border-color: rgba(243, 177, 106, 0.35);
  color: #fff4e6;
}

.sidebar-card {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.usage-link {
  text-decoration: none;
  color: inherit;
  display: block;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.usage-link:hover {
  transform: translateY(-2px);
  border-color: rgba(241, 179, 109, 0.5);
}

.usage-card {
  display: grid;
  gap: 0.6rem;
}

.usage-count {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.usage-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(248, 241, 232, 0.2);
  overflow: hidden;
}

.usage-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--nav-accent), #f6d39f);
}

.plan-card-mini {
  display: grid;
  gap: 0.5rem;
}

.plan-name {
  margin: 0;
  font-weight: 700;
}

.plan-price {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--nav-accent);
}

.sidebar-text {
  margin: 0.4rem 0 0;
  color: rgba(248, 241, 232, 0.7);
  font-size: 0.9rem;
  line-height: 1.4;
}

.user-card {
  margin-top: auto;
  padding: 1rem;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.user-label {
  margin: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(248, 241, 232, 0.6);
}

.user-email {
  margin: 0.3rem 0 0;
  font-size: 0.95rem;
}

.main {
  flex: 1;
  padding: 2.5rem clamp(1.5rem, 4vw, 3.5rem);
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.75rem;
  color: var(--accent-deep);
  margin: 0 0 0.6rem;
}

.subhead {
  margin: 0.4rem 0 0;
  color: var(--muted);
  max-width: 560px;
}

.content {
  display: grid;
  gap: 2rem;
  animation: slideIn 0.5s ease;
}

.content-grid {
  display: grid;
  gap: 1.5rem;
}

.card {
  background: var(--card);
  border-radius: 22px;
  padding: 2rem;
  border: 1px solid var(--border);
  box-shadow: 0 24px 50px var(--shadow);
  animation: liftIn 0.5s ease;
}

.soft-card {
  background: rgba(255, 255, 255, 0.72);
}

.card-title {
  margin: 0 0 0.6rem;
  font-size: 1.35rem;
}

.card-subhead {
  margin: 0 0 1.5rem;
  color: var(--muted);
}

.form-grid {
  display: grid;
  gap: 1.2rem;
}

.form-row {
  display: grid;
  gap: 1.2rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

input,
select,
textarea,
button {
  font: inherit;
}

input[type="text"],
input[type="password"],
select,
textarea {
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(18, 24, 39, 0.2);
  background: var(--card-strong);
}

input[type="file"] {
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border: 1px dashed rgba(18, 24, 39, 0.2);
  background: var(--card-strong);
}

button {
  border: none;
  background: linear-gradient(135deg, var(--accent), #f1b36d);
  color: #1c130c;
  padding: 0.85rem 1.6rem;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 14px 28px rgba(215, 103, 67, 0.25);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
  transform: translateY(-2px);
}

.ghost-button {
  text-decoration: none;
  border: 1px solid rgba(248, 241, 232, 0.3);
  color: #f8f1e8;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  background: transparent;
}

.topbar .ghost-button {
  border-color: rgba(18, 24, 39, 0.2);
  color: var(--ink);
}

.helper {
  font-size: 0.85rem;
  color: var(--muted);
}

.list {
  padding-left: 1.2rem;
  margin: 1rem 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.callout {
  margin-top: 1.5rem;
  padding: 1rem;
  border-radius: 16px;
  background: rgba(42, 93, 104, 0.08);
  border: 1px solid rgba(42, 93, 104, 0.2);
}

.callout-title {
  margin: 0;
  font-weight: 700;
}

.callout-text {
  margin: 0.4rem 0 0;
  color: var(--muted);
}

.alert {
  background: #fff2df;
  border: 1px solid rgba(215, 103, 67, 0.35);
  padding: 0.75rem 1rem;
  border-radius: 12px;
  color: #7a2f1c;
}

.alert.success {
  background: #ecf7ef;
  border-color: rgba(42, 93, 104, 0.2);
  color: #1f5a3b;
}

.alert ul {
  margin: 0.5rem 0 0 1.25rem;
}

.stats-grid {
  display: grid;
  gap: 1rem;
}

.stat-card {
  background: var(--card);
  border-radius: 18px;
  padding: 1.5rem;
  border: 1px solid var(--border);
  box-shadow: 0 16px 30px rgba(15, 23, 42, 0.1);
}

.stat-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.stat-value {
  margin: 0.5rem 0 0;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent-deep);
}

.snapshot {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
}

.snapshot-label {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.snapshot-value {
  margin: 0.3rem 0 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.stats-row {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  margin-bottom: 1.5rem;
}

.mini-stat {
  background: rgba(18, 24, 39, 0.04);
  border-radius: 14px;
  padding: 0.75rem 1rem;
  display: grid;
  gap: 0.3rem;
  border: 1px solid rgba(18, 24, 39, 0.08);
}

.mini-stat span {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.mini-stat strong {
  font-size: 1.2rem;
}

.plans-grid {
  display: grid;
  gap: 1rem;
}

.plan-card {
  background: rgba(18, 24, 39, 0.04);
  border-radius: 18px;
  padding: 1.5rem;
  border: 1px solid rgba(18, 24, 39, 0.08);
}

.plan-card.is-active {
  border-color: rgba(215, 103, 67, 0.4);
  background: rgba(215, 103, 67, 0.08);
}

.plan-badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(42, 93, 104, 0.2);
  color: var(--accent-deep);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.plan-current {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.usage-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-radius: 14px;
  background: rgba(18, 24, 39, 0.04);
  border: 1px solid rgba(18, 24, 39, 0.08);
  font-weight: 600;
}

.checkout-box {
  margin-top: 1rem;
  padding: 1.5rem;
  border-radius: 18px;
  border: 1px dashed rgba(18, 24, 39, 0.2);
  background: rgba(18, 24, 39, 0.03);
  display: flex;
  justify-content: center;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 16px;
  border: 1px solid rgba(18, 24, 39, 0.1);
  background: var(--card-strong);
}

.history-form {
  display: grid;
  gap: 1rem;
}

.history-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.history-actions .helper {
  margin: 0;
}

.history-action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.danger-button {
  background: linear-gradient(135deg, #c44e37, #f0b07d);
}

.check-cell {
  width: 80px;
}

.table-link {
  color: var(--accent-deep);
  text-decoration: none;
  font-weight: 600;
}

.table-link:hover {
  text-decoration: underline;
}

.table-muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.mapping-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.mapping-actions .ghost-button {
  border-color: rgba(18, 24, 39, 0.2);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
  font-weight: 600;
}

.tally-lists {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.tally-list {
  border: 1px solid rgba(18, 24, 39, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.7);
  padding: 0.85rem;
}

.tally-list-title {
  margin: 0;
  font-weight: 700;
  font-size: 0.95rem;
}

.tally-list-body {
  margin-top: 0.6rem;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 0.4rem;
}

.tally-list-item {
  font-size: 0.85rem;
  padding: 0.2rem 0;
  border-bottom: 1px dashed rgba(18, 24, 39, 0.08);
}

.tally-list-item:last-child {
  border-bottom: none;
}

.mapping-board {
  display: grid;
  gap: 1rem;
}

.mapping-panel {
  border: 1px solid rgba(18, 24, 39, 0.12);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.7);
  padding: 1rem;
}

.mapping-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.mapping-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.mapping-list {
  display: grid;
  gap: 0.6rem;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 0.4rem;
}

.mapping-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.5fr) minmax(160px, 1fr);
  gap: 0.75rem;
  align-items: center;
}

.mapping-source {
  font-weight: 600;
  font-size: 0.9rem;
}

.mapping-target {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  border: 1px solid rgba(18, 24, 39, 0.2);
  background: var(--card-strong);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th,
td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(18, 24, 39, 0.08);
  text-align: left;
}

th {
  background: rgba(18, 24, 39, 0.04);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.download {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.download form {
  margin: 0;
}

.download-hero {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.5rem;
  border-radius: 18px;
  border: 1px solid rgba(18, 24, 39, 0.12);
  background: rgba(255, 255, 255, 0.8);
  margin-bottom: 1.5rem;
}

.processing-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  padding: 2rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 20;
}

.processing-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  padding: 2rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 30;
}

.modal-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--card);
  border-radius: 24px;
  padding: 2rem;
  border: 1px solid var(--border);
  box-shadow: 0 30px 60px var(--shadow);
  position: relative;
  width: min(520px, 100%);
}

.modal-card.wide-card {
  width: min(640px, 100%);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: transparent;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--accent-deep);
  box-shadow: none;
}

.processing-card {
  background: var(--card);
  border-radius: 24px;
  padding: 2.5rem;
  border: 1px solid var(--border);
  box-shadow: 0 30px 60px var(--shadow);
  width: min(520px, 100%);
  text-align: center;
}

.progress-track {
  margin: 1.5rem 0 1rem;
  height: 8px;
  background: rgba(18, 24, 39, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #f1b36d);
  transition: width 0.25s ease;
}

.progress-bar.is-animated {
  width: 40%;
  animation: progressSlide 1.8s ease-in-out infinite;
}

.processing-meta {
  margin-top: 0.5rem;
  display: grid;
  gap: 0.25rem;
}

.processing-count {
  margin: 0;
  font-weight: 600;
}

.processing-remaining {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.processing-current {
  margin: 0;
  font-size: 0.9rem;
  color: var(--accent-deep);
}

.processing-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  max-height: 180px;
  overflow: auto;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.processing-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.processing-item.is-working {
  color: var(--accent-deep);
  font-weight: 600;
}

.processing-item.is-done {
  color: var(--accent);
}

.processing-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.processing-status {
  flex-shrink: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.processing-error {
  margin: 1rem 0 0;
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  background: #fff2df;
  border: 1px solid rgba(215, 103, 67, 0.35);
  color: #7a2f1c;
}

.processing-close {
  margin-top: 0.75rem;
  padding: 0.6rem 1.4rem;
  font-size: 0.85rem;
}

.processing-note {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.login-page {
  background: radial-gradient(circle at 20% 20%, #fde7cb 0%, transparent 50%),
    radial-gradient(circle at 90% 10%, #e4f0ff 0%, transparent 40%),
    linear-gradient(120deg, #f4efe7 0%, #f9fbff 100%);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: 24px;
  padding: 2.5rem;
  border: 1px solid var(--border);
  box-shadow: 0 30px 60px var(--shadow);
  display: grid;
  gap: 1.2rem;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes liftIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes progressSlide {
  0% {
    transform: translateX(-50%);
  }
  50% {
    transform: translateX(120%);
  }
  100% {
    transform: translateX(-50%);
  }
}

@media (min-width: 900px) {
  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

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

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

  .download-hero {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

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

  .plan-current {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

@media (max-width: 960px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
  }

  .nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .sidebar-card {
    display: none;
  }

  .user-card {
    margin-top: 0;
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .card {
    padding: 1.5rem;
  }
}
