/* ================================================================ appearance: themes, fonts, text size
   Loaded after style.css. The look is chosen by /js/theme.js through attributes on <html>:
   data-theme = light | sepia | dark | night,  data-font = vazir | naskh | system,  --fs = text scale. */

/* ---------- text size + font ---------- */
html { font-size: calc(100% * var(--fs, 1)); -webkit-text-size-adjust: 100%; }
body { font-size: .9375rem; }
html[data-font="naskh"] { --font: "Noto Naskh Arabic", "Vazirmatn", Tahoma, serif; }
html[data-font="naskh"] body { line-height: 2; }
html[data-font="system"] { --font: Tahoma, "Segoe UI", system-ui, sans-serif; }
button, input, select, textarea { font-family: inherit; }

/* ---------- colour themes: the palette ---------- */
html[data-theme="sepia"] {
  --bg: #f0e7d3; --card: #f8f1e2; --text: #3a2f1f; --muted: #6b5c44; --border: #dccfb3;
  --danger: #a82c20; --primary-50: #ebe3d0; --accent-50: #f3e7cd; --success-50: #e3ecd6; --danger-50: #f4ddd3;
  --shadow: 0 1px 2px rgba(80,60,20,.06), 0 10px 30px rgba(80,60,20,.08);
}
html[data-theme="dark"] {
  --primary: #9ec1f0; --primary-600: #cfe1fa; --primary-50: #1b2a44; --btn-bg: #2f5a99; --btn-hover: #3a6bb3;
  --accent: #c9a56e; --accent-600: #b8935a; --accent-50: #2b2518; --gold-soft: #d8c19a;
  --danger: #e0685c; --danger-50: #3a1f1d; --success: #4cc38a; --success-50: #17301f;
  --text: #e8ebf1; --muted: #a0abbd; --border: #263042; --bg: #0e131b; --card: #161d29;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  --shadow-lg: 0 18px 50px rgba(0,0,0,.55);
}
html[data-theme="night"] {
  --primary: #e3bb77; --primary-600: #f3d49a; --primary-50: #261f14; --btn-bg: #7a5a2c; --btn-hover: #8c6a35;
  --accent: #d4a65a; --accent-600: #c0933f; --accent-50: #2a2112; --gold-soft: #d9bd8a;
  --danger: #e57a63; --danger-50: #3a221b; --success: #8fc07a; --success-50: #1f2c18;
  --text: #e9dcc4; --muted: #a89a80; --border: #2f281c; --bg: #14110d; --card: #1c1813;
  --shadow: 0 1px 2px rgba(0,0,0,.45), 0 10px 30px rgba(0,0,0,.4);
  --shadow-lg: 0 18px 50px rgba(0,0,0,.6);
}
html[data-theme="dark"], html[data-theme="night"], html[data-theme="code"], html[data-theme="sepia"] { background: var(--bg); }

/* "programmer" theme: a dark that is lighter than "dark" (like an editor's soft-dark scheme) with vivid, strong text colours */
html[data-theme="code"] {
  --primary: #7fd4ff; --primary-600: #b5e6ff; --primary-50: #34445c; --btn-bg: #2f6fb0; --btn-hover: #3777ba;
  --accent: #ffcb6b; --accent-600: #f0b94a; --accent-50: #41392a; --gold-soft: #ffd98f;
  --danger: #ff8f87; --danger-50: #4a2a2c; --success: #7ee787; --success-50: #263d2c;
  --text: #f4f7fc; --muted: #b9c4d6; --border: #4a5568; --bg: #2a303c; --card: #343c4a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.28);
  --shadow-lg: 0 18px 50px rgba(0,0,0,.45);
}
html[data-theme="code"] body { font-weight: 500; }
html[data-theme="code"] :is(h1, h2, h3, .book-card h3, .price .now, .section-head h2) { text-shadow: 0 0 .5px currentColor; }
html[data-theme="code"] :is(.cart-btn, .btn:not(.btn-ghost):not(.btn-outline):not(.btn-accent)) { background: var(--btn-bg); }
/* ---------- surfaces that were hard-coded white ---------- */
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"], [data-theme="sepia"]) :is(.site-header, .bottom-nav) { background: color-mix(in srgb, var(--card) 94%, transparent); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"], [data-theme="sepia"]) :is(input, select, textarea, .input, .qty, .btn-ghost, .hero-search, .search:focus-within) { background: var(--card); color: var(--text); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"], [data-theme="sepia"]) :is(.hero-search input) { color: var(--text); background: transparent; }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"], [data-theme="sepia"]) :is(.table th) { background: color-mix(in srgb, var(--card) 80%, var(--bg)); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"], [data-theme="sepia"]) :is(.table tr.clickable:hover td) { background: color-mix(in srgb, var(--card) 85%, var(--primary-50)); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"], [data-theme="sepia"]) :is(.invoice, .gift-row, .note-item) { background: var(--card); color: var(--text); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) :is(.feature .fi, .cat-card .ci) { background: var(--accent-50); color: var(--accent); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) :is(.btn-ghost:hover) { background: var(--primary-50); color: var(--text); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) :is(.deal-dot, .ribbon) { color: #fff; }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) ::selection { background: var(--accent-50); color: var(--accent); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) :is(img.logo, .logo img) { background: #faf7f1; border-radius: 12px; padding: 2px; }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .cover { box-shadow: inset 6px 0 8px -4px rgba(0,0,0,.45), 0 4px 12px rgba(0,0,0,.5); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) input::placeholder, :is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) textarea::placeholder { color: var(--muted); opacity: .8; }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .hero { box-shadow: 0 0 0 1px rgba(216,193,154,.18), var(--shadow); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .site-footer { background: linear-gradient(180deg, #0b111b, #070b12); }

/* ---------- comfortable focus + motion ---------- */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* ---------- the appearance control ---------- */
.look-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer; margin-inline-end: 6px; }
.look-btn:hover, .look-btn[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
.look-panel { position: fixed; z-index: 90; top: 74px; left: 16px; width: min(340px, calc(100vw - 24px)); max-height: calc(100vh - 90px); overflow: auto;
  background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg, 0 18px 50px rgba(0,0,0,.25)); padding: 16px; }
.look-panel[hidden] { display: none; }
.lk-title { font-weight: 800; font-size: 1.05rem; margin-bottom: 10px; }
.lk-group { margin-bottom: 14px; }
.lk-label { font-size: .82rem; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; }
.lk-label b { color: var(--text); }
.lk-row { display: flex; flex-wrap: wrap; gap: 6px; }
.lk-chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--text); cursor: pointer; font-size: .88rem; }
.lk-chip:hover { border-color: var(--accent); }
.lk-chip.on { border-color: var(--accent); background: var(--accent-50); color: var(--text); font-weight: 700; box-shadow: 0 0 0 1px var(--accent) inset; }
.lk-sw { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(127,127,127,.5); display: inline-block; }
.lk-sw-auto { background: linear-gradient(90deg, #fff 50%, #161d29 50%); }
.lk-sw-code { background: #2a303c; box-shadow: inset 0 0 0 3px #7fd4ff; } .lk-sw-light { background: #fff; } .lk-sw-sepia { background: #f1e5c9; } .lk-sw-dark { background: #161d29; } .lk-sw-night { background: #1c1813; box-shadow: inset 0 0 0 3px #d4a65a; }
.lk-sw-vazir, .lk-sw-naskh, .lk-sw-system { display: none; }
.lk-hint { font-size: .76rem; color: var(--muted); margin-top: 6px; }
.lk-size { align-items: center; flex-wrap: nowrap; }
.lk-btn { min-width: 44px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: transparent; color: var(--text); cursor: pointer; font-weight: 700; }
.lk-btn:hover:not(:disabled) { border-color: var(--accent); }
.lk-btn:disabled { opacity: .35; cursor: default; }
.lk-steps { flex: 1; display: flex; gap: 4px; justify-content: center; }
.lk-steps i { width: 100%; max-width: 34px; height: 6px; border-radius: 99px; background: var(--border); }
.lk-steps i.on { background: var(--accent); }
.lk-reset { width: 100%; padding: 9px; border-radius: 10px; border: 1px dashed var(--border); background: transparent; color: var(--muted); cursor: pointer; }
.lk-reset:hover { color: var(--text); border-color: var(--accent); }
@media (max-width: 720px) {
  .look-panel { top: auto; bottom: 74px; left: 12px; right: 12px; width: auto; max-height: 70vh; }
  .look-btn { width: 38px; height: 38px; }
}

/* dark themes: --primary is now the light "text" tone, so filled buttons/chips use --btn-bg */
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) :is(.btn:not(.btn-ghost):not(.btn-outline):not(.btn-accent), .cart-btn, .pagination .current, .steps span.on, .timeline .tl.done i, .book-card .add, .cat-nav a.active, .filters .cats a.active, .admin-nav a.active, .shelf-chip.on, .app-steps li::before) {
  background: var(--btn-bg); border-color: var(--btn-bg); color: #fff; }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) :is(.btn:not(.btn-ghost):not(.btn-outline):not(.btn-accent):hover, .cart-btn:hover) { background: var(--btn-hover); color: #fff; }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) :is(.lib-hero, .points-hero) { background: linear-gradient(135deg, var(--btn-bg), var(--card) 90%); color: #fff; }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .search button { background: transparent; }

/* a few more hard-coded light tones */
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"], [data-theme="sepia"]) .search { background: color-mix(in srgb, var(--card) 80%, var(--bg)); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .skeleton { background: linear-gradient(90deg, #1b2330 25%, #232d3d 50%, #1b2330 75%); background-size: 200% 100%; }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .book-card .cover-link { background: linear-gradient(180deg, color-mix(in srgb, var(--card) 85%, var(--bg)), var(--card)); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .st-paid { background: #1c2a4d; color: #9db8ff; }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .st-processing { background: #2a2145; color: #c4a6f0; }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .st-cancelled { background: #262b31; color: #a9b2bb; }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .invoice th { background: color-mix(in srgb, var(--card) 80%, var(--bg)); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .heat i, :is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .heat-legend i { background: #222a37; }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .note-item img { background: #fff; }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"], [data-theme="sepia"]) .heart { background: color-mix(in srgb, var(--card) 92%, transparent); color: var(--text); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .heart:not(.on) { box-shadow: 0 2px 8px rgba(0,0,0,.45); }


/* ---------- e-book reader: warm filter (less blue light) and the warm-night mode ---------- */
.reader.theme-night { --rd-bg: #14110d; --rd-bar: #1c1813; --rd-text: #e9dcc4; --rd-filter: invert(.88) hue-rotate(180deg) sepia(.35); }
.rd-page { filter: var(--rd-filter) sepia(var(--rd-warm, 0)) brightness(var(--rd-bright, 1)); }
.sw-night { background: #1c1813; box-shadow: inset 0 0 0 3px #d4a65a; }
.rd-set input[type="checkbox"] { width: 18px; height: 18px; vertical-align: middle; margin-inline-end: 6px; accent-color: var(--accent); }
.rd-set input[type="range"] { accent-color: var(--accent); }


/* ---------- free sample button on an e-book page: the strongest call to action next to "buy" ---------- */
.sample-btn, .sample-btn:hover { background: var(--accent); color: #1a1305; }
.sample-btn:hover { filter: brightness(1.08); }
.sample-btn::after { display: none; }
.sample-btn { margin-top: 10px; gap: 12px; justify-content: flex-start; text-align: start; min-height: 56px; border: 2px solid var(--accent-600); box-shadow: 0 6px 16px rgba(0,0,0,.12); }
.sample-btn > span:last-child { display: flex; flex-direction: column; line-height: 1.5; }
.sample-btn b { font-weight: 800; font-size: 1rem; }
.sample-btn small { font-size: .78rem; font-weight: 500; opacity: .85; }
.sample-btn .ico-lg { font-size: 1.5rem; }

/* ---------- appearance panel: header with a close button, bigger touch targets ---------- */
.lk-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.lk-head .lk-title { margin-bottom: 0; }
.lk-close { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: transparent; color: var(--text); cursor: pointer; font-size: 1rem; }
.lk-close:hover { border-color: var(--accent); }
.lk-chip { min-height: 40px; }
.lk-hint { color: var(--muted); }
@media (max-width: 720px) {
  .lk-chip { min-height: 44px; padding: 8px 14px; }
  .lk-btn { min-height: 44px; }
  .look-btn { width: 44px; height: 44px; }
  .lk-reset { min-height: 44px; }
  .look-panel { overscroll-behavior: contain; }
}

/* ---------- fixes found by the visual QA pass ---------- */
/* admin pages on phones: a 1fr grid column grows to fit its widest child (the tab bar, wide tables) and
   made the whole page scroll sideways; minmax(0, 1fr) lets the children scroll inside their own box */
@media (max-width: 900px) {
  .admin, .catalog, .two-col, .book-form, .admin-grid { grid-template-columns: minmax(0, 1fr); }
  .admin > *, .catalog > *, .two-col > * { min-width: 0; }
  .admin-nav { max-width: 100%; -webkit-overflow-scrolling: touch; }
}
/* "+ add book" lives in a .section-head whose link colour (gold) was winning over the white button text */
.section-head a.btn:not(.btn-ghost):not(.btn-outline), .section-head a.btn:not(.btn-ghost):not(.btn-outline):hover { color: #fff; }
/* the yellow notice used a dark-brown text that vanished on the dark themes */
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) .alert-warn { color: var(--accent); }

/* the little green light on the account button: you are signed in */
.online-dot { width: 9px; height: 9px; border-radius: 50%; background: #22a35a; box-shadow: 0 0 0 3px rgba(34, 163, 90, .22); flex: none; }
#userBtn { gap: 8px; }

/* ---------- e-book reader: soft paper, gentle page fade-in, calm skeleton ---------- */
.reader { --rd-paper: #fbf9f3; }
.reader.theme-sepia { --rd-paper: #f6eedb; }
.rd-page { background: var(--rd-paper); transition: filter .25s ease; }
.rd-page canvas { mix-blend-mode: multiply; opacity: 0; transition: opacity .35s ease; }
.rd-page.ready canvas { opacity: 1; }
.rd-page:not(.ready)::before { background: linear-gradient(100deg, rgba(127,127,127,.10) 30%, rgba(127,127,127,.18) 50%, rgba(127,127,127,.10) 70%); background-size: 200% 100%; }
.rd-presets button { font-size: .85rem; }
@media (prefers-reduced-motion: reduce) { .rd-page, .rd-page canvas { transition: none; } .rd-page:not(.ready)::before { animation: none; } }

/* ---------- invoice on phones: the items table was wider than the card and pushed the page sideways ---------- */
@media screen and (max-width: 720px) {
  .invoice { padding: 18px 14px; overflow-x: auto; }
  .invoice-parties { grid-template-columns: minmax(0, 1fr); }
  .invoice table { min-width: 460px; }
}

/* ---------- dark themes: text that kept its light-theme colour on a light accent, or dark-brown on dark-brown ---------- */
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) :is(.badge, .ep-format button.on) { color: var(--bg); }
:is([data-theme="dark"], [data-theme="night"], [data-theme="code"]) :is(.rd-sample, .st-pending_payment) { color: var(--accent); }
