/*
 * Pglemaps Partner workspace theme contract
 *
 * The advertiser pages are standalone HTML documents with several historic
 * token names. This compatibility layer maps them to one dark palette and
 * fixes the remaining neutral surfaces that still use a literal white.
 * Theme selection remains owned by the main dashboard; sub-pages read only.
 */

:root[data-theme="dark"] {
  color-scheme: dark;

  /* Shared workspace palette */
  --workspace-bg: #0f1020;
  --workspace-surface: #17182b;
  --workspace-surface-raised: #1e2036;
  --workspace-border: #2a2c45;
  --workspace-border-strong: #3a3d5c;
  --workspace-text: #edeef7;
  --workspace-muted: #9ca3c4;
  --workspace-muted-light: #6b6f92;

  /* Canonical dashboard / legacy page tokens */
  --bg: var(--workspace-bg);
  --card: var(--workspace-surface);
  --panel: var(--workspace-surface);
  --panel-2: var(--workspace-surface-raised);
  --border: var(--workspace-border);
  --border-strong: var(--workspace-border-strong);
  --line: var(--workspace-border);
  --line-soft: #24263d;
  --line-strong: var(--workspace-border-strong);
  --text: var(--workspace-text);
  --ink: var(--workspace-text);
  --muted: var(--workspace-muted);
  --muted-light: var(--workspace-muted-light);
  --muted-2: var(--workspace-muted-light);
  --muted2: var(--workspace-muted-light);
  --sidebar-bg: #0f172a;

  /* Status backgrounds must remain legible without becoming light panels. */
  --primary-light: rgba(37, 99, 235, 0.22);
  --primary-soft: rgba(37, 99, 235, 0.18);
  --accent-light: rgba(192, 38, 211, 0.2);
  --success-light: rgba(16, 185, 129, 0.16);
  --warning-light: rgba(249, 115, 22, 0.16);
  --danger-light: rgba(220, 38, 38, 0.2);
  --purple-soft: rgba(124, 92, 252, 0.18);
  --purple-line: rgba(155, 123, 255, 0.42);
  --green-soft: rgba(22, 163, 74, 0.16);
  --green-line: rgba(34, 197, 94, 0.35);
  --amber-soft: rgba(245, 158, 11, 0.15);
  --amber-line: rgba(245, 158, 11, 0.34);
  --red-soft: rgba(239, 68, 68, 0.16);
  --red-line: rgba(239, 68, 68, 0.34);
  --gold-soft: rgba(245, 166, 35, 0.16);
}

/* --soft is a surface token on these pages, but a text token in the legacy
   message inbox. Scope it so the two meanings cannot collide. */
:root[data-theme="dark"][data-partner-template="coupon-builder-html"],
:root[data-theme="dark"][data-partner-template="noshow-refund-html"] {
  --soft: var(--workspace-surface-raised);
}

:root[data-theme="dark"],
:root[data-theme="dark"] body {
  background-color: var(--workspace-bg);
  color: var(--workspace-text);
}

:root[data-theme="dark"] body {
  transition:
    background-color 0.2s ease,
    color 0.2s ease;
}

/* Literal-white neutral surfaces retained by older standalone templates. */
:root[data-theme="dark"] :where(
  body > header,
  .topbar,
  .stat-card,
  .filter-bar,
  .res-card,
  .act-btn:not(.act-btn-confirm):not(.act-btn-complete):not(.act-btn-reject):not(.act-btn-noshow),
  .cal-section,
  .cal-week-btn,
  .staff-tab:not(.active):not(.staff-tab-drop),
  .naver-cal-month,
  .naver-cal-day,
  .ncd-subslot:not(.booked):not(.drop-target),
  .ncd-slot:not(.open):not(.booked):not(.past):not(.range-selecting):not(.drop-target),
  .cal-slot:not(.open):not(.booked):not(.past):not(.drop-target),
  .summary-card,
  .review-card,
  .rev-card,
  .rev-btn:not(.rev-btn-primary),
  .menu-card,
  .menu-btn,
  .cat-group,
  .category-group,
  .filter-chip:not(.active),
  .notice-card,
  .card,
  .staff-card,
  .empty,
  .modal,
  .terms-modal,
  .not-rentcar,
  .conv,
  .shell,
  .composer,
  .msg,
  .link-btn,
  .btn-ghost,
  .kpi-row,
  .withdraw-section,
  .modal-panel,
  .desg-modal,
  .desg-current-label,
  .claim-card,
  .btn-detail,
  .cat-tab:not(.active),
  .chip:not(.active):not(.on),
  .toggle button:not(.on-ok):not(.on-off),
  .add:not(:hover):not(:disabled),
  .store-img-preview,
  .interior-thumb,
  .img-btn:not(.img-btn-primary),
  .modal-card,
  .confirm-card,
  .hanbok-accessory-row,
  .opt-off-btn,
  .opt-stock-btn:not(.active),
  .opt-row-del,
  .hair-off-btn,
  .hair-row-del,
  .medical-off-btn,
  .medical-row-del
) {
  background-color: var(--workspace-surface);
  border-color: var(--workspace-border);
  color: var(--workspace-text);
}

:root[data-theme="dark"] :where(
  input:not([type]),
  input[type="text"],
  input[type="search"],
  input[type="number"],
  input[type="date"],
  input[type="time"],
  input[type="email"],
  input[type="tel"],
  input[type="url"],
  select,
  textarea,
  .form-input,
  .form-select,
  .form-textarea,
  .input,
  .textarea
) {
  background-color: var(--workspace-surface);
  border-color: var(--workspace-border-strong);
  color: var(--workspace-text);
}

:root[data-theme="dark"] :where(
  input,
  textarea
)::placeholder {
  color: var(--workspace-muted-light);
}

/* The reservation page is the only workspace where .head-btn is a neutral
   control. On menu/review pages that same class is the primary gradient CTA. */
:root[data-theme="dark"][data-partner-template="reservation-html"]
  .head-btn:not(.head-btn-primary) {
  background: var(--workspace-surface);
  border-color: var(--workspace-border);
  color: var(--workspace-text);
}

/* Inline white is used only by the legacy modal shells in these pages. */
:root[data-theme="dark"] :where(
  .modal-backdrop,
  .confirm-backdrop,
  .detail-backdrop
) > [style*="background:#fff"],
:root[data-theme="dark"] :where(
  .modal-backdrop,
  .confirm-backdrop,
  .detail-backdrop
) > [style*="background: #fff"] {
  background-color: var(--workspace-surface) !important;
  border-color: var(--workspace-border) !important;
  color: var(--workspace-text) !important;
}

/* Page-specific contrast repairs for hard-coded light helper blocks. */
:root[data-theme="dark"] .notice-detail p {
  color: var(--workspace-muted);
}

:root[data-theme="dark"] .notice-card.pinned {
  background: rgba(37, 99, 235, 0.12);
}

:root[data-theme="dark"][data-partner-template="reviews-html"] .summary {
  background: linear-gradient(
    135deg,
    rgba(245, 158, 11, 0.16),
    rgba(249, 115, 22, 0.11)
  );
  border-color: rgba(245, 158, 11, 0.34);
}

:root[data-theme="dark"][data-partner-template="reviews-html"] .kpi-row {
  background: var(--workspace-surface-raised);
}

:root[data-theme="dark"] .step-tip {
  background: rgba(249, 115, 22, 0.14);
  color: #fdba74;
}

:root[data-theme="dark"][data-partner-template="insurance-html"] .warn-banner {
  background: linear-gradient(
    135deg,
    rgba(249, 115, 22, 0.16),
    rgba(245, 158, 11, 0.12)
  );
  border-color: rgba(249, 115, 22, 0.42);
  color: #fdba74;
}

:root[data-theme="dark"][data-partner-template="insurance-html"]
  .toggle button.on-ok {
  background: rgba(16, 185, 129, 0.16);
  color: #6ee7b7;
}

:root[data-theme="dark"] .history-panel {
  background: var(--workspace-surface-raised);
}

:root[data-theme="dark"] .coupon-card .cp-bot {
  background: var(--workspace-surface);
  border-color: var(--workspace-border);
}

:root[data-theme="dark"] .customer-qna-page .switch-track::after,
:root[data-theme="dark"][data-partner-template="customer-qna-html"] .switch-track::after {
  background: var(--workspace-text);
}

:root[data-theme="dark"][data-partner-template="store-html"]
  :where(.store-img-cell, .interior-add) {
  background: var(--workspace-surface-raised);
  border-color: var(--workspace-border);
}

:root[data-theme="dark"][data-partner-template="store-html"]
  :where(.store-img-uploading, .interior-uploading) {
  background: rgba(23, 24, 43, 0.9);
}

:root[data-theme="dark"][data-partner-template="help-contact-html"]
  .faq-a-inner {
  color: var(--workspace-muted);
}

:root[data-theme="dark"][data-partner-template="announcements-html"]
  .notice-body {
  color: var(--workspace-muted);
}

:root[data-theme="dark"][data-partner-template="dashboard-html"]
  :where(.msg-row.unread, .nt-row.unread) {
  background: rgba(249, 115, 22, 0.14);
}

:root[data-theme="dark"][data-partner-template="dashboard-html"]
  :where(.pgl-notice, .pgl-nt-foot, .pgl-reservation-step) {
  background: var(--workspace-surface);
  border-color: var(--workspace-border);
  color: var(--workspace-text);
}

:root[data-theme="dark"][data-partner-template="dashboard-html"]
  :where(.pgl-slot-demo, .pgl-nt-btn.ghost) {
  background: var(--workspace-surface-raised);
  border-color: var(--workspace-border);
}

:root[data-theme="dark"][data-partner-template="dashboard-html"]
  :where(.pgl-nt-tip, .pgl-reservation-warning) {
  background: rgba(249, 115, 22, 0.14);
  color: #fdba74;
}

:root[data-theme="dark"][data-partner-template="dashboard-html"]
  .pgl-nt-good {
  background: rgba(16, 185, 129, 0.14);
  color: #6ee7b7;
}

/* customer_messages.html intentionally owns a compact full-height chat
   palette on body; its existing body.light compatibility remains for light. */
:root[data-theme="dark"][data-partner-template="customer-messages-html"] body {
  color-scheme: dark;
}

/* Independent message inbox/thread pages use different token names. */
:root[data-theme="dark"][data-partner-template="messages-inbox-html"] {
  --soft: var(--workspace-muted);
}

:root[data-theme="dark"][data-partner-template="messages-html"] .head {
  background: var(--workspace-surface-raised);
}

:root[data-theme="dark"][data-partner-template="messages-html"] .msg.partner,
:root[data-theme="dark"][data-partner-template="messages-inbox-html"] .conv.unread {
  background: var(--primary-light);
}

@media (prefers-reduced-motion: reduce) {
  :root[data-theme="dark"] body {
    transition: none;
  }
}
