/* ==========================================================================
   KISHWOOD design system — shared by the admin panel and the storefront.
   Plain CSS with tokens (no build step). Loaded AFTER admin.css / shop.css.
   Colours come from Settings > Appearance (preset or custom) via --primary, --secondary, --accent, --g1, --g2.
   ========================================================================== */
/* Theme colours (--primary, --primary-600, --primary-soft, --g1/--g2, --bg, --surface, --surface-2, --border, --text, --text-muted, --ink)
   are emitted by App\Support\Theme::css() for the selected theme + neutral set. The :where() block is only a safety fallback. */
:where(:root) { --primary: #1f61c4; --primary-600: #1b57b0; --primary-soft: #e8f0fc; --accent: #1f61c4; --secondary: #5b6b82; --g1: #3d8ee8; --g2: #2a4fc0;
    --bg: #f3f5f8; --surface: #fff; --surface-2: #eceff3; --border: #d9dee6; --text: #17202c; --text-muted: #556070; --muted: #556070; --ink: #101722; }
:root {
    --success: #1a7f4b; --danger: #c0392b; --warn: #a96412; --info: #2563b8; --on-primary: #fff;
    --g1d: var(--primary-600); --g2d: var(--g2);
    --accent-gradient: linear-gradient(135deg, var(--g1), var(--g2));
    --grad: var(--accent-gradient);
    --grad-btn: linear-gradient(135deg, var(--primary-600), var(--g2));
    --radius-sm: 4px; --radius: 8px; --radius-lg: 12px; --r-sm: var(--radius); --r-lg: var(--radius-lg);
    --sh-1: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.04);
    --sh-2: 0 4px 8px -2px rgba(16,24,40,.08), 0 14px 28px -6px rgba(16,24,40,.16);
    --ring: color-mix(in srgb, var(--primary) 28%, transparent);
    --font-main: "IRANSans", Vazirmatn, "Segoe UI", Tahoma, system-ui, sans-serif;
    --pad: 20px; --row-y: 11px; --gap: 16px;
    --control-h: 44px; --ch: var(--control-h); --control-fs: .95rem; --control-px: 12px; --label-fs: .85rem;
}
[data-density="compact"] { --pad: 14px; --row-y: 6px; --gap: 12px; --control-h: 36px; }
[data-theme="dark"] { --sh-1: 0 1px 2px rgba(0,0,0,.5); --sh-2: 0 14px 30px rgba(0,0,0,.6); }
html { scroll-behavior: smooth; }
body, button, input, select, textarea { font-family: var(--font-main); }
body { background: var(--bg); color: var(--text); transition: background-color .25s, color .25s; }
::selection { background: color-mix(in srgb, var(--g1) 35%, transparent); }
:focus-visible { outline: 2px solid var(--g1); outline-offset: 2px; border-radius: var(--radius-sm); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; } }

/* ---- icons ---- */
.ic { width: 1.2em; height: 1.2em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.2em; }
[dir="rtl"] .ic.flip, [dir="rtl"] .btn .ic-arrow { transform: scaleX(-1); }
.illus { width: 100%; height: auto; display: block; }

/* ---- buttons ---- */
.btn { position: relative; overflow: hidden; border-radius: var(--radius); font-weight: 600; transition: transform .12s, box-shadow .2s, background .2s, border-color .2s, filter .2s; }
.btn:active { transform: translateY(1px) scale(.99); }
.btn.primary, .btn.cta { background: var(--grad-btn); border-color: transparent; color: #fff; box-shadow: 0 1px 2px rgba(16,24,40,.18); }
.btn.primary:hover, .btn.cta:hover { filter: brightness(1.08); box-shadow: 0 4px 12px color-mix(in srgb, var(--primary-600) 35%, transparent); background: var(--grad-btn); }
.btn.soft { background: var(--primary-soft); border-color: transparent; color: var(--primary); }

.btn.outline { background: transparent; border-color: var(--primary); color: var(--primary); }
.btn.icon { width: 40px; height: 40px; padding: 0; border-radius: var(--radius); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn-ripple { position: absolute; border-radius: 50%; background: rgba(255,255,255,.45); transform: scale(0); animation: kwRipple .6s linear; pointer-events: none; }
@keyframes kwRipple { to { transform: scale(4); opacity: 0; } }

/* ---- cards, each with its own tint ---- */
.card { --tint: var(--g1); position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--sh-1); padding: var(--pad); }
.card > h3:first-child { display: flex; align-items: center; gap: 10px; border-bottom: 0; padding-bottom: 0; margin-bottom: 14px; }
.card > h3:first-child::before { content: ""; width: 3px; height: 16px; border-radius: var(--radius-sm); background: var(--primary); }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .table-scroll, .card.flush { overflow-x: auto; }

/* ---- badges & status pills ---- */
.badge, .tag { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600; padding: 2px 9px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--muted) 14%, transparent); color: var(--muted); line-height: 1.7; }
.badge::before, .tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.accent, .tag.pending, .tag.partially_paid { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.badge.ok, .tag.paid { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.badge.bad, .tag.cancelled, .tag.refunded { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge.info { background: color-mix(in srgb, var(--info) 15%, transparent); color: var(--info); }

/* ---- forms: ONE control height / font / radius / padding / label style for the whole project ---- */
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=hidden]):not([type=file]):not([type=image]):not([type=submit]):not([type=button]), select {
    height: var(--ch); padding: 0 var(--control-px); font-size: var(--control-fs); line-height: 1.4; border-radius: var(--radius); background-color: var(--surface); color: var(--text);
    border: 1px solid var(--border); transition: border-color .15s, box-shadow .15s, background-color .15s; }
textarea { min-height: 88px; padding: 10px var(--control-px); font-size: var(--control-fs); line-height: 1.6; border-radius: var(--radius); background: var(--surface); color: var(--text); border: 1px solid var(--border); transition: border-color .15s, box-shadow .15s; }
select { appearance: none; -webkit-appearance: none; padding-inline-end: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23778' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-size: 16px; background-position: right 11px center; }
[dir="rtl"] select { background-position: left 11px center; }
select[multiple], select[size] { height: auto; padding: 6px; background-image: none; }
input[type=file] { height: auto; min-height: var(--ch); padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text-muted); font-size: var(--control-fs); line-height: calc(var(--ch) - 2px); width: 100%; }
input[type=file]::file-selector-button { height: calc(var(--ch) - 2px); margin: 0; margin-inline-end: 12px; padding: 0 14px; border: 0; border-inline-end: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
input[type=color] { height: var(--ch); width: 56px; padding: 4px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
input:hover:not(:disabled):not([type=checkbox]):not([type=radio]), select:hover, textarea:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
input:disabled, select:disabled, textarea:disabled { opacity: .6; background-color: var(--surface-2); cursor: not-allowed; }
::placeholder { color: color-mix(in srgb, var(--text-muted) 70%, transparent); }
label:not(.check):not(.pill):not(.swatch):not(.opt):not(.preset) > span:first-child:not(.field-icon), .field > label { display: block; font-size: var(--label-fs); font-weight: 600; line-height: 20px; margin-bottom: 6px; color: var(--text); }
label.check { display: flex; align-items: center; gap: 10px; min-height: var(--ch); font-size: var(--control-fs); }
label.check > span { font-weight: 500; }
input[type=checkbox]:not(.sw), input[type=radio] { width: 18px; height: 18px; accent-color: var(--primary); flex: none; margin: 0; }
.field-icon { position: relative; display: block; }
.field-icon > .ic { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.field-icon > input { padding-inline-start: 38px; }
input[aria-invalid="true"], .has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
/* switch: <label class="check switch"><input type="checkbox">…</label> (also every checkbox inside a Settings group) */
label.switch input[type=checkbox], .settings-group label.check input[type=checkbox] { appearance: none; -webkit-appearance: none; width: 38px; height: 22px; border-radius: 11px; background: color-mix(in srgb, var(--text-muted) 40%, var(--surface)); position: relative; cursor: pointer; transition: background .2s; flex: none; border: 0; }
label.switch input[type=checkbox]::after, .settings-group label.check input[type=checkbox]::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: inset-inline-start .2s; }
label.switch input[type=checkbox]:checked, .settings-group label.check input[type=checkbox]:checked { background: var(--primary); }
label.switch input[type=checkbox]:checked::after, .settings-group label.check input[type=checkbox]:checked::after { inset-inline-start: 19px; }
/* buttons share the control height; compact inside tables / pagination / toolbars of chips */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--ch); padding: 0 16px; font-size: var(--control-fs); line-height: 1.5; text-align: center; vertical-align: middle; white-space: nowrap; }
.btn.icon { width: var(--ch); min-width: var(--ch); padding: 0; }
td, th, .pagination, .btn.sm, .btn-sm, .btn.small, .card-head, .row-actions { --ch: 34px; }
.topbar { --ch: 38px; }
/* 12-column grid with standard widths; rows align controls on their bottom edge so labels of different length never push a field */
.row12, .grid.two, .grid.three, .grid.four, .form .two, .filters-form .two { display: grid; gap: var(--gap); align-items: end; }
.row12 { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.grid.two, .form .two { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); } .grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.c12 { grid-column: span 12; } .c8 { grid-column: span 8; } .c6 { grid-column: span 6; } .c4 { grid-column: span 4; } .c3 { grid-column: span 3; } .wide { grid-column: 1 / -1; }
@media (max-width: 760px) { .row12 > *, .grid.two, .grid.three, .grid.four { grid-column: span 12; grid-template-columns: 1fr; } }
/* reserved helper/error slot: fields without hint text still keep the line so neighbours stay level */
.grid.two > label:not(.check):not(.wide):not(:has(small))::after, .grid.three > label:not(.check):not(.wide):not(:has(small))::after, .form .two > label:not(:has(small))::after { content: ""; display: block; min-height: 1.3em; }
.field { display: flex; flex-direction: column; min-width: 0; }
.field > label { margin-bottom: 6px; }
.field .hint, .field .err { display: block; min-height: 1.3em; margin-top: 4px; font-size: .78rem; line-height: 1.3; color: var(--text-muted); }
.field .err { color: var(--danger); }
.field .unit { display: flex; gap: 8px; align-items: stretch; }
.field .unit > .btn { flex: none; }

/* ---- scroll reveal / counters / skeleton ---- */
.reveal { opacity: 0; transform: translateY(22px); transition: opacity .7s cubic-bezier(.2,.7,.2,1), transform .7s cubic-bezier(.2,.7,.2,1); transition-delay: var(--d, 0s); }
.reveal.in { opacity: 1; transform: none; }
.skeleton { position: relative; overflow: hidden; background: color-mix(in srgb, var(--muted) 14%, var(--surface)); border-radius: var(--radius); min-height: 14px; }
.skeleton::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, color-mix(in srgb, #fff 45%, transparent), transparent); transform: translateX(-100%); animation: kwShimmer 1.3s infinite; }
[dir="rtl"] .skeleton::after { animation-direction: reverse; }
@keyframes kwShimmer { to { transform: translateX(100%); } }

/* ---- modal / confirm / dropdown ---- */
.kw-modal { position: fixed; inset: 0; z-index: 3000; display: grid; place-items: center; padding: 20px; background: rgba(20,14,10,.5); backdrop-filter: blur(4px); animation: kwFade .18s ease; }
.kw-modal[hidden] { display: none; }
.kw-dialog { width: min(440px, 100%); background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--sh-2); padding: 26px; text-align: center; animation: kwPop .22s cubic-bezier(.2,.8,.2,1.1); }
.kw-dialog .dlg-ic { width: 56px; height: 56px; border-radius: var(--radius-lg); margin: 0 auto 14px; display: grid; place-items: center; background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); font-size: 1.6rem; }
.kw-dialog p { margin: 0 0 18px; color: var(--muted); }
.kw-dialog .row { display: flex; gap: 10px; justify-content: center; }
@keyframes kwFade { from { opacity: 0; } }
@keyframes kwPop { from { opacity: 0; transform: translateY(10px) scale(.96); } }
.dropdown { position: relative; }
.dropdown > .menu { position: absolute; inset-inline-end: 0; top: calc(100% + 8px); min-width: 210px; z-index: 600; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--sh-2); padding: 6px; display: none; }
.dropdown.open > .menu { display: block; animation: kwPop .16s ease; }
.dropdown .menu a, .dropdown .menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: var(--radius); color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; text-align: start; }
.dropdown .menu a:hover, .dropdown .menu button:hover { background: var(--surface-2); }
.dropdown .menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

/* ---- empty state ---- */
.empty-state { text-align: center; padding: 38px 16px; color: var(--muted); }
.empty-state .illus { max-width: 190px; margin: 0 auto 10px; }
.empty-state strong { display: block; color: var(--text); font-size: 1.05rem; margin-bottom: 4px; }

/* ---- shared decoration ---- */
.orb { display: none; }
.dots { position: absolute; width: 120px; height: 90px; background-image: radial-gradient(currentColor 1.6px, transparent 1.6px); background-size: 14px 14px; opacity: .25; pointer-events: none; }
.wave { display: block; width: 100%; height: 48px; }
.copy-btn.done { color: var(--success); }
