/* =======================================================================
   WP COLORING — FULL UI STYLESHEET (v1.8 - Sửa lỗi xung đột Theme Flatsome)
   ======================================================================= */

/* ========================== 0) CSS RESET (nhẹ) ========================== */
button {
  margin-bottom: 0px !important;
}
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Inter,
    "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
  color: #1e293b;
  background: #f7f9fc;
}
img,
svg,
video,
canvas {
  display: block;
  max-width: 100%;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}
:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.45);
  outline-offset: 2px;
}
[hidden] {
  display: none !important;
}

/* ====================== 1) BASE VARIABLES & THEME ====================== */
:root {
  /* Surfaces */
  --bg: #f0f4f8;
  --panel: #ffffff;
  --panel-2: #fbfdff;
  --panel-muted: #f7f9fc;

  /* Lines & shadows */
  --stroke: #e0e7ff;
  --stroke-2: #e6ebf2;
  --ring: rgba(79, 70, 229, 0.18);
  --ring-strong: #4f46e5;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.08);

  /* Texts */
  --text: #1e293b;
  --muted: #64748b;

  /* Accent */
  --accent: #3b82f6;

  /* Palette sizes (PC defaults) */
  --swatch-size: 40px;
  --swatch-inner: 24px;

  /* Action sizes (PC defaults) */
  --action-size: 60px;
  --action-radius: 14px;
  --action-font: 30px;

  /* Canvas */
  --canvas-radius: 12px;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --panel: #0b1220;
    --panel-2: #0d1526;
    --panel-muted: #0e182b;
    --stroke: #23314e;
    --stroke-2: #1e2b45;
    --ring: rgba(99, 102, 241, 0.35);
    --ring-strong: #818cf8;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

/* ========================= 2) SHELL & GRID ========================= */
.wp-coloring-shell {
  width: 100%;
  max-width: 1200px;
  margin-inline: auto;
  padding: 16px;
  box-sizing: border-box;
  background: transparent;
}
.wp-coloring-grid {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 100px;
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) {
  .wp-coloring-grid{ grid-template-columns:1fr !important; gap:12px; } 
  .wp-coloring-sidebar.right, .wp-coloring-sidebar.left{ display:none !important; }
}

/* ====================== 3) SIDEBARS (PC) ====================== */
.wp-coloring-sidebar {
  border: 1px solid var(--stroke);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px;
  /* position: relative; */
  top: 155px;
}
.wp-coloring-sidebar.left {
  width: 120px;
}
.wp-coloring-sidebar.right {
  width: 100px;
}

/* ====================== 4) PALETTE (PC + MOBILE) ====================== */
.palette-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(44px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 2px;
  list-style: none;
}
.palette-btn {
  inline-size: var(--swatch-size);
  block-size: var(--swatch-size);
  border-radius: 50%;
  border: 1px solid var(--stroke-2);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.05s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.palette-btn::before {
  content: "";
  inline-size: var(--swatch-inner);
  block-size: var(--swatch-inner);
  border-radius: 50%;
  background: var(--clr);
}
.palette-btn:hover {
  border-color: var(--ring-strong);
  box-shadow: 0 0 0 3px var(--ring);
}
.palette-btn:focus-visible {
  outline: none;
  border-color: var(--ring-strong);
  box-shadow: 0 0 0 4px var(--ring);
}
.palette-btn.active {
  border-color: #000;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}

/* === SỬA LỖI XUNG ĐỘT FLATSOME: MOBILE PALETTE === */
.mobile-palette {
  display: flex;
  gap: 8px;
  padding: 8px;
  margin: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(
    to right,
    transparent 0%,
    black 20px,
    black calc(100% - 20px),
    transparent 100%
  );
  mask-image: linear-gradient(
    to right,
    transparent 0%,
    black 20px,
    black calc(100% - 20px),
    transparent 100%
  );
}
.mobile-palette::-webkit-scrollbar {
  display: none;
}

.wp-coloring-shell .mobile-palette .palette-btn {
  padding: 0 !important;
  margin: 0 !important;
  line-height: 1 !important;
  text-align: center !important;
  text-transform: none !important;
  flex-shrink: 0;
  aspect-ratio: 1 / 1;
  width: var(--swatch-size, 40px) !important;
  height: var(--swatch-size, 40px) !important;
  min-width: var(--swatch-size, 40px) !important;
  max-width: var(--swatch-size, 40px) !important;
  display: grid !important;
  place-items: center !important;
}
.wp-coloring-shell .mobile-palette .palette-btn::before {
  width: var(--swatch-inner, 24px) !important;
  height: var(--swatch-inner, 24px) !important;
}

.palette-btn-picker {
    position: relative; /* Quan trọng: Để input có thể định vị tuyệt đối bên trong */
    overflow: hidden;
}

.palette-btn-picker::before {
  background: conic-gradient(
    from 180deg at 50% 50%,
    #ff0000,
    #ff7f00,
    #ffff00,
    #00ff00,
    #0000ff,
    #4b0082,
    #9400d3,
    #ff0000
  );
  background-color: var(--clr);
  background-image: var(
    --clr-bg,
    conic-gradient(
      from 180deg at 50% 50%,
      #ff0000,
      #ff7f00,
      #ffff00,
      #00ff00,
      #0000ff,
      #4b0082,
      #9400d3,
      #ff0000
    )
  );
}

.palette-btn-picker .cl-input {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    
    /* Làm cho nó trong suốt và có độ ưu tiên nhấp chuột cao */
    opacity: 0 !important;
    cursor: pointer !important;
    z-index: 5 !important; /* Cao hơn các thành phần khác trong nút */
}

.palette-btn-picker input[type="color"] {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}
.palette-btn-picker.active::before {
  background-image: none;
  background-color: var(--clr);
}
@keyframes pulse-ring {
  0% {
    box-shadow: inset 0 0 0 1px white,
      0 0 0 0px var(--accent, rgba(59, 130, 246, 0.7));
  }
  100% {
    box-shadow: inset 0 0 0 1px white, 0 0 0 5px rgba(59, 130, 246, 0);
  }
}
.palette-btn-picker.active {
  border: 2px solid var(--accent, #3b82f6);
  box-shadow: inset 0 0 0 1px white;
  animation: pulse-ring 1.5s infinite cubic-bezier(0.215, 0.61, 0.355, 1);
}
.palette-btn-picker.active:hover {
  animation-play-state: paused;
}

/* ====================== 5) MAIN / CANVAS ====================== */
.wp-coloring-main {
  border: 1px solid var(--stroke);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.wp-coloring-canvas-outer {
  width: 100%;
  position: relative;
  border: 1px dashed var(--stroke);
  border-radius: var(--canvas-radius);
  background: #fff;
  overflow: hidden;
  touch-action: none;
  aspect-ratio: var(--canvas-aspect-ratio, 3 / 4);
}
.wp-coloring-status {
  text-align: center;
  color: var(--muted);
  font-weight: 500;
  padding: 8px;
  min-height: 20px;
}
.bg-canvas,
.paint-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.paint-canvas {
  mix-blend-mode: multiply;
}

/* ====================== 6) ACTIONS (SIDEBARS & MOBILE) ====================== */
.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.action-btn {
  inline-size: var(--action-size);
  block-size: var(--action-size);
  border-radius: var(--action-radius);
  border: 1px solid var(--stroke-2);
  background-color: var(--panel, #fff);
  color: var(--text, #1e293b);
  display: grid;
  place-items: center;
  font-size: var(--action-font);
  /* line-height: 1; */
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.action-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  background-color: var(--accent);
}
.action-btn:active {
  transform: translateY(0);
}
.action-btn.active {
  background-color: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 3px var(--ring);
}
.action-btn > * {
  background: none !important;
  padding: 0 !important;
  margin: 0 !important;
  display: block !important;
}

.wp-coloring-shell .action-btn svg {
  width: var(--action-font); /* Chiều rộng bằng kích thước font */
  height: var(--action-font); /* Chiều cao bằng kích thước font */
  /* Đảm bảo màu sắc icon tuân theo màu chữ của nút */
  stroke: currentColor; 
}
/* QUAN TRỌNG: Đảm bảo SVG thay đổi màu khi nút được active hoặc hover */
.wp-coloring-shell .action-btn:hover svg {
    stroke: var(--accent);
}
.wp-coloring-shell .action-btn.active svg {
    stroke: #fff;
}
/* ====================== 7) MOBILE COMBINED SIDEBAR ====================== */
.wp-coloring-mobile-sidebar {
  display: none;
}
@media (max-width: 900px) {
 .wp-coloring-shell > .wp-coloring-mobile-sidebar {
    display: flex !important; /* Ép hiển thị trên mobile */
    border-top: 1px solid var(--stroke); padding-top: 12px; margin-top: 12px;
    flex-direction: column; gap: 12px;
  }
}
.mobile-actions {
  display: flex;
  gap: 8px;
  padding: 4px;
  overflow-x: auto;
}
.wp-coloring-shell .mobile-actions .action-btn {
  padding: 0 !important;
  margin: 0 !important;
  line-height: 1 !important;
  text-transform: none !important;
  flex-shrink: 0;
  inline-size: 50px !important;
  block-size: 50px !important;
  min-width: 50px !important;
  font-size: 24px !important;
  border-radius: 12px !important;
  display: grid !important;
  place-items: center !important;
}
.wp-coloring-shell .mobile-actions .action-btn > * {
  line-height: 1 !important;
  height: auto !important;
  width: auto !important;
}

/* ====================== 8) UTILITIES & STATES ====================== */
.wp-coloring-error {
  color: #dc2626;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* ====================== 9) PRINT STYLES ====================== */
@media print {
  body {
    background: #fff;
  }
  .wp-coloring-shell {
    max-width: 100%;
    padding: 0;
  }
  .wp-coloring-sidebar,
  .wp-coloring-mobile-sidebar,
  .topbar,
  .actions {
    display: none !important;
  }
  .wp-coloring-main {
    border: none;
    box-shadow: none;
    padding: 0;
  }
  .wp-coloring-canvas-outer {
    border: none;
    border-radius: 0;
  }
  .wp-coloring-canvas-outer > canvas {
    width: 100% !important;
    height: auto !important;
  }
}

/* ====================== 10) PICKER SHORTCODE STYLES ====================== */
.wp-coloring-picker .thumb-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 96px;
  gap: 8px;
  overflow-x: auto;
  padding: 6px;
  scrollbar-width: none;
}
.wp-coloring-picker .thumb-grid::-webkit-scrollbar {
  display: none;
}
.wp-coloring-picker .thumb {
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  border: 1px solid #e6ebf2;
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.15s;
}
.wp-coloring-picker .thumb:hover {
  box-shadow: 0 0 0 3px var(--ring);
}
.wp-coloring-picker .thumb.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}
.wp-coloring-picker .thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

button {
  margin-right: 0px !important;
  padding: 0px !important;
}