:root {
  --ink: #241220;
  --curtain: #3c1538;
  --paper: #fbf6ec;
  --gold: #c89b4a;
  --sage: #4f7a52;
  --danger: #a83b3b;

  --paper-raised: #ffffff;
  --border: #e4dcc8;
  --text-muted: #6b5f68;
  --nav-height: 64px;
  --header-height: 56px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

/* ---------- header ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 20px;
  background: var(--curtain);
  color: var(--paper);
}

.app-header h1 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.01em;
}

/* ---------- layout ---------- */

#app-main {
  padding: 16px 16px calc(var(--nav-height) + 24px);
  max-width: 640px;
  margin: 0 auto;
  min-height: calc(100vh - var(--header-height));
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  background: var(--paper-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 16px;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 9px 12px;
  border-radius: 7px;
  cursor: pointer;
}

.tab.active {
  background: var(--curtain);
  color: var(--paper);
}

.paid-date {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--sage);
}

/* ---------- cohortes ---------- */

.cohort-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cohort-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--paper-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
  box-shadow: 0 1px 2px rgba(36, 18, 32, 0.04);
}

.cohort-card:hover { border-color: var(--gold); }

.cohort-name {
  font-weight: 600;
  font-size: 1rem;
}

.cohort-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.cohort-chevron {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--curtain);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 4px 0 16px;
  cursor: pointer;
}

.back-icon {
  width: 18px;
  height: 18px;
}

.cohort-member-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 14px;
}

.contact-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.contact-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--paper-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.contact-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.contact-name {
  font-weight: 500;
  font-size: 0.92rem;
}

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

.contact-phone {
  border: none;
  background: transparent;
  padding: 0;
  font: inherit;
  color: var(--curtain);
  font-weight: 600;
  cursor: pointer;
}

.contact-phone:active {
  opacity: 0.7;
}

.invoice-status.paid {
  background: #e5efe5;
  color: var(--sage);
}

/* ---------- dev/demo panel ---------- */

.dev-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: #fff8e6;
  border: 1px dashed var(--gold);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 18px;
  font-size: 0.78rem;
}

.dev-panel-label {
  font-weight: 600;
  color: #8a6a1f;
  white-space: nowrap;
}

.dev-panel-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.dev-btn {
  border: 1px solid var(--gold);
  background: var(--paper-raised);
  color: var(--ink);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.76rem;
  cursor: pointer;
}

.dev-btn:hover { background: #fff2d6; }
.dev-btn.active { background: var(--gold); color: #fff; border-color: var(--gold); }

/* ---------- invoice list ---------- */

.invoice-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.invoice-card {
  background: var(--paper-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 1px 2px rgba(36, 18, 32, 0.04);
}

.invoice-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.invoice-contact {
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
}

.invoice-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.invoice-amount {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--curtain);
  white-space: nowrap;
}

.invoice-status {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  width: fit-content;
}

.invoice-status.sent {
  background: #f1e6d8;
  color: #8a6a1f;
}

.invoice-status.partial {
  background: #fbe6e6;
  color: var(--danger);
}

.invoice-card-actions {
  display: flex;
  justify-content: flex-end;
}

/* ---------- buttons ---------- */

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.btn:hover { opacity: 0.9; }
.btn:active { opacity: 0.8; }

.btn-primary {
  background: var(--sage);
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
}

/* ---------- state panels (loading / error / empty) ---------- */

.state-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  padding: 48px 20px;
  color: var(--text-muted);
}

.state-error-title {
  font-weight: 700;
  color: var(--danger);
  margin: 0;
}

.state-error-message {
  margin: -6px 0 0;
  font-size: 0.85rem;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--curtain);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---------- bottom nav ---------- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  display: flex;
  background: var(--paper-raised);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.68rem;
  cursor: pointer;
}

.nav-item.active { color: var(--curtain); }

.nav-icon {
  width: 22px;
  height: 22px;
}

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(36, 18, 32, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.modal {
  background: var(--paper-raised);
  border-radius: 14px;
  padding: 22px;
  max-width: 360px;
  width: 100%;
}

.modal h2 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  color: var(--ink);
}

.modal p {
  margin: 0 0 20px;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 16px);
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 30;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.toast.err {
  background: var(--danger);
}

/* ---------- desktop layout ---------- */

@media (min-width: 860px) {
  :root { --nav-height: 100vh; }

  body { display: flex; }

  .app-header {
    position: fixed;
    left: 200px;
    right: 0;
    top: 0;
  }

  .bottom-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: auto;
    width: 200px;
    height: 100vh;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    border-top: none;
    border-right: 1px solid var(--border);
    padding: 20px 0 0;
    gap: 4px;
  }

  .nav-item {
    flex: none;
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    padding: 10px 24px;
    font-size: 0.85rem;
  }

  .nav-item.active {
    background: #f1e6d8;
  }

  #app-main {
    margin-left: 200px;
    padding-top: calc(var(--header-height) + 24px);
    padding-bottom: 40px;
    max-width: 720px;
  }

  .toast {
    left: calc(50% + 100px);
  }
}
