/* ═══════════════════════════════════════════════════════════════
   FREEPASS ERP — 테마 시스템
   ═══════════════════════════════════════════════════════════════ */

/* ─── 클래식 테마 ──────────────────────────────────────────────── */

html.theme-classic {
  --radius-xs: 0; --radius-sm: 0; --radius-md: 0; --radius-lg: 0;
  --radius-pill: 0; --radius-ui: 0;
  --new-bg-app: #ffffff; --new-bg-main: #ffffff;
  --new-bg-sidebar: #fafaf8; --new-bg-panel-head: #fafaf8;
  --surface-subtle: #fafafa; --surface-hover: #f5f5f5;
  --surface-selected: #f0f0f0; --surface-muted: #fafafa;
  --interactive-hover-bg: #f5f5f5; --interactive-active-bg: #ebebeb;
  --interactive-selected-bg: #f0f0f0;
  --border-soft: #e5e5e5; --border-main: #d4d4d4;
  --new-border-soft: #e5e5e5; --new-border-strong: #d4d4d4; --new-line-view: #e5e5e5;
  --panel-gap: 0; --panel-shadow: none;
}
html.theme-classic body { background: #ffffff; }
html.theme-classic .dashboard-shell--new .sidebar { background: #fafaf8; border-right: 1px solid #e5e5e5; box-shadow: none; }
html.theme-classic .main-shell { padding: 0 !important; gap: 0 !important; }
html.theme-classic .work-page { gap: 0; }
html.theme-classic .panel { box-shadow: none; border: 1px solid #e5e5e5; border-radius: 0; }
html.theme-classic .panel-resize-handle { flex: 0 0 1px; background: #e5e5e5; }
html.theme-classic .panel-resize-handle:hover { background: #2563eb; }

/* ═══════════════════════════════════════════════════════════════
   다크모드 (클래식 전용)
   전략: CSS 변수 + 와일드카드로 전체 반전
   ═══════════════════════════════════════════════════════════════ */

html.theme-classic.theme-dark {
  /* 배경 계층 */
  --dk-bg-deep: #09090b;
  --dk-bg-base: #0c0c0e;
  --dk-bg-card: #111113;
  --dk-bg-elevated: #18181b;
  --dk-bg-hover: #1f1f23;
  --dk-bg-selected: #27272a;

  /* 텍스트 계층 (눈 편한 톤) */
  --dk-text-primary: #c8c8cd;
  --dk-text-secondary: #8e8e96;
  --dk-text-tertiary: #63636b;
  --dk-text-muted: #4a4a52;

  /* 테두리 계층 */
  --dk-border-subtle: #1f1f23;
  --dk-border-default: #27272a;
  --dk-border-strong: #3f3f46;

  /* 액센트 */
  --dk-accent: #3b82f6;
  --dk-accent-hover: #2563eb;
  --dk-link: #60a5fa;

  /* 기존 변수 매핑 */
  --new-bg-app: var(--dk-bg-deep); --new-bg-main: var(--dk-bg-deep);
  --new-bg-sidebar: var(--dk-bg-base); --new-bg-panel: var(--dk-bg-card);
  --new-bg-panel-head: var(--dk-bg-elevated);
  --surface-base: var(--dk-bg-card); --surface-subtle: var(--dk-bg-elevated);
  --surface-hover: var(--dk-bg-hover); --surface-selected: var(--dk-bg-selected);
  --surface-muted: var(--dk-bg-elevated);
  --interactive-hover-bg: var(--dk-bg-hover); --interactive-active-bg: var(--dk-bg-selected);
  --interactive-selected-bg: var(--dk-bg-selected);
  --text-main: var(--dk-text-primary); --text-subtle: var(--dk-text-secondary); --text-muted: var(--dk-text-tertiary);
  --new-text-main: var(--dk-text-primary); --new-text-sub: var(--dk-text-secondary);
  --new-text-primary: var(--dk-text-primary); --new-text-secondary: var(--dk-text-secondary);
  --new-sidebar-text: var(--dk-text-secondary); --new-sidebar-text-active: #ffffff;
  --new-sidebar-icon: var(--dk-text-tertiary); --new-sidebar-icon-active: #ffffff;
  --border-soft: var(--dk-border-subtle); --border-main: var(--dk-border-default); --border-strong: var(--dk-border-strong);
  --new-border-soft: var(--dk-border-subtle); --new-border-strong: var(--dk-border-default);
  --new-border-panel: var(--dk-border-default); --new-border-control: var(--dk-border-strong);
  --new-line-view: var(--dk-border-subtle);
  --new-sidebar-accent: var(--dk-link);
  --new-hover: rgba(255,255,255,0.05); --new-selected: rgba(255,255,255,0.08);
  --new-accent: var(--dk-accent); --new-accent-hover: var(--dk-accent-hover);
  --panel-shadow: none;
  color-scheme: dark;
}

/* ── 와일드카드: 모든 요소의 흰 배경/검은 텍스트 강제 반전 ── */
html.theme-classic.theme-dark body { background: var(--dk-bg-deep); color: var(--dk-text-primary); }

html.theme-classic.theme-dark *:not(img):not(svg):not(video):not(canvas):not(iframe):not([class*="badge"]):not([class*="btn-primary"]):not([class*="btn-tone-save"]):not([class*="auth-submit"]) {
  border-color: var(--dk-border-default) !important;
}

html.theme-classic.theme-dark .main-area,
html.theme-classic.theme-dark .main-shell,
html.theme-classic.theme-dark .work-page { background: var(--dk-bg-deep) !important; }

html.theme-classic.theme-dark .dashboard-shell--new .sidebar { background: var(--dk-bg-base) !important; }

html.theme-classic.theme-dark .panel,
html.theme-classic.theme-dark .panel--form,
html.theme-classic.theme-dark .pls-grid-panel { background: var(--dk-bg-card) !important; }

html.theme-classic.theme-dark .panel-head { background: var(--dk-bg-elevated) !important; }
html.theme-classic.theme-dark .panel-body,
html.theme-classic.theme-dark .panel-body--detail,
html.theme-classic.theme-dark .manage-form-body,
html.theme-classic.theme-dark .manage-form-shell,
html.theme-classic.theme-dark .form-stack,
html.theme-classic.theme-dark .form-grid { background: var(--dk-bg-card) !important; }

html.theme-classic.theme-dark .pls-grid-scroll { background: var(--dk-bg-base) !important; }
html.theme-classic.theme-dark .panel-resize-handle { background: var(--dk-border-default) !important; }

/* ── 상세 패널 ── */
html.theme-classic.theme-dark .pls-detail-panel { background: var(--dk-bg-base) !important; box-shadow: -4px 0 20px rgba(0,0,0,0.5) !important; }
html.theme-classic.theme-dark .pls-detail-panel .panel-body,
html.theme-classic.theme-dark .pls-detail-panel .panel-body--detail { background: var(--dk-bg-base) !important; }

/* md- 카드/섹션 (상세 마크업) */
html.theme-classic.theme-dark .md-card { background: var(--dk-bg-card) !important; box-shadow: none !important; }
html.theme-classic.theme-dark .md-section-head { color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark .md-section-head svg { color: var(--dk-text-tertiary) !important; }
html.theme-classic.theme-dark .md-row { border-color: var(--dk-border-subtle) !important; }
html.theme-classic.theme-dark .md-row span { color: var(--dk-text-tertiary) !important; }
html.theme-classic.theme-dark .md-row strong { color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark .md-table th { background: var(--dk-bg-elevated) !important; color: var(--dk-text-tertiary) !important; }
html.theme-classic.theme-dark .md-table td { background: var(--dk-bg-card) !important; color: var(--dk-text-secondary) !important; }
html.theme-classic.theme-dark .md-table td strong { color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark .md-note { background: var(--dk-bg-elevated) !important; color: var(--dk-text-muted) !important; }
html.theme-classic.theme-dark .md-link { color: var(--dk-link) !important; }

/* ── 테이블 (목록) ── */
html.theme-classic.theme-dark .pls-table th { background: var(--dk-bg-card) !important; color: var(--dk-text-tertiary) !important; }
html.theme-classic.theme-dark .pls-table td { background: var(--dk-bg-base) !important; color: var(--dk-text-secondary) !important; }
html.theme-classic.theme-dark .pls-table tr:nth-child(even) td { background: var(--dk-bg-card) !important; }
html.theme-classic.theme-dark .pls-table tr:hover td { background: var(--dk-bg-hover) !important; }
html.theme-classic.theme-dark .pls-table tr.is-selected td { background: var(--dk-bg-selected) !important; }

/* ── 사이드바 ── */
html.theme-classic.theme-dark .sidebar-link { color: var(--dk-text-secondary) !important; }
html.theme-classic.theme-dark .sidebar-link:hover { background: var(--dk-bg-hover) !important; color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark .sidebar-link.is-active { background: var(--dk-bg-hover) !important; color: #ffffff !important; }
html.theme-classic.theme-dark .sidebar-head { border-color: var(--dk-border-subtle) !important; }
html.theme-classic.theme-dark .sidebar-toggle-btn { color: var(--dk-text-tertiary) !important; }

/* ── 탑바 ── */
html.theme-classic.theme-dark .top-bar { background: var(--dk-bg-base) !important; border-color: var(--dk-border-subtle) !important; }
html.theme-classic.theme-dark .top-bar-user-item { color: var(--dk-text-secondary) !important; }
html.theme-classic.theme-dark .top-bar-page-name { color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark .top-bar-identity { color: var(--dk-text-secondary) !important; }
html.theme-classic.theme-dark .top-bar-logout-btn { color: var(--dk-text-tertiary) !important; }

/* ── 폼 요소 ── */
html.theme-classic.theme-dark input,
html.theme-classic.theme-dark select,
html.theme-classic.theme-dark textarea { background: var(--dk-bg-elevated) !important; color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark input::placeholder { color: var(--dk-text-muted) !important; }
html.theme-classic.theme-dark input:focus,
html.theme-classic.theme-dark select:focus { border-color: var(--dk-accent) !important; }
html.theme-classic.theme-dark input[readonly] { background: var(--dk-bg-base) !important; color: var(--dk-text-muted) !important; }
html.theme-classic.theme-dark input[type="checkbox"] { accent-color: var(--dk-accent); }
html.theme-classic.theme-dark label { color: var(--dk-text-secondary) !important; }
html.theme-classic.theme-dark .field label { color: var(--dk-text-tertiary) !important; }
html.theme-classic.theme-dark .section-title { color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark .form-section-title { color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark .form-section-title svg { color: var(--dk-text-tertiary) !important; }

/* ── 버튼 ── */
html.theme-classic.theme-dark .inline-button { background: var(--dk-bg-elevated) !important; color: var(--dk-text-secondary) !important; }
html.theme-classic.theme-dark .inline-button:hover { background: var(--dk-bg-selected) !important; }
html.theme-classic.theme-dark .btn-tone-save,
html.theme-classic.theme-dark .auth-submit { background: var(--dk-accent) !important; color: #ffffff !important; }

/* ── 대화 페이지 (전체 다크) ── */
html.theme-classic.theme-dark [class*="chat"],
html.theme-classic.theme-dark [class*="Chat"],
html.theme-classic.theme-dark [class*="room"],
html.theme-classic.theme-dark [class*="Room"],
html.theme-classic.theme-dark [class*="message"],
html.theme-classic.theme-dark [class*="Message"] { background-color: var(--dk-bg-deep); color: var(--dk-text-primary); }
html.theme-classic.theme-dark .chat-messages { background: var(--dk-bg-deep) !important; }
html.theme-classic.theme-dark .message-form { background: var(--dk-bg-card) !important; border-color: var(--dk-border-subtle) !important; }
html.theme-classic.theme-dark .message-form textarea { background: var(--dk-bg-card) !important; color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark .message-form-code { color: var(--dk-text-muted) !important; }
html.theme-classic.theme-dark .chat-date-separator { color: var(--dk-text-muted) !important; }
html.theme-classic.theme-dark .chat-system-msg { color: var(--dk-text-muted) !important; }

/* 채팅 말풍선 */
html.theme-classic.theme-dark .chat-msg-row { background: transparent !important; }
/* 상대 말풍선 */
html.theme-classic.theme-dark .message-bubble { background: #1f1f23 !important; color: #e4e4e7 !important; border: 1px solid #2a2a2e !important; }
/* 내 말풍선 */
html.theme-classic.theme-dark .message-wrap.out .message-bubble { background: #1a2e4a !important; color: #c8ddf5 !important; border: 1px solid #243a5c !important; }
html.theme-classic.theme-dark .message-sender { color: var(--dk-text-tertiary) !important; }
html.theme-classic.theme-dark .message-time { color: var(--dk-text-muted) !important; }
html.theme-classic.theme-dark .message-date-divider { color: var(--dk-text-muted) !important; }
html.theme-classic.theme-dark .message-wrap { background: transparent !important; }
html.theme-classic.theme-dark .message-content { background: transparent !important; }

/* 대화 목록 카드 */
html.theme-classic.theme-dark .m-list-card { background: var(--dk-bg-card) !important; }
html.theme-classic.theme-dark .m-list-card:hover { background: var(--dk-bg-elevated) !important; }
html.theme-classic.theme-dark .m-list-card.is-active { background: var(--dk-bg-hover) !important; }
html.theme-classic.theme-dark .m-list-card__name { color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark .m-list-card__sub { color: var(--dk-text-tertiary) !important; }

/* 채팅 오른쪽 상세 패널 (m-pd 마크업) */
html.theme-classic.theme-dark .m-pd,
html.theme-classic.theme-dark .m-pd--desktop,
html.theme-classic.theme-dark .m-pd * { background-color: var(--dk-bg-base) !important; color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark .m-pd-group__body { background: var(--dk-bg-card) !important; }
html.theme-classic.theme-dark .m-pd__row { border-color: var(--dk-border-subtle) !important; }
html.theme-classic.theme-dark .m-pd__row-label { color: var(--dk-text-tertiary) !important; }
html.theme-classic.theme-dark .m-pd__row-value { color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark .m-pd-group-head { color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark .m-pd-group-head svg { color: var(--dk-text-tertiary) !important; }
html.theme-classic.theme-dark .m-pd .md-table th { background: var(--dk-bg-elevated) !important; color: var(--dk-text-tertiary) !important; }
html.theme-classic.theme-dark .m-pd .md-table td { background: var(--dk-bg-card) !important; color: var(--dk-text-secondary) !important; }
html.theme-classic.theme-dark .m-pd img { background: transparent !important; }

/* ── 설정 페이지 ── */
html.theme-classic.theme-dark .settings-section-block { background: var(--dk-bg-card) !important; }
html.theme-classic.theme-dark .section-title-row .section-desc { color: var(--dk-text-muted) !important; }
html.theme-classic.theme-dark .settings-catalog-link-input { background: var(--dk-bg-elevated) !important; color: var(--dk-text-secondary) !important; }
html.theme-classic.theme-dark .settings-badge-label { color: var(--dk-text-secondary) !important; }
html.theme-classic.theme-dark .settings-helper { color: var(--dk-text-muted) !important; }
html.theme-classic.theme-dark .settings-account-action-row { color: var(--dk-text-secondary) !important; }
html.theme-classic.theme-dark .settings-account-action-row:hover { background: var(--dk-bg-elevated) !important; }
html.theme-classic.theme-dark .toggle-switch-track { background: var(--dk-bg-selected) !important; }

/* ── 컨텍스트 메뉴 ── */
html.theme-classic.theme-dark .pm-ctx-menu { background: var(--dk-bg-elevated) !important; box-shadow: 0 8px 24px rgba(0,0,0,0.6) !important; }
html.theme-classic.theme-dark .pm-ctx-item { color: var(--dk-text-secondary) !important; }
html.theme-classic.theme-dark .pm-ctx-item:hover { background: var(--dk-bg-selected) !important; }
html.theme-classic.theme-dark .pm-ctx-item svg { color: var(--dk-text-tertiary) !important; }
html.theme-classic.theme-dark .pm-ctx-divider { background: var(--dk-border-default) !important; }
html.theme-classic.theme-dark .pm-ctx-submenu { background: var(--dk-bg-elevated) !important; }

/* ── 모달 ── */
html.theme-classic.theme-dark .fp-modal-box { background: var(--dk-bg-elevated) !important; }
html.theme-classic.theme-dark .fp-modal-text { color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark .fp-modal-btn--cancel { background: var(--dk-bg-selected) !important; color: var(--dk-text-secondary) !important; }
html.theme-classic.theme-dark .fp-modal-btn--ok { background: var(--dk-accent) !important; }

/* ── 토스트 ── */
html.theme-classic.theme-dark .fp-toast { background: var(--dk-bg-selected) !important; color: var(--dk-text-primary) !important; }

/* ── 스크롤바 ── */
html.theme-classic.theme-dark ::-webkit-scrollbar { width: 8px; height: 8px; }
html.theme-classic.theme-dark ::-webkit-scrollbar-track { background: var(--dk-bg-deep); }
html.theme-classic.theme-dark ::-webkit-scrollbar-thumb { background: var(--dk-bg-selected); }
html.theme-classic.theme-dark ::-webkit-scrollbar-thumb:hover { background: var(--dk-border-strong); }

/* ── 빈 상태 ── */
html.theme-classic.theme-dark .empty-block,
html.theme-classic.theme-dark .manage-idle-hint { color: var(--dk-text-muted) !important; }

/* ── 필터 ── */
html.theme-classic.theme-dark .filter-overlay { background: var(--dk-bg-card) !important; }
html.theme-classic.theme-dark .filter-group-head { background: var(--dk-bg-elevated) !important; color: var(--dk-text-secondary) !important; }

/* ── 링크 ── */
html.theme-classic.theme-dark a { color: var(--dk-link) !important; }
html.theme-classic.theme-dark a:hover { color: #93bbfd !important; }

/* ── 계약 체크 ── */
html.theme-classic.theme-dark .contract-check-item span { color: var(--dk-text-secondary) !important; }

/* ── 뱃지 (무채색 통일) ── */
html.theme-classic.theme-dark .manage-badge,
html.theme-classic.theme-dark [class*="badge"],
html.theme-classic.theme-dark [class*="Badge"] {
  filter: saturate(0) !important;
  opacity: 0.85;
}

/* ── 상세 패널 배경 강제 (모든 depth) ── */
html.theme-classic.theme-dark #productDetail,
html.theme-classic.theme-dark #plsDetailPanel,
html.theme-classic.theme-dark [class*="detail-panel"],
html.theme-classic.theme-dark [class*="detail"] > div,
html.theme-classic.theme-dark [class*="detail"] > div > div,
html.theme-classic.theme-dark [class*="detail"] > div > div > div,
html.theme-classic.theme-dark [class*="detail"] section,
html.theme-classic.theme-dark [class*="plist-detail"],
html.theme-classic.theme-dark [class*="plist-detail"] * {
  background-color: var(--dk-bg-base) !important;
  color: var(--dk-text-primary) !important;
}
html.theme-classic.theme-dark [class*="plist-detail"] span,
html.theme-classic.theme-dark [class*="plist-detail"] label,
html.theme-classic.theme-dark [class*="detail"] span:not([class*="badge"]) { color: var(--dk-text-secondary) !important; }
html.theme-classic.theme-dark [class*="plist-detail"] strong,
html.theme-classic.theme-dark [class*="detail"] strong { color: var(--dk-text-primary) !important; }
html.theme-classic.theme-dark [class*="plist-detail"] th { background: var(--dk-bg-elevated) !important; color: var(--dk-text-tertiary) !important; }
html.theme-classic.theme-dark [class*="plist-detail"] td { background: var(--dk-bg-card) !important; color: var(--dk-text-secondary) !important; }
