/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg:         #f5f7fa;
  --color-surface:    #ffffff;
  --color-border:     #e2e8f0;
  --color-primary:    #2563eb;
  --color-primary-h:  #1d4ed8;
  --color-secondary:  #64748b;
  --color-success:    #16a34a;
  --color-error:      #dc2626;
  --color-text:       #1e293b;
  --color-muted:      #64748b;
  --radius:           10px;
  --shadow:           0 1px 4px rgba(0,0,0,.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.header { background: var(--color-surface); border-bottom: 1px solid var(--color-border); }
.header-inner {
  max-width: 900px; margin: 0 auto; padding: 1rem 1.5rem;
  display: flex; align-items: baseline; gap: 1rem;
}
.logo { font-size: 1.4rem; font-weight: 700; color: var(--color-primary); }
.tagline { font-size: .85rem; color: var(--color-muted); }

/* ── Main layout ──────────────────────────────────────────────────────────── */
.main { flex: 1; max-width: 900px; width: 100%; margin: 0 auto; padding: 2rem 1.5rem; }

/* ── Hero ─────────────────────────────────────────────────────────────────── */
.hero { margin-bottom: 2rem; }
.hero h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: .5rem; }
.hero p { color: var(--color-muted); max-width: 560px; }

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
}

/* ── Customer section ─────────────────────────────────────────────────────── */
.customer-section { margin-bottom: 2rem; }
.customer-section label { display: block; font-weight: 600; margin-bottom: .5rem; }
.input-row { display: flex; gap: .75rem; flex-wrap: wrap; }
.input-row input {
  flex: 1; min-width: 200px; padding: .5rem .75rem;
  border: 1px solid var(--color-border); border-radius: 6px;
  font-size: 1rem; outline: none;
  transition: border-color .15s;
}
.input-row input:focus { border-color: var(--color-primary); }

/* ── Integrations ─────────────────────────────────────────────────────────── */
.integrations h2 { font-size: 1.2rem; font-weight: 600; margin-bottom: 1rem; }
.integration-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.integration-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: .75rem;
  transition: box-shadow .15s;
}
.integration-card.connected         { cursor: pointer; }
.integration-card.connected:hover   { border-color: #94a3b8; box-shadow: 0 4px 16px rgba(0,0,0,.1); }
.integration-card.selected          { border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12), var(--shadow); }
/* /connect/<provider> landing: the card the user came to connect */
.integration-card.attention         { border-color: var(--color-primary); box-shadow: 0 0 0 4px rgba(37,99,235,.28), var(--shadow); }
.connect-hint  { font-size: .85rem; font-weight: 600; color: var(--color-primary); margin: .35rem 0 .6rem; }
.landing-hero .login-context { margin-top: .75rem; font-weight: 600; color: var(--color-text); }

.integration-header { display: flex; align-items: center; gap: .75rem; }
.integration-logo { width: 40px; height: 40px; object-fit: contain; }
.integration-header h3 { font-size: 1rem; font-weight: 600; }
.integration-desc { font-size: .875rem; color: var(--color-muted); flex: 1; }
.integration-footer { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; font-size: .7rem; font-weight: 600;
  padding: .15rem .45rem; border-radius: 4px; text-transform: uppercase; letter-spacing: .04em;
}
.badge-sandbox { background: #fef9c3; color: #854d0e; }
.badge-live    { background: #dcfce7; color: #166534; }

/* ── Store subdomain input (Shopify) ──────────────────────────────────────── */
.store-input-row {
  display: flex; align-items: center;
  border: 1px solid var(--color-border); border-radius: 6px;
  overflow: hidden; font-size: .875rem;
}
.store-input-row input {
  flex: 1; min-width: 0; padding: .4rem .6rem;
  border: none; outline: none; font-size: .875rem;
}
.store-input-row input:focus { box-shadow: inset 0 0 0 2px var(--color-primary); }
.store-input-suffix {
  padding: .4rem .6rem; background: var(--color-bg);
  color: var(--color-muted); white-space: nowrap;
  border-left: 1px solid var(--color-border);
}

/* ── Status indicator ─────────────────────────────────────────────────────── */
.status-indicator { display: flex; align-items: center; gap: .35rem; font-size: .8rem; color: var(--color-muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-disconnected { background: #94a3b8; }
.dot-connected { background: var(--color-success); }
.dot-loading { background: #f59e0b; animation: pulse 1s infinite; }
.dot-warning { background: var(--color-error); }
/* Reconnect needed: status gets its own row, Reconnect + Disconnect sit together on the right */
.integration-footer:has(.reconnect-btn) .status-indicator { flex-basis: 100%; }
.integration-footer .reconnect-btn { margin-left: auto; }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  padding: .5rem 1rem; border: none; border-radius: 6px;
  font-size: .9rem; font-weight: 600; cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
a.btn { display: inline-block; text-align: center; text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--color-primary-h); }
.btn-secondary { background: var(--color-border); color: var(--color-text); }
.btn-secondary:not(:disabled):hover { background: #cbd5e1; }
.btn-danger { background: var(--color-error); color: #fff; }
.btn-danger:not(:disabled):hover { background: #b91c1c; }

/* ── Toast notifications ──────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: .5rem; z-index: 999; }
.toast {
  background: var(--color-text); color: #fff;
  padding: .75rem 1.25rem; border-radius: 8px;
  font-size: .875rem; box-shadow: 0 4px 12px rgba(0,0,0,.2);
  animation: slideIn .2s ease-out;
  max-width: 320px;
}
.toast.success { background: var(--color-success); }
.toast.error   { background: var(--color-error); }

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

/* ── QuickBooks Explorer ──────────────────────────────────────────────────── */
.qb-explorer { margin-top: 2.5rem; }

.qb-explorer-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.qb-explorer-header h2 { font-size: 1.2rem; font-weight: 600; }

.qb-panels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.qb-section-divider {
  grid-column: 1 / -1;
  font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--color-muted);
  padding: .5rem 0 .25rem;
  border-bottom: 1px solid var(--color-border);
  margin-top: .5rem;
}
.qb-section-divider:first-child { margin-top: 0; }

.qb-panel { overflow: hidden; }
.qb-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: .6rem;
}
.qb-panel-title { font-weight: 600; font-size: .95rem; }
.qb-panel-meta  { font-size: .75rem; color: var(--color-muted); }

.qb-panel-body {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: .78rem; line-height: 1.55;
  background: #f8fafc; border-radius: 6px;
  padding: .875rem; overflow: auto; max-height: 320px;
  color: var(--color-text); white-space: pre; margin: 0;
  border: 1px solid var(--color-border);
}

.qb-loading { color: var(--color-muted); font-style: italic; font-family: inherit; }
.qb-error   { color: var(--color-error);  font-family: inherit; }

.qb-lookup {
  display: flex; flex-direction: column; gap: .6rem;
  margin-top: .5rem;
}
.qb-lookup-label { font-size: .8rem; font-weight: 600; color: var(--color-muted); text-transform: uppercase; letter-spacing: .05em; }
.qb-lookup-result { margin-top: .25rem; max-height: 240px; }

.qb-select {
  padding: .5rem .6rem; border: 1px solid var(--color-border); border-radius: 6px;
  font-size: .9rem; background: var(--color-surface); outline: none; cursor: pointer;
}
.qb-select:focus { border-color: var(--color-primary); }

.btn-sm { padding: .3rem .65rem; font-size: .8rem; }

/* ── JSON syntax highlighting ─────────────────────────────────────────────── */
.jk { color: #2563eb; font-weight: 600; }
.js { color: #16a34a; }
.jn { color: #d97706; }
.jb { color: #7c3aed; }
.jz { color: #94a3b8; font-style: italic; }

/* ── GA property ID row (inside explorer header) ─────────────────────────── */
.ga-property-row { display: flex; gap: .5rem; align-items: center; }
.ga-property-row input {
  padding: .3rem .65rem; width: 190px;
  border: 1px solid var(--color-border); border-radius: 6px;
  font-size: .875rem; outline: none;
}
.ga-property-row input:focus { border-color: var(--color-primary); }

/* ── Landing page ─────────────────────────────────────────────────────────── */
.landing-page {
  display: flex;
  align-items: center;
  justify-content: center;
  /* Leaves room for header + main padding + the two-line footer, so the legal/support links
     show without scrolling on the sign-in page. */
  min-height: calc(100vh - 220px);
}

.landing-card {
  width: 100%;
  max-width: 480px;
  padding: 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.landing-hero h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: .5rem; }
.landing-hero p  { color: var(--color-muted); font-size: .95rem; line-height: 1.55; }

/* ── Org selector ─────────────────────────────────────────────────────────── */
.org-selector-group { display: flex; flex-direction: column; gap: .6rem; }
.org-selector-label { font-weight: 600; font-size: .875rem; }

.org-select-row { display: flex; gap: .5rem; }

.org-select {
  flex: 1;
  padding: .55rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: .95rem;
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  cursor: pointer;
  transition: border-color .15s;
}
.org-select:focus    { border-color: var(--color-primary); }
.org-select:disabled { opacity: .55; cursor: not-allowed; }

.btn-link {
  background: none;
  border: none;
  color: var(--color-primary);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  text-align: left;
  transition: color .15s;
}
.btn-link:hover { color: var(--color-primary-h); text-decoration: underline; }

/* ── Add org form ─────────────────────────────────────────────────────────── */
.add-org-form {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding-top: .25rem;
  border-top: 1px solid var(--color-border);
}

/* ── Org bar (dashboard header) ───────────────────────────────────────────── */
.org-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: .75rem 1.25rem;
  margin-bottom: 1.75rem;
  box-shadow: var(--shadow);
}

.org-bar-info { display: flex; align-items: baseline; gap: .6rem; }
.org-bar-label { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--color-muted); }
.org-bar-id    { font-size: 1rem; font-weight: 700; color: var(--color-text); }

/* ── Schedule row (inside integration card) ───────────────────────────────── */
.schedule-row {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding-top: .6rem;
  border-top: 1px solid var(--color-border);
}
.schedule-label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.schedule-select {
  flex: 1;
  padding: .3rem .5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: .8rem;
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  cursor: pointer;
  transition: border-color .15s;
}
.schedule-select:focus { border-color: var(--color-primary); }

/* ── Utilities ────────────────────────────────────────────────────────────── */
/* ── Sign in / signed-in user ─────────────────────────────────────────────── */
.header-user { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.header-user-email { font-size: .85rem; color: var(--color-muted); }
.login-form { display: flex; flex-direction: column; gap: .6rem; }
.login-form input {
  padding: .55rem .75rem; border: 1px solid var(--color-border); border-radius: 6px;
  font-size: .95rem; outline: none; transition: border-color .15s;
}
.login-form input:focus { border-color: var(--color-primary); }
.login-form .btn-primary { margin-top: .5rem; }
.login-notice { font-size: .85rem; color: var(--color-success); }

/* ── Customer access (staff) ──────────────────────────────────────────────── */
.access-panel { margin-bottom: 1.75rem; display: flex; flex-direction: column; gap: .75rem; }
.access-panel h2 { font-size: 1.05rem; font-weight: 600; }
.access-desc { font-size: .85rem; color: var(--color-muted); }
.access-list { list-style: none; display: flex; flex-direction: column; gap: .4rem; }
.access-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; font-size: .9rem; }
.access-empty { font-size: .85rem; color: var(--color-muted); }

.hidden { display: none !important; }
.error-text { color: var(--color-error); font-size: .85rem; margin-top: .35rem; }

/* ── Footer ───────────────────────────────────────────────────────────────── */
.footer { text-align: center; padding: 1.5rem; font-size: .8rem; color: var(--color-muted); border-top: 1px solid var(--color-border); }

/* ── Footer links (support contact + legal pages, shown on every page) ───── */
.footer a { color: inherit; text-decoration: underline; }
.footer a:hover { color: var(--color-primary); }
.footer-sep { margin: 0 .4rem; color: var(--color-border); }

/* Header logo as a link back to the portal (legal + disconnect pages) */
.logo-link { text-decoration: none; }

/* ── Legal pages (/privacy, /terms) ──────────────────────────────────────── */
.legal { max-width: 760px; margin: 0 auto; padding: 2rem 2.25rem; line-height: 1.6; }
.legal h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.25; }
.legal h2 { font-size: 1.15rem; font-weight: 700; margin: 2rem 0 .6rem; scroll-margin-top: 1rem; }
.legal p { margin-bottom: .9rem; }
.legal ul { margin: 0 0 .9rem 1.25rem; }
.legal li { margin-bottom: .45rem; }
.legal a { color: var(--color-primary); overflow-wrap: anywhere; }
.legal-meta { color: var(--color-muted); font-size: .9rem; margin-bottom: 1.5rem; }
.legal-table-wrap { overflow-x: auto; margin-bottom: 1rem; }
.legal table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.legal th, .legal td { text-align: left; vertical-align: top; padding: .55rem .65rem; border: 1px solid var(--color-border); }
.legal th { background: var(--color-bg); font-weight: 600; }

@media (max-width: 600px) {
  .legal { padding: 1.25rem 1rem; }
  .legal h1 { font-size: 1.45rem; }
  /* Fixed layout so the 3-column table fits the screen and wraps instead of scrolling sideways */
  .legal table { font-size: .8rem; table-layout: fixed; }
  .legal th, .legal td { padding: .45rem .4rem; overflow-wrap: anywhere; hyphens: auto; }
}
