/* KILIM Quiet Luxury — Unified Light & Dark Theme */
:root {
  --k-bg: #FAF7F2;
  --k-surface: #FFFFFF;
  --k-surface-2: #F4EFE6;
  --k-surface-3: #ECE5D8;
  --k-border: #E6DEC9;
  --k-border-soft: #EFE8DB;
  --k-text: #1C1614;
  --k-text-2: #493F3A;
  --k-text-muted: #7A6E66;
  --k-gold: #C6A96C;
  --k-gold-bright: #D4B678;
  --k-gold-ink: #8E7033;
  --k-photo-bg: #F6F2EB;
  color-scheme: light;
}

html[data-theme="dark"] {
  --k-bg: #121110;
  --k-surface: #1A1816;
  --k-surface-2: #23201D;
  --k-surface-3: #2C2824;
  --k-border: #322D27;
  --k-border-soft: #28241F;
  --k-text: #F3ECE1;
  --k-text-2: #CFC6B9;
  --k-text-muted: #988F84;
  --k-gold: #D4B678;
  --k-gold-bright: #E5CA8E;
  --k-gold-ink: #DEC285;
  --k-photo-bg: #221F1C;
  color-scheme: dark;
}

/* Smooth transitions only after first paint (prevents FOUC/flicker) */
html.theme-ready body,
html.theme-ready .rug-card,
html.theme-ready .pick,
html.theme-ready .cat-tab,
html.theme-ready .col-card,
html.theme-ready .sim-card,
html.theme-ready .faq details,
html.theme-ready #ai-chat-window.mc,
html.theme-ready #product-modal > div,
html.theme-ready #checkout-modal > div,
html.theme-ready #cart-drawer > div,
html.theme-ready #room-modal > div,
html.theme-ready input,
html.theme-ready select,
html.theme-ready textarea {
  transition: background-color 0.22s ease, color 0.22s ease, border-color 0.22s ease;
}

/* Sun/Moon toggle button icon switching */
[data-theme-toggle] .ico-sun { display: none; }
[data-theme-toggle] .ico-moon { display: block; }
html[data-theme="dark"] [data-theme-toggle] .ico-sun { display: block; }
html[data-theme="dark"] [data-theme-toggle] .ico-moon { display: none; }

/* SSR floating compact toggle for subpages without main header */
.k-theme-pill {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  z-index: 60;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(212, 182, 120, 0.45);
  background: rgba(24, 21, 19, 0.88);
  color: #E8D5A8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.k-theme-pill:hover { border-color: #D4B678; }

/* ==================== DARK THEME OVERRIDES ==================== */
html[data-theme="dark"] body {
  background-color: var(--k-bg) !important;
  color: var(--k-text) !important;
}

/* Global Tailwind light surfaces -> Quiet Luxury graphite */
html[data-theme="dark"] .bg-white,
html[data-theme="dark"] .bg-white\/95,
html[data-theme="dark"] .bg-\[\#FFFDF9\],
html[data-theme="dark"] .bg-\[\#fffdf9\],
html[data-theme="dark"] .bg-\[\#FAF5E8\],
html[data-theme="dark"] .bg-oxblood-50 {
  background-color: var(--k-surface) !important;
}
html[data-theme="dark"] .bg-ivory-50,
html[data-theme="dark"] .bg-\[\#FAF7F2\],
html[data-theme="dark"] .bg-\[\#f8f5ef\],
html[data-theme="dark"] .bg-\[\#f6f2ec\] {
  background-color: var(--k-bg) !important;
}
html[data-theme="dark"] .bg-ivory-100,
html[data-theme="dark"] .bg-ivory-200,
html[data-theme="dark"] .bg-\[\#F6F1E7\],
html[data-theme="dark"] .bg-\[\#F3EDE3\] {
  background-color: var(--k-surface-2) !important;
}
html[data-theme="dark"] .hover\:bg-ivory-200:hover,
html[data-theme="dark"] .hover\:bg-ivory-100:hover {
  background-color: var(--k-surface-3) !important;
}

/* Borders */
html[data-theme="dark"] .border-ivory-200,
html[data-theme="dark"] .border-ivory-300,
html[data-theme="dark"] .border-obsidian-900,
html[data-theme="dark"] .border-\[\#ECE5D8\],
html[data-theme="dark"] .border-\[\#E5DCCB\],
html[data-theme="dark"] .border-\[\#DFD6C5\],
html[data-theme="dark"] .border-\[\#EAE3D5\],
html[data-theme="dark"] .border-\[\#E5DBC8\] {
  border-color: var(--k-border) !important;
}

/* Typography contrast */
html[data-theme="dark"] .text-ink-900,
html[data-theme="dark"] .text-ink-800,
html[data-theme="dark"] .text-obsidian-900:not(.gold-cta):not(.bg-gold-400) {
  color: var(--k-text) !important;
}
html[data-theme="dark"] .text-ink-700,
html[data-theme="dark"] .text-ink-600 {
  color: var(--k-text-2) !important;
}
html[data-theme="dark"] .text-ink-500,
html[data-theme="dark"] .text-ink-400,
html[data-theme="dark"] .ql-meta {
  color: var(--k-text-muted) !important;
}
html[data-theme="dark"] .text-oxblood-700 {
  color: var(--k-gold-bright) !important;
}
html[data-theme="dark"] .pm-sz-btn.bg-obsidian-900 {
  background-color: var(--k-gold) !important;
  border-color: var(--k-gold) !important;
  color: #161311 !important;
}
html[data-theme="dark"] .pm-sz-btn.bg-obsidian-900 * {
  color: #161311 !important;
}
html[data-theme="dark"] #checkout-modal .bg-\[\#1C1614\],
html[data-theme="dark"] #btn-proceed-checkout {
  background-color: var(--k-gold) !important;
  color: #161311 !important;
}
html[data-theme="dark"] #checkout-modal .sticky.bg-\[\#1C1614\] {
  background-color: #171513 !important;
  color: var(--k-text) !important;
  border-bottom: 1px solid var(--k-border);
}

/* Keep dark text on gold CTA buttons and badges, except dark inner pill like #cart-count-badge */
html[data-theme="dark"] .gold-cta,
html[data-theme="dark"] .gold-cta > span:not(#cart-count-badge),
html[data-theme="dark"] .gold-cta > svg,
html[data-theme="dark"] #fav-count-badge,
html[data-theme="dark"] .size-chip.on {
  color: #161311 !important;
}
html[data-theme="dark"] #cart-count-badge {
  background-color: #150F0D !important;
  color: #F2D794 !important;
  border: 1px solid rgba(212, 182, 120, 0.35);
}

/* Catalog cards, picks, category tabs, collections, FAQ, reviews */
html[data-theme="dark"] .rug-card,
html[data-theme="dark"] .col-card,
html[data-theme="dark"] .sim-card,
html[data-theme="dark"] .faq details {
  background: var(--k-surface) !important;
  border-color: var(--k-border) !important;
  color: var(--k-text) !important;
}
html[data-theme="dark"] .rug-card:hover,
html[data-theme="dark"] .col-card:hover {
  border-color: rgba(212, 182, 120, 0.55) !important;
  box-shadow: 0 12px 28px -18px rgba(0, 0, 0, 0.7) !important;
}
html[data-theme="dark"] .col-info b,
html[data-theme="dark"] .sim-name,
html[data-theme="dark"] .sim-price,
html[data-theme="dark"] .faq summary {
  color: var(--k-text) !important;
}
html[data-theme="dark"] .col-info small,
html[data-theme="dark"] .faq p,
html[data-theme="dark"] .stock-ind {
  color: var(--k-text-muted) !important;
}
html[data-theme="dark"] .pick,
html[data-theme="dark"] .cat-tab:not(.bg-obsidian-900),
html[data-theme="dark"] .col-tabs button:not(.on) {
  background: var(--k-surface) !important;
  border-color: var(--k-border) !important;
  color: var(--k-text-2) !important;
}
html[data-theme="dark"] .pick.on,
html[data-theme="dark"] .cat-tab.bg-obsidian-900,
html[data-theme="dark"] .col-tabs button.on {
  background: var(--k-gold) !important;
  border-color: var(--k-gold) !important;
  color: #161311 !important;
}
html[data-theme="dark"] .pick.on small {
  color: #2B2319 !important;
}
html[data-theme="dark"] .luxury-filter-strip {
  background: #171513 !important;
  border-color: rgba(212, 182, 120, 0.28) !important;
}

/* Reviews section */
html[data-theme="dark"] #home-reviews,
html[data-theme="dark"] .reviews-home,
html[data-theme="dark"] .review-card,
html[data-theme="dark"] .rv-card {
  background: var(--k-surface) !important;
  border-color: var(--k-border) !important;
  color: var(--k-text) !important;
}
html[data-theme="dark"] #home-reviews h2,
html[data-theme="dark"] .reviews-home h2 {
  color: var(--k-text) !important;
}
html[data-theme="dark"] #home-reviews p,
html[data-theme="dark"] .reviews-home p {
  color: var(--k-text-muted) !important;
}
html[data-theme="dark"] #home-reviews a,
html[data-theme="dark"] .reviews-home a {
  color: var(--k-gold-bright) !important;
}

/* Form inputs, selects, custom dropdowns inside modals/checkout */
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not(#header-search):not(#mobile-search),
html[data-theme="dark"] textarea,
html[data-theme="dark"] select:not(.lux-select),
html[data-theme="dark"] .msel-light .msel-btn {
  background-color: var(--k-surface-2) !important;
  border-color: var(--k-border) !important;
  color: var(--k-text) !important;
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: var(--k-text-muted) !important;
}
html[data-theme="dark"] .msel-list,
html[data-theme="dark"] .msel-pop {
  background: var(--k-surface) !important;
  border-color: var(--k-border) !important;
  color: var(--k-text) !important;
}
html[data-theme="dark"] .msel-opt:hover,
html[data-theme="dark"] .msel-opt[aria-selected="true"] {
  background: var(--k-surface-3) !important;
  color: var(--k-gold-bright) !important;
}

/* Modals, Cart Drawer, Checkout, Virtual Try-On */
html[data-theme="dark"] #product-modal > div,
html[data-theme="dark"] #checkout-modal > div,
html[data-theme="dark"] #room-modal > div,
html[data-theme="dark"] #cart-drawer > div,
html[data-theme="dark"] #info-modal > div,
html[data-theme="dark"] #collections-modal > div,
html[data-theme="dark"] #callback-modal > div {
  background: var(--k-surface) !important;
  border-color: rgba(212, 182, 120, 0.32) !important;
  color: var(--k-text) !important;
}
html[data-theme="dark"] #product-modal .sticky,
html[data-theme="dark"] #checkout-modal .sticky,
html[data-theme="dark"] #room-modal .sticky,
html[data-theme="dark"] #cart-drawer .sticky {
  background: rgba(26, 24, 22, 0.96) !important;
  border-color: var(--k-border) !important;
}
html[data-theme="dark"] .quick-toggle {
  background: var(--k-surface-2) !important;
  border-color: rgba(212, 182, 120, 0.45) !important;
  color: var(--k-gold-bright) !important;
}

/* AI Assistant Chat Window (#ai-chat-window.mc) */
html[data-theme="dark"] #ai-chat-window.mc {
  background: var(--k-surface) !important;
  border-color: rgba(212, 182, 120, 0.4) !important;
  color: var(--k-text) !important;
}
html[data-theme="dark"] .mc-body {
  background-color: #141210 !important;
  background-image: radial-gradient(rgba(212, 182, 120, 0.08) 1px, transparent 1px) !important;
}
html[data-theme="dark"] .mc-row.bot .mc-b {
  background: var(--k-surface-2) !important;
  color: var(--k-text) !important;
}
html[data-theme="dark"] .mc-row.me .mc-b {
  background: #2D261B !important;
  color: #F6EFE2 !important;
}
html[data-theme="dark"] .mc-p b {
  color: var(--k-gold-bright) !important;
}
html[data-theme="dark"] .mc-b a {
  color: var(--k-gold-bright) !important;
}
html[data-theme="dark"] .mc-b a.mc-lnk {
  background: #2B241A !important;
  border-color: rgba(212, 182, 120, 0.4) !important;
  color: var(--k-gold-bright) !important;
}
html[data-theme="dark"] .mc-q,
html[data-theme="dark"] .mc-quote {
  background: rgba(212, 182, 120, 0.1) !important;
  color: var(--k-text-2) !important;
}
html[data-theme="dark"] .mc-meta {
  color: var(--k-text-muted) !important;
}
html[data-theme="dark"] .mc-foot,
html[data-theme="dark"] .mc-channels,
html[data-theme="dark"] .mc-rec,
html[data-theme="dark"] .mc-menu,
html[data-theme="dark"] .mc-down {
  background: var(--k-surface) !important;
  border-color: var(--k-border) !important;
  color: var(--k-text) !important;
}
html[data-theme="dark"] .mc .mc-channels > * {
  background: var(--k-surface-2) !important;
  border-color: var(--k-border) !important;
  color: var(--k-text) !important;
}
html[data-theme="dark"] .mc-bar textarea {
  background: var(--k-surface-2) !important;
  border-color: var(--k-border) !important;
  color: var(--k-text) !important;
}
html[data-theme="dark"] .mc-bar textarea:focus {
  border-color: var(--k-gold) !important;
  background: #1F1C19 !important;
}
html[data-theme="dark"] .mc-ibtn {
  color: var(--k-text-muted) !important;
}
html[data-theme="dark"] .mc-ibtn:hover,
html[data-theme="dark"] .mc-menu button:hover {
  background: var(--k-surface-2) !important;
}

/* SSR Landing Pages (/kovry/*), Product Pages (/catalog/*), Order Page */
html[data-theme="dark"] main h1,
html[data-theme="dark"] main h2,
html[data-theme="dark"] footer b {
  color: var(--k-text) !important;
}
html[data-theme="dark"] .lead,
html[data-theme="dark"] .guide p,
html[data-theme="dark"] .meta-bar,
html[data-theme="dark"] .description,
html[data-theme="dark"] main p {
  color: var(--k-text-2) !important;
}
html[data-theme="dark"] ul.grid li a,
html[data-theme="dark"] table,
html[data-theme="dark"] .trust,
html[data-theme="dark"] .sizes li {
  background: var(--k-surface) !important;
  border-color: var(--k-border) !important;
  color: var(--k-text) !important;
}
html[data-theme="dark"] td {
  border-color: var(--k-border-soft) !important;
}
html[data-theme="dark"] td:first-child,
html[data-theme="dark"] ul.grid li .m,
html[data-theme="dark"] main nav,
html[data-theme="dark"] .links {
  color: var(--k-text-muted) !important;
}
html[data-theme="dark"] .cta,
html[data-theme="dark"] .button {
  background: var(--k-gold) !important;
  color: #161311 !important;
}
html[data-theme="dark"] .cta.sec,
html[data-theme="dark"] .button.sec {
  background: var(--k-surface-2) !important;
  color: var(--k-text) !important;
  border-color: var(--k-border) !important;
}

/* Order & Reviews pages dark rules */
html[data-theme="dark"] .card,
html[data-theme="dark"] .review-controls,
html[data-theme="dark"] .review-nav,
html[data-theme="dark"] .review-footer {
  background: var(--k-surface) !important;
  border-color: var(--k-border) !important;
  color: var(--k-text) !important;
}
html[data-theme="dark"] .item { border-color: var(--k-border-soft) !important; }
html[data-theme="dark"] .item a,
html[data-theme="dark"] .review-nav a,
html[data-theme="dark"] .review-footer a { color: var(--k-text) !important; }
html[data-theme="dark"] .muted,
html[data-theme="dark"] .sub,
html[data-theme="dark"] .review-meta { color: var(--k-text-muted) !important; }
html[data-theme="dark"] .back { color: var(--k-gold-bright) !important; }

/* ==================== CARPET PHOTO COLOR FIDELITY ==================== */
/* Never dim, tint, invert, or filter carpet photos in dark mode */
html[data-theme="dark"] .rug-card-arch-media,
html[data-theme="dark"] ul.grid li img,
html[data-theme="dark"] .gallery img,
html[data-theme="dark"] #co-items-summary img {
  background-color: var(--k-photo-bg) !important;
}
html[data-theme="dark"] img:not(.photo-fill),
html[data-theme="dark"] canvas {
  filter: none !important;
}
html[data-theme="dark"] .rug-card img,
html[data-theme="dark"] .gallery img,
html[data-theme="dark"] #pm-swipe-area img,
html[data-theme="dark"] #lightbox-modal img,
html[data-theme="dark"] #co-items-summary img,
html[data-theme="dark"] ul.grid li img {
  opacity: 1 !important;
  mix-blend-mode: normal !important;
}
