/* JAWANDA Marketing Dashboard — standalone frontend shell (login/forbidden/dashboard).
   This page is NOT rendered inside wp-admin or a theme, so unlike admin.css it needs its
   own base reset and re-declares the same --jmd-* tokens at the body level (admin.css
   only scopes them under .jmd-wrap, which the sidebar/topbar/login card sit outside of).
   No external fonts/icons/CDN — everything here is plain CSS + inline SVG, so there is
   nothing extra to fetch or that can fail to load.

   2026-09 Phase 2 UI round: rebuilt from a top-nav bar into a fixed left-sidebar layout
   (dark navy, orange active state) matching the approved reference design — see
   docs/known-limitations.md for the two places the reference showed data this read-only
   API cannot actually provide (live campaign status, per-service connection latency) and
   how those were honestly adapted instead of faked. */

:root {
  color-scheme: light;
}

body.jmd-fe {
  --jmd-navy: #1b2a4a;
  --jmd-navy-light: #2c4270;
  --jmd-navy-deep: #101a30;
  --jmd-orange: #e8720c;
  --jmd-orange-light: #fdeee0;
  --jmd-orange-soft: #f59440;
  --jmd-green: #2e7d32;
  --jmd-green-light: #e7f3e8;
  --jmd-red: #c0392b;
  --jmd-red-light: #fbeae8;
  --jmd-amber: #b45309;
  --jmd-amber-light: #fef3e2;
  --jmd-grey: #6b7280;
  --jmd-grey-light: #98a1ae;
  --jmd-border: #e2e5ea;
  --jmd-bg: #f2f3f6;
  --jmd-sidebar-width: 260px;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  /* Thai tone marks/vowels stack above and below the consonant line — a Latin-tuned
     1.4-1.5 line-height clips or crowds them. 1.65 gives Thai body text room without
     making the (much shorter) English strings look sparse. */
  line-height: 1.65;
  color: #1d2327;
  background: var(--jmd-bg);
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}
body.jmd-fe *,
body.jmd-fe *::before,
body.jmd-fe *::after {
  box-sizing: inherit;
}
body.jmd-fe button {
  font-family: inherit;
}

/* ---------------- Login / Forbidden pages: split-screen ---------------- */

.jmd-fe-auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.jmd-fe-auth-brand-panel {
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, var(--jmd-navy) 0%, var(--jmd-navy-deep) 70%, #0b1120 100%);
  color: #fff;
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
}
.jmd-fe-auth-brand-panel::before,
.jmd-fe-auth-brand-panel::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(2px);
  pointer-events: none;
  z-index: 0;
}
.jmd-fe-auth-brand-panel::before {
  width: 620px;
  height: 620px;
  top: -220px;
  right: -260px;
  background: radial-gradient(circle at 30% 30%, rgba(232, 114, 12, 0.4), rgba(232, 114, 12, 0) 70%);
}
.jmd-fe-auth-brand-panel::after {
  width: 520px;
  height: 520px;
  bottom: -240px;
  left: -200px;
  background: radial-gradient(circle at 60% 60%, rgba(44, 66, 112, 0.7), rgba(44, 66, 112, 0) 70%);
}
.jmd-fe-auth-brand-panel > * {
  position: relative;
  z-index: 1;
}

.jmd-fe-auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.jmd-fe-auth-brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--jmd-orange);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 18px;
  flex: none;
}
.jmd-fe-auth-brand-text {
  font-weight: 800;
  letter-spacing: 0.03em;
  font-size: 16px;
  line-height: 1.3;
}
.jmd-fe-auth-brand-text small {
  display: block;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.65);
}

.jmd-fe-auth-tagline-wrap {
  margin-top: auto;
  margin-bottom: auto;
  max-width: 480px;
}
.jmd-fe-auth-tagline-rule {
  width: 56px;
  height: 3px;
  background: var(--jmd-orange);
  margin-bottom: 24px;
}
.jmd-fe-auth-tagline {
  font-size: 34px;
  line-height: 1.3;
  font-weight: 800;
  margin: 0 0 16px;
}
.jmd-fe-auth-tagline-sub {
  font-size: 14px;
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.75);
  margin: 0;
  max-width: 420px;
}

.jmd-fe-auth-footer {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
}

.jmd-fe-auth-form-panel {
  display: flex;
  flex-direction: column;
  padding: 32px 56px;
  background: var(--jmd-bg);
  position: relative;
}

.jmd-fe-lang-toggle {
  align-self: flex-end;
  display: inline-flex;
  border: 1px solid var(--jmd-border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.jmd-fe-lang-toggle button {
  border: none;
  background: #fff;
  color: var(--jmd-grey);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  cursor: pointer;
}
.jmd-fe-lang-toggle button.is-active {
  background: var(--jmd-navy);
  color: #fff;
}

.jmd-fe-auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  margin: auto;
}

.jmd-fe-auth-title {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 800;
  color: var(--jmd-navy);
}

.jmd-fe-auth-subtitle {
  margin: 0 0 24px;
  color: var(--jmd-grey);
  font-size: 13px;
  line-height: 1.6;
}

.jmd-fe-auth-error {
  background: var(--jmd-red-light);
  border-left: 3px solid var(--jmd-red);
  color: #7a241c;
  padding: 10px 12px;
  border-radius: 4px;
  margin: 0 0 18px;
  font-size: 13px;
}

.jmd-fe-auth-hint {
  margin-top: 20px;
  text-align: center;
  font-size: 12px;
  color: var(--jmd-grey-light);
}

/* wp_login_form() output — restyled to match the card, not overridden structurally */
.jmd-fe-auth-card #jmd-fe-loginform p {
  margin: 0 0 16px;
}
.jmd-fe-auth-card #jmd-fe-loginform label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--jmd-navy);
}
.jmd-fe-auth-card #jmd-fe-loginform input[type="text"],
.jmd-fe-auth-card #jmd-fe-loginform input[type="password"] {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--jmd-border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.jmd-fe-auth-card #jmd-fe-loginform input[type="text"]:focus,
.jmd-fe-auth-card #jmd-fe-loginform input[type="password"]:focus {
  outline: none;
  border-color: var(--jmd-orange);
  box-shadow: 0 0 0 3px var(--jmd-orange-light);
}
.jmd-fe-password-field {
  position: relative;
}
.jmd-fe-password-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--jmd-grey);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 6px;
}
.jmd-fe-auth-card #jmd-fe-loginform .login-remember label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 400;
}
.jmd-fe-auth-card #jmd-fe-loginform .button {
  width: 100%;
  background: var(--jmd-orange);
  border: none;
  color: #fff;
  padding: 13px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.jmd-fe-auth-card #jmd-fe-loginform .button:hover {
  opacity: 0.92;
}

.jmd-fe-forbidden-panel {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.jmd-fe-forbidden-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(4, 8, 20, 0.12);
  padding: 40px;
  max-width: 420px;
  text-align: center;
}

/* ---------------- Dashboard shell: fixed sidebar + main ---------------- */

.jmd-shell {
  display: flex;
  min-height: 100vh;
  align-items: flex-start;
}

.jmd-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: var(--jmd-sidebar-width);
  flex: none;
  background: var(--jmd-navy-deep);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.jmd-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 12px;
}
.jmd-sidebar-brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--jmd-orange);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  flex: none;
}
.jmd-sidebar-brand-text {
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.03em;
  line-height: 1.35;
}
.jmd-sidebar-brand-text small {
  display: block;
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.55);
}

.jmd-sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 14px;
}

.jmd-sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: 13px;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  padding: 12px 14px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.15s ease, color 0.15s ease;
}
.jmd-sidebar-nav-link svg {
  flex: none;
  width: 18px;
  height: 18px;
}
.jmd-sidebar-nav-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
}
.jmd-sidebar-nav-link.is-active {
  color: #fff;
  background: var(--jmd-orange);
  box-shadow: 0 2px 8px rgba(232, 114, 12, 0.35);
}

.jmd-sidebar-footer {
  margin-top: auto;
  padding: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.jmd-sidebar-health {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.55);
  margin-bottom: 8px;
  text-transform: uppercase;
}
.jmd-sidebar-health-value {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
  color: var(--jmd-green-light);
}
.jmd-sidebar-health-value::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
}
.jmd-sidebar-health.is-error .jmd-sidebar-health-value {
  color: #fecaca;
}
.jmd-sidebar-health.is-error .jmd-sidebar-health-value::before {
  background: var(--jmd-red);
}
.jmd-sidebar-health-bar {
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
  margin-bottom: 14px;
}
.jmd-sidebar-health-bar-fill {
  height: 100%;
  width: 100%;
  background: #4ade80;
}
.jmd-sidebar-health.is-error .jmd-sidebar-health-bar-fill {
  background: var(--jmd-red);
}

.jmd-sidebar-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}
.jmd-sidebar-logout:hover {
  color: #fff;
}
.jmd-sidebar-logout svg {
  width: 16px;
  height: 16px;
}

.jmd-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.jmd-topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  background: #fff;
  border-bottom: 1px solid var(--jmd-border);
  padding: 16px 28px;
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Same class of bug the .jmd-modal[hidden] rule already guards against (see admin.css):
   this element's own `display: flex` below has higher specificity than the browser's
   default [hidden] { display: none }, so JS setting .hidden = true on it (Diagnostics
   has no date range) was silently NOT hiding it — found via real-WordPress-runtime
   verification (2026-09-24). Every element Phase 2 toggles via .hidden and also gives
   its own `display` value needs this same explicit override. */
.jmd-topbar-daterange[hidden] {
  display: none;
}
.jmd-topbar-daterange {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--jmd-navy);
  font-size: 13px;
  font-weight: 600;
}
.jmd-topbar-daterange svg {
  width: 16px;
  height: 16px;
  color: var(--jmd-grey);
  flex: none;
}
.jmd-topbar-daterange input[type="date"] {
  border: 1px solid var(--jmd-border);
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 13px;
  color: var(--jmd-navy);
}

#jmd-fe-attribution-control select {
  border: 1px solid var(--jmd-border);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 13px;
}

.jmd-topbar-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-left: auto;
}

.jmd-lang-toggle {
  display: inline-flex;
  border: 1px solid var(--jmd-border);
  border-radius: 8px;
  overflow: hidden;
}
.jmd-lang-toggle button {
  border: none;
  background: #fff;
  color: var(--jmd-grey);
  font-size: 12px;
  font-weight: 700;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.jmd-lang-toggle button.is-active {
  background: var(--jmd-navy);
  color: #fff;
}

.jmd-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 17px;
  cursor: pointer;
  border: 1px solid var(--jmd-border);
  background: #fff;
  color: var(--jmd-navy);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.jmd-btn svg {
  width: 15px;
  height: 15px;
}
.jmd-btn:hover {
  border-color: var(--jmd-navy-light);
}
.jmd-btn-primary {
  background: var(--jmd-navy);
  border-color: var(--jmd-navy);
  color: #fff;
}
.jmd-btn-primary:hover {
  background: var(--jmd-navy-light);
  border-color: var(--jmd-navy-light);
}

.jmd-topbar-controls .jmd-muted {
  color: var(--jmd-grey-light);
  font-size: 12px;
}

.jmd-fe-error-banner {
  margin: 16px 28px 0;
}

.jmd-fe-content {
  padding: 28px;
  flex: 1;
}

.jmd-fe-page {
  max-width: 1320px;
  margin: 0 auto;
}

.jmd-page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 32px;
}
.jmd-page-eyebrow {
  color: var(--jmd-orange);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  line-height: 1.4;
  margin: 0 0 8px;
}
.jmd-page-title {
  color: var(--jmd-navy);
  font-size: 27px;
  font-weight: 800;
  line-height: 1.35;
  margin: 0 0 8px;
}
.jmd-page-subtitle {
  color: var(--jmd-grey);
  font-size: 13.5px;
  line-height: 1.6;
  margin: 0;
}
.jmd-page-updated {
  color: var(--jmd-grey-light);
  font-size: 12px;
  white-space: nowrap;
}

.jmd-fe-page-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}

.jmd-unavailable {
  padding: 10px 0;
}

/* Compact single-line info banner (2026-09 v0.7.1) for KPI groups where every value is
   null — replaces the old full-height renderUnavailable() card, which read as "broken"
   rather than "no data for this metric group in the current source". */
.jmd-info-banner-compact {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--jmd-bg);
  border: 1px solid var(--jmd-border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--jmd-grey);
  font-size: 12.5px;
  line-height: 1.5;
}
.jmd-info-banner-compact-icon {
  flex: none;
  color: var(--jmd-grey-light);
  font-size: 15px;
  line-height: 1;
}

/* Two-way mode switch (trend chart raw-count / conversion-rate toggle, v0.7.1) —
   visually distinct from the multi-select legend chips below it: a single active
   segment rather than a set of independently-toggleable filters. */
.jmd-toggle-group {
  display: inline-flex;
  background: var(--jmd-bg);
  border: 1px solid var(--jmd-border);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
  flex: none;
}
.jmd-toggle-btn {
  border: none;
  background: transparent;
  color: var(--jmd-grey);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.jmd-toggle-btn.is-active {
  background: #fff;
  color: var(--jmd-navy);
  box-shadow: 0 1px 2px rgba(27, 42, 74, 0.12);
}

/* Collapsible "ดูรายละเอียดทางเทคนิค" disclosure (Diagnostics + attribution alert,
   v0.7.1) — keeps the raw API caveat/note text available without it being the primary
   thing a non-technical reader sees. */
.jmd-tech-details {
  margin-top: 8px;
}
.jmd-tech-summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--jmd-grey);
  list-style: none;
  user-select: none;
}
.jmd-tech-summary::-webkit-details-marker {
  display: none;
}
.jmd-tech-summary::before {
  content: "▸ ";
}
.jmd-tech-details[open] > .jmd-tech-summary::before {
  content: "▾ ";
}
.jmd-tech-details .jmd-fe-technical-detail {
  margin-top: 6px;
}

.jmd-fe-technical-detail {
  margin-top: 6px;
  font-size: 12px;
  color: var(--jmd-grey-light);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
}

.jmd-modal-loading {
  padding: 20px 0;
  text-align: center;
  color: var(--jmd-grey);
}

/* Long URLs/GCLIDs (campaign, landing page, modal content) must never blow out a table
   cell or the modal width — break anywhere as a last resort, prefer breaking at natural
   separators first. */
.jmd-fe-truncate {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: bottom;
}
.jmd-fe-wrap-anywhere {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Campaign identity cell (2026-09 "final UI polish" round) — landing path primary,
   real campaign name (when known) as smaller secondary text underneath. */
.jmd-identity {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.jmd-identity-primary {
  color: #1d2327;
  font-weight: 600;
  max-width: 220px;
}
.jmd-identity-secondary {
  color: var(--jmd-grey-light);
  font-size: 11.5px;
  max-width: 220px;
}

.jmd-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Desktop-first, as requested — tablet gets a lighter touch, mobile collapses the fixed
   sidebar into a slide-in drawer (toggled by a hamburger button in the topbar) so nothing
   overflows the viewport, rather than a full separate mobile layout. */
@media (max-width: 1080px) {
  .jmd-fe-auth-page {
    grid-template-columns: 1fr;
  }
  .jmd-fe-auth-brand-panel {
    padding: 36px 32px;
    min-height: 260px;
  }
  .jmd-fe-auth-tagline {
    font-size: 26px;
  }
  .jmd-fe-auth-form-panel {
    padding: 32px;
  }
}
@media (max-width: 960px) {
  .jmd-page-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
@media (max-width: 782px) {
  .jmd-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.2);
  }
  .jmd-shell.jmd-sidebar-open .jmd-sidebar {
    transform: translateX(0);
  }
  .jmd-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(9, 14, 28, 0.5);
    z-index: 15;
  }
  .jmd-shell.jmd-sidebar-open .jmd-sidebar-backdrop {
    display: block;
  }
  .jmd-sidebar-toggle {
    display: inline-flex;
  }
  .jmd-topbar {
    padding: 12px 16px;
  }
  .jmd-topbar-daterange {
    flex-wrap: wrap;
  }
  .jmd-fe-content {
    padding: 16px;
  }
  .jmd-fe-error-banner {
    margin: 12px 16px 0;
  }
  .jmd-fe-auth-card {
    padding: 0;
  }
}
@media (min-width: 783px) {
  .jmd-sidebar-toggle {
    display: none;
  }
  .jmd-sidebar-backdrop {
    display: none;
  }
}
@media (max-width: 480px) {
  .jmd-fe-truncate {
    max-width: 160px;
  }
}
