*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-deep:    #0f0804;
  --bg-dark:    #1c0d01;
  --bg-mid:     #2e1a0a;
  --text:       #fff9f5;
  --text-muted: #a08070;
  --accent:     #e06f25;
  --accent-hover: #c85f1a;
  --border:     #2e1a0a;
  --success:    #2e9c5a;
  --danger:     #dc3c28;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  min-height: 100vh;
}

/* ── Centered auth layout ── */
body.centered-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-wrap {
  width: 100%;
  max-width: 420px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.logo-text {
  display: block;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

.logo-sub {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 3px;
}

.auth-card {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 32px;
}

.auth-card h1, .auth-card h2 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text);
}

.auth-hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 24px;
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.auth-footer a { color: var(--accent); text-decoration: none; }

/* ── Portal header ── */
.portal-header {
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.portal-header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.portal-logo { text-decoration: none; }
.portal-logo .logo-text { font-size: 0.95rem; }

.portal-header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.portal-customer-name {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.portal-logout {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: color 0.15s, border-color 0.15s;
}

.portal-logout:hover { color: var(--danger); border-color: var(--danger); }

/* ── Portal main content ── */
.portal-main { padding: 32px 24px; }

.portal-container {
  max-width: 860px;
  margin: 0 auto;
}

.portal-page-header {
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.portal-page-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s;
  font-family: inherit;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: none; color: var(--text-muted); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--text-muted); color: var(--text); }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ── Forms ── */
.form-group { margin-bottom: 18px; }

.form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.form-group input:focus { border-color: var(--accent); }

/* ── Alerts ── */
.alert {
  padding: 12px 16px;
  border-radius: 7px;
  font-size: 0.875rem;
  line-height: 1.5;
}

.alert-error   { background: rgba(220,60,40,0.15);  border: 1px solid rgba(220,60,40,0.4);  color: #f08070; }
.alert-success { background: rgba(46,156,90,0.15);  border: 1px solid rgba(46,156,90,0.4);  color: #3abf6e; }

/* ── Status badges ── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.badge-draft     { background: rgba(160,128,112,0.2); color: #a08070; }
.badge-sent      { background: rgba(60,100,220,0.2);  color: #6080f0; }
.badge-partial   { background: rgba(220,160,30,0.2);  color: #d0a020; }
.badge-paid      { background: rgba(46,156,90,0.2);   color: #3abf6e; }
.badge-cancelled { background: rgba(220,60,40,0.2);   color: #e06050; }
.badge-pending   { background: rgba(160,128,112,0.2); color: #a08070; }

/* ── Spinner ── */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

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

/* ── Success / error icons ── */
.success-icon, .error-icon {
  font-size: 2.5rem;
  margin-bottom: 16px;
}

.success-icon { color: var(--success); }
.error-icon   { color: var(--accent); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.7;
}

.empty-state a { color: var(--accent); text-decoration: none; }

/* ── Invoice cards ── */
.invoice-card {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.invoice-card-meta { flex: 1; min-width: 180px; }
.invoice-card-meta h3 { font-size: 0.95rem; font-weight: 700; margin-bottom: 4px; }
.invoice-card-meta p  { font-size: 0.8rem; color: var(--text-muted); }
.invoice-card-amounts { text-align: right; }
.invoice-card-amounts .total   { font-size: 1.05rem; font-weight: 700; }
.invoice-card-amounts .balance { font-size: 0.85rem; color: var(--accent); margin-top: 2px; }

/* ── Link button ── */
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
  font-family: inherit;
}

/* ── Back navigation ── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  margin-bottom: 20px;
  transition: color 0.15s;
}
.back-link:hover { color: var(--accent); }

/* ── Invoice page header ── */
.inv-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}
.inv-header h1  { font-size: 1.4rem; font-weight: 700; margin-bottom: 4px; }
.inv-header-date { font-size: 0.85rem; color: var(--text-muted); }

.inv-section       { margin-bottom: 28px; }
.inv-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ── Line items table ── */
.inv-table-wrap { overflow-x: auto; }
.inv-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.inv-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.inv-table th:not(:first-child),
.inv-table td:not(:first-child) { text-align: right; }
.inv-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: top;
}
.inv-table tbody tr:last-child td { border-bottom: none; }
.inv-item-name        { font-weight: 600; }
.inv-item-desc        { font-size: 0.8rem; color: var(--text-muted); margin-top: 3px; }

.inv-totals { border-top: 2px solid var(--border); padding-top: 4px; }
.inv-total-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 10px;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.inv-total-row.grand {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.inv-total-row.grand .total-val { color: var(--accent); }

/* ── Payment schedule cards ── */
.schedule-card {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.schedule-card.paid   { border-color: rgba(46,156,90,0.35); }
.schedule-card.overdue { border-color: rgba(220,60,40,0.35); }
.schedule-card-info   { flex: 1; min-width: 140px; }
.schedule-card-label  { font-weight: 700; font-size: 0.95rem; margin-bottom: 3px; }
.schedule-card-date   { font-size: 0.8rem; color: var(--text-muted); }
.schedule-card-date.overdue { color: #f08070; }
.schedule-card-right  { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.schedule-card-amount { font-size: 1.05rem; font-weight: 700; }
.schedule-card.paid .schedule-card-amount { color: var(--success); }
.schedule-card-paid-date { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; text-align: right; }

.paid-badge-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--success);
  background: rgba(46,156,90,0.1);
  border: 1px solid rgba(46,156,90,0.25);
  border-radius: 20px;
  padding: 4px 10px;
}

/* ── Notes ── */
.inv-notes-text {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.7;
  white-space: pre-wrap;
}

/* ── Videos ── */
.inv-videos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.inv-video-title {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
}
.inv-video-thumb { position: relative; border-radius: 8px; overflow: hidden; aspect-ratio: 16/9; background: var(--bg-mid); }
.inv-video-thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ── Paid in full banner ── */
.paid-banner {
  background: rgba(46,156,90,0.12);
  border: 1px solid rgba(46,156,90,0.35);
  border-radius: 10px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  font-weight: 700;
  color: #3abf6e;
}

/* ── Payment modal ── */
.pay-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.pay-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(3px);
}
.pay-modal-box {
  position: relative;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.pay-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.pay-modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.pay-modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
}
.pay-modal-close:hover { color: var(--danger); }
.pay-amount-row {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}
.pay-amount-row strong { color: var(--accent); font-size: 1.1rem; }
.card-element-wrap {
  background: var(--bg-mid);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.pay-error {
  color: #f08070;
  font-size: 0.85rem;
  margin-bottom: 12px;
  min-height: 20px;
}

/* ── Pay success ── */
.pay-success-content {
  text-align: center;
  padding: 16px 0 8px;
}
.pay-success-content .success-icon { font-size: 2.8rem; color: var(--success); margin-bottom: 12px; }
.pay-success-content h3 { font-size: 1.15rem; font-weight: 700; margin-bottom: 8px; }
.pay-success-content p  { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 24px; }

/* ── Mobile responsive ── */
@media (max-width: 600px) {
  .portal-header-inner { padding: 0 16px; height: 52px; }
  .portal-customer-name { display: none; }
  .portal-main { padding: 20px 14px; }
  .portal-page-header h1 { font-size: 1.2rem; }

  /* Invoice cards */
  .invoice-card { padding: 16px; gap: 12px; flex-direction: column; align-items: flex-start; }
  .invoice-card-meta { min-width: 0; }
  .invoice-card-right { width: 100%; justify-content: space-between; }

  /* Invoice detail table */
  .inv-table th, .inv-table td { padding: 8px 6px; font-size: 0.8rem; }
  .inv-table th:nth-child(3),
  .inv-table td:nth-child(3) { display: none; }
  .inv-table th:nth-child(4),
  .inv-table td:nth-child(4) { display: none; }

  /* Totals */
  .inv-total-row { padding: 6px 6px; font-size: 0.82rem; }
  .inv-total-row.grand { font-size: 0.95rem; }

  /* Schedule cards */
  .schedule-card { padding: 14px; gap: 10px; }
  .schedule-card-right { width: 100%; justify-content: space-between; }

  /* Payment modal */
  .pay-modal { padding: 10px; }
  .pay-modal-box { padding: 20px; }

  /* Videos grid */
  .inv-videos-grid { grid-template-columns: 1fr; }

  /* Notes */
  .inv-notes-text { padding: 12px; font-size: 0.82rem; }

  /* Paid banner */
  .paid-banner { padding: 12px 16px; font-size: 0.9rem; }

  /* Auth card */
  .auth-card { padding: 28px 20px; }
}
