/* Site Header (portal pages) */
.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Portal Layout */
.portal-main {
  min-height: calc(100vh - 72px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6) var(--space-4);
}

.dashboard-main {
  min-height: calc(100vh - 72px);
  padding: var(--space-6) var(--space-4);
}

/* Header */
.header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
}

.dashboard-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.dashboard-header__firm {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-weight: 500;
}

/* Login Card */
.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  width: 100%;
  max-width: 420px;
}

.login-card__header {
  margin-bottom: var(--space-6);
}

.login-card__title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 400;
  margin-bottom: var(--space-1);
}

.login-card__subtitle {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.login-form .form-group {
  margin-bottom: var(--space-4);
}

.btn--full {
  width: 100%;
  justify-content: center;
  margin-top: var(--space-2);
}

.login-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  margin-bottom: var(--space-3);
}

.login-success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  font-size: 13px;
  margin-bottom: var(--space-3);
}

[data-theme="dark"] .login-error {
  background: #450a0a;
  color: #fca5a5;
  border-color: #7f1d1d;
}

.login-card__help {
  text-align: center;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-4);
}

/* Dashboard */
.dashboard-welcome {
  margin-bottom: var(--space-6);
}

.dashboard-welcome__heading {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 400;
}

.dashboard-welcome__sub {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
}

/* Forms Grid */
.forms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

.forms-loading,
.forms-empty {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  grid-column: 1 / -1;
  padding: var(--space-8) 0;
  text-align: center;
}

/* Form Card */
.form-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s, border-color 0.2s;
  cursor: pointer;
  overflow: hidden;
}

.form-card:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  border-color: var(--color-accent);
}

/* Thumbnail */
.form-card__thumb {
  width: 100%;
  height: 180px;
  overflow: hidden;
  background: var(--color-bg);
  position: relative;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.form-card__thumb-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: 400%;
  height: 720px;
  border: none;
  transform: scale(0.25);
  transform-origin: top left;
  pointer-events: none;
}

.form-card__thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.form-card__body {
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.form-card__name {
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.3;
}

.form-card__meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* Status badges */
.form-card__status,
.form-panel__status {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.status--draft { background: #f3f4f6; color: #6b7280; }
.status--review { background: #fef9c3; color: #854d0e; }
.status--live { background: #dcfce7; color: #166534; }

[data-theme="dark"] .status--draft { background: #1f2937; color: #9ca3af; }
[data-theme="dark"] .status--review { background: #422006; color: #fde047; }
[data-theme="dark"] .status--live { background: #052e16; color: #4ade80; }

/* Form Panel */
.form-panel__header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}

.form-panel__back {
  background: none;
  border: none;
  color: var(--color-accent);
  cursor: pointer;
  font-size: var(--text-sm);
  padding: 0;
}

.form-panel__title {
  font-size: var(--text-xl);
  font-weight: 600;
  flex: 1;
}

/* Tabs */
.form-panel__tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-5);
}

.panel-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.panel-tab--active {
  color: var(--color-text);
  border-bottom-color: var(--color-accent);
}

/* Preview iframe */
.form-preview {
  width: 100%;
  height: 70vh;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

/* Embed */
.embed-instructions {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
}

.embed-code-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
}

.embed-code {
  font-family: monospace;
  font-size: var(--text-sm);
  flex: 1;
  word-break: break-all;
  color: var(--color-text);
}

/* Metrics */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.metric-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.metric-card__value {
  font-size: var(--text-3xl);
  font-weight: 700;
  line-height: 1;
}

.metric-card__label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metrics-note {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* User Menu */
.user-menu {
  position: relative;
}

.user-menu__trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-1) var(--space-3) var(--space-1) var(--space-2);
  cursor: pointer;
  color: var(--color-text);
  font-size: var(--text-sm);
  transition: background 0.15s;
}

.user-menu__trigger:hover {
  background: var(--color-surface);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  flex-shrink: 0;
}

.user-menu__name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu__dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 50;
  overflow: hidden;
}

.user-menu__email {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  word-break: break-all;
}

.user-menu__divider {
  height: 1px;
  background: var(--color-border);
}

.user-menu__item {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}

.user-menu__item:hover {
  background: var(--color-bg);
}

.user-menu__item--danger {
  color: #dc2626;
}

/* Settings */
.settings-header {
  margin-bottom: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--space-5);
}

.settings-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.settings-card__title {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-5);
}

.settings-feedback {
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  margin-bottom: var(--space-3);
}

.settings-feedback--success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.settings-feedback--error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

[data-theme="dark"] .settings-feedback--success {
  background: #052e16;
  color: #4ade80;
  border-color: #166534;
}

[data-theme="dark"] .settings-feedback--error {
  background: #450a0a;
  color: #fca5a5;
  border-color: #7f1d1d;
}

/* Team section */
.team-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}
.team-member {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px 16px;
}

/* Field Editor */
.field-editor {
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
}

.fe-wrap {
  padding: var(--space-5);
}

.fe-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
}

.fe-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.fe-loading,
.fe-empty {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding: var(--space-4) 0;
  text-align: center;
}

.fe-section {
  margin-bottom: var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.fe-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.fe-section-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
}

.fe-field-list {
  padding: var(--space-2) 0;
}

.fe-empty-section {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: var(--space-3) var(--space-4);
  text-align: center;
}

.fe-field-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  font-size: var(--text-sm);
}

.fe-field-row:last-child { border-bottom: none; }

.fe-field-type-select {
  font-size: var(--text-xs);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  color: var(--color-text-muted);
  flex-shrink: 0;
  width: 90px;
  cursor: pointer;
}

.fe-field-label-input {
  flex: 1;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  min-width: 0;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.fe-field-label-input:hover { border-color: var(--color-border); background: var(--color-bg); }
.fe-field-label-input:focus { outline: none; border-color: var(--color-primary); background: var(--color-surface); }

.fe-field-name {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-family: monospace;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

.fe-req-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
}

.fe-req-toggle input { width: 14px; height: 14px; accent-color: var(--color-primary); }

.fe-delete-btn {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
  flex-shrink: 0;
  transition: color 0.15s;
}
.fe-delete-btn:hover { color: #dc2626; }

/* Admin */
.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
  gap: var(--space-3);
}

.client-row {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-3);
  overflow: hidden;
}

.client-row__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  gap: var(--space-3);
  flex-wrap: wrap;
}

.client-row__info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.client-row__name {
  font-weight: 600;
  font-size: var(--text-base);
}

.client-row__contact {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.client-row__forms {
  border-top: 1px solid var(--color-border);
  padding: var(--space-4) var(--space-5);
}

.client-forms {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  gap: var(--space-3);
  flex-wrap: wrap;
}

.form-row__info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.form-row__name {
  font-weight: 500;
  font-size: var(--text-sm);
}

.form-row__jotform {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.form-row__status {
  font-size: var(--text-sm);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
}

/* Modal */
.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.modal__card {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  width: 100%;
  max-width: 480px;
  z-index: 1;
}

.modal__title {
  font-size: var(--text-xl);
  font-weight: 600;
  margin-bottom: var(--space-5);
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
}

.modal-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  margin-bottom: var(--space-3);
}

[data-theme="dark"] .modal-error {
  background: #450a0a;
  color: #fca5a5;
  border-color: #7f1d1d;
}

/* ── Billing ── */
.billing-plan {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.billing-plan__name {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-weight: 500;
  margin-bottom: var(--space-1);
}

.billing-plan__amount {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-text);
}

.billing-plan__amount span {
  font-size: var(--text-sm);
  font-weight: 400;
  color: var(--color-text-muted);
}

.billing-plan__renews {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.billing-empty {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  padding: var(--space-6) 0;
}

.billing-invoices__heading {
  font-size: var(--text-base);
  font-weight: 600;
  margin-bottom: var(--space-3);
}

.billing-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.billing-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.billing-invoice-row td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
}

.billing-invoice-link {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
}

.billing-invoice-link:hover { text-decoration: underline; }

.billing-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}

.billing-badge--paid { background: #dcfce7; color: #166534; }
.billing-badge--open { background: #fef9c3; color: #854d0e; }
.billing-badge--void,
.billing-badge--uncollectible { background: #f3f4f6; color: #6b7280; }

[data-theme="dark"] .billing-badge--paid { background: #14532d; color: #86efac; }

/* ── Integrations section ──────────────────────────────────────────────────── */

.integrations-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  max-width: 520px;
}

.integrations-select,
.integrations-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-family: var(--font-body);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

.integrations-input {
  background-image: none;
  padding-right: 12px;
  cursor: text;
}

.integrations-select:focus,
.integrations-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 15%, transparent);
}

.integrations-hint {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 6px;
}

.integrations-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
}

.integrations-status--connected {
  color: #166534;
}

[data-theme="dark"] .integrations-status--connected {
  color: #86efac;
}

.integrations-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-border);
  flex-shrink: 0;
}

.integrations-dot--connected {
  background: #22c55e;
}

.integrations-save-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.integrations-feedback {
  font-size: var(--text-sm);
}

.integrations-feedback--success { color: #166534; }
.integrations-feedback--error   { color: var(--color-error, #dc2626); }

[data-theme="dark"] .integrations-feedback--success { color: #86efac; }
[data-theme="dark"] .billing-badge--open { background: #422006; color: #fde68a; }
