/* ============================================================
   PROUHD · Liquid Glass theme
   Adaptive light/dark · full LTR/RTL via logical properties
   ============================================================ */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Inter", "Noto Sans Arabic", system-ui, "Segoe UI", Roboto, sans-serif;

  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --radius-pill: 999px;

  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.22);
  --pos: #30d158;
  --neg: #ff453a;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- Dark (default) ---------- */
[data-theme="dark"] {
  --bg: #04050a;
  --text: rgba(255, 255, 255, 0.96);
  --text-2: rgba(255, 255, 255, 0.62);
  --text-3: rgba(255, 255, 255, 0.4);

  --glass: rgba(255, 255, 255, 0.07);
  --glass-strong: rgba(255, 255, 255, 0.1);
  --glass-thin: rgba(255, 255, 255, 0.06);
  --glass-brd: rgba(255, 255, 255, 0.16);
  --glass-hi: rgba(255, 255, 255, 0.45);
  --field: rgba(255, 255, 255, 0.05);
  --field-brd: rgba(255, 255, 255, 0.12);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --track: rgba(255, 255, 255, 0.14);

  --aurora-a: #5e5ce6;
  --aurora-b: #bf5af2;
  --aurora-c: #64d2ff;
  --aurora-d: #ff375f;
}

/* ---------- Light ---------- */
[data-theme="light"] {
  --bg: #eef2f8;
  --text: rgba(0, 0, 0, 0.9);
  --text-2: rgba(0, 0, 0, 0.55);
  --text-3: rgba(0, 0, 0, 0.4);

  --glass: rgba(255, 255, 255, 0.55);
  --glass-strong: rgba(255, 255, 255, 0.7);
  --glass-thin: rgba(255, 255, 255, 0.5);
  --glass-brd: rgba(255, 255, 255, 0.8);
  --glass-hi: rgba(255, 255, 255, 0.95);
  --field: rgba(255, 255, 255, 0.65);
  --field-brd: rgba(0, 0, 0, 0.08);
  --shadow: 0 18px 50px rgba(60, 80, 120, 0.22);
  --track: rgba(0, 0, 0, 0.1);

  --aurora-a: #7d7bff;
  --aurora-b: #d98bff;
  --aurora-c: #7fdcff;
  --aurora-d: #ff7aa0;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  line-height: 1.45;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background 0.5s var(--ease), color 0.3s var(--ease);
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Aurora substrate (what the glass refracts) ---------- */
.aurora {
  position: fixed; inset: 0; z-index: -1; overflow: hidden; filter: saturate(1.2);
}
.blob {
  position: absolute; border-radius: 50%;
  filter: blur(70px); opacity: 0.85;
  animation: drift 26s var(--ease) infinite alternate;
}
.blob-1 { width: 46vw; height: 46vw; background: var(--aurora-a); inset-block-start: -8vw; inset-inline-start: -6vw; }
.blob-2 { width: 40vw; height: 40vw; background: var(--aurora-b); inset-block-start: 30vh; inset-inline-end: -8vw; animation-delay: -6s; }
.blob-3 { width: 38vw; height: 38vw; background: var(--aurora-c); inset-block-end: -10vw; inset-inline-start: 18vw; animation-delay: -12s; }
.blob-4 { width: 30vw; height: 30vw; background: var(--aurora-d); inset-block-start: 8vh; inset-inline-start: 40vw; animation-delay: -18s; opacity: 0.6; }
[data-theme="light"] .blob { opacity: 0.5; }

@keyframes drift {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(4vw, 5vh) scale(1.12); }
  100% { transform: translate(-3vw, -4vh) scale(0.95); }
}

/* ---------- Glass surfaces ---------- */
.glass, .glass-thin {
  position: relative;
  background: var(--glass);
  -webkit-backdrop-filter: blur(34px) saturate(180%);
  backdrop-filter: blur(34px) saturate(180%);
  border: 1px solid var(--glass-brd);
  box-shadow: var(--shadow), inset 0 1px 0 var(--glass-hi);
}
.glass-thin {
  background: var(--glass-thin);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  backdrop-filter: blur(20px) saturate(170%);
  box-shadow: inset 0 1px 0 var(--glass-hi);
}
/* top specular sheen */
.glass::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(180deg, var(--glass-hi) 0%, transparent 16%);
  opacity: 0.5; mix-blend-mode: overlay;
}

/* ---------- Shell & layout ---------- */
.shell {
  max-width: 1120px; margin-inline: auto;
  padding: clamp(16px, 3vw, 32px);
  padding-block-end: 48px;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 16px; border-radius: var(--radius-lg);
  margin-block-end: clamp(16px, 3vw, 26px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  font-weight: 800; font-size: 20px; color: #fff;
  background: linear-gradient(140deg, var(--aurora-a), var(--aurora-b));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.5), 0 6px 16px rgba(0,0,0,0.3);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 16px; letter-spacing: 0.04em; }
.brand-sub { font-size: 12px; color: var(--text-2); }

.controls { display: flex; align-items: center; gap: 10px; }
.icon-btn, .lang-btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--glass-brd); border-radius: var(--radius-pill);
  color: var(--text); cursor: pointer; font-family: inherit;
  transition: transform 0.18s var(--ease), background 0.3s var(--ease);
}
.icon-btn { width: 42px; height: 42px; justify-content: center; }
.lang-btn { height: 42px; padding-inline: 16px; font-size: 14px; font-weight: 600; }
.icon-btn:hover, .lang-btn:hover { transform: translateY(-1px); }
.icon-btn:active, .lang-btn:active { transform: scale(0.96); }

.ico-sun { display: none; }
[data-theme="light"] .ico-moon { display: none; }
[data-theme="light"] .ico-sun { display: block; }

.layout {
  display: grid; grid-template-columns: 1.08fr 0.92fr; gap: clamp(16px, 2.5vw, 24px);
  align-items: start;
}
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
}

.panel { border-radius: var(--radius-xl); padding: clamp(18px, 3vw, 28px); }

/* ---------- Fields ---------- */
.field { margin-block-end: 22px; }
.field:last-child { margin-block-end: 0; }
.field-label {
  display: block; font-size: 13px; font-weight: 600; color: var(--text-2);
  margin-block-end: 10px; letter-spacing: 0.02em;
}
.field-label .unit, .input-cap i { color: var(--text-3); font-style: normal; font-weight: 500; }
.row-between { display: flex; align-items: baseline; justify-content: space-between; }

/* Segmented control */
.segmented {
  position: relative; display: flex; gap: 4px; padding: 4px;
  background: var(--field); border: 1px solid var(--field-brd);
  border-radius: var(--radius-md);
}
.seg-indicator {
  position: absolute; inset-block: 4px; inset-inline-start: 4px;
  width: calc((100% - 8px) / var(--seg-count, 2));
  transform: translateX(calc(var(--seg-i, 0) * 100%));
  background: var(--glass-strong);
  border: 1px solid var(--glass-brd); border-radius: 12px;
  box-shadow: inset 0 1px 0 var(--glass-hi), 0 4px 12px rgba(0,0,0,0.18);
  transition: transform 0.32s var(--ease);
}
[dir="rtl"] .seg-indicator { transform: translateX(calc(var(--seg-i, 0) * -100%)); }
.seg-opt {
  position: relative; flex: 1; z-index: 1; padding: 10px 8px;
  background: none; border: 0; border-radius: 12px; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--text-2); transition: color 0.25s var(--ease);
}
.seg-opt.active { color: var(--text); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-width: 46px; padding: 9px 14px; cursor: pointer; font-family: inherit;
  font-size: 14px; font-weight: 600; color: var(--text-2);
  background: var(--field); border: 1px solid var(--field-brd); border-radius: var(--radius-sm);
  transition: all 0.22s var(--ease);
}
.chip:hover { color: var(--text); }
.chip.active {
  color: #fff; border-color: transparent;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 70%, var(--aurora-b)));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), 0 6px 16px var(--accent-soft);
}

/* Number inputs */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (max-width: 460px) { .grid-3 { grid-template-columns: 1fr 1fr; } }

.input-wrap {
  display: flex; flex-direction: column-reverse; gap: 6px;
  background: var(--field); border: 1px solid var(--field-brd);
  border-radius: var(--radius-md); padding: 10px 12px;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.input-cap { font-size: 11px; color: var(--text-2); font-weight: 600; letter-spacing: 0.02em; }
.num {
  width: 100%; border: 0; background: none; outline: none; color: var(--text);
  font-family: inherit; font-size: 19px; font-weight: 600;
}
.num::-webkit-outer-spin-button, .num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* Slider */
.profit-readout {
  font-size: 22px; font-weight: 800;
  background: linear-gradient(120deg, var(--accent), var(--aurora-b));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.slider {
  -webkit-appearance: none; appearance: none; width: 100%; height: 26px;
  background: none; cursor: pointer; margin-block: 6px;
}
.slider::-webkit-slider-runnable-track {
  height: 8px; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) var(--fill, 30%), var(--track) var(--fill, 30%));
}
.slider::-moz-range-track { height: 8px; border-radius: 999px; background: var(--track); }
.slider::-moz-range-progress { height: 8px; border-radius: 999px; background: var(--accent); }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 24px; height: 24px; margin-block-start: -8px;
  border-radius: 50%; background: #fff; border: 1px solid rgba(0,0,0,0.1);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3), inset 0 1px 0 #fff;
}
.slider::-moz-range-thumb {
  width: 24px; height: 24px; border: 1px solid rgba(0,0,0,0.1); border-radius: 50%;
  background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.hint { font-size: 11.5px; color: var(--text-3); margin-block-start: 6px; }

/* Switch list */
.switch-list {
  background: var(--field); border: 1px solid var(--field-brd);
  border-radius: var(--radius-md); overflow: hidden;
}
.switch-row {
  display: flex; align-items: center; gap: 10px; padding: 13px 14px; cursor: pointer;
  border-block-end: 1px solid var(--field-brd); font-size: 14.5px; font-weight: 500;
}
.switch-row:last-child { border-block-end: 0; }
.switch-row .adj {
  margin-inline-start: auto; font-size: 12px; font-weight: 700; color: var(--pos);
}
.switch-row .adj.neg { color: var(--neg); }
.switch-row input { display: none; }
.switch {
  position: relative; width: 46px; height: 28px; flex: none; border-radius: 999px;
  background: var(--track); transition: background 0.28s var(--ease);
}
.switch::after {
  content: ""; position: absolute; inset-block-start: 3px; inset-inline-start: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3); transition: transform 0.28s var(--ease);
}
.switch-row input:checked + .switch { background: var(--pos); }
.switch-row input:checked + .switch::after { transform: translateX(18px); }
[dir="rtl"] .switch-row input:checked + .switch::after { transform: translateX(-18px); }

/* Advanced */
.advanced {
  margin-block-start: 6px; border-block-start: 1px solid var(--field-brd); padding-block-start: 16px;
}
.advanced summary {
  display: flex; align-items: center; justify-content: space-between; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--text-2); list-style: none;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary svg { transition: transform 0.25s var(--ease); }
.advanced[open] summary svg { transform: rotate(180deg); }
.adv-grid { margin-block-start: 14px; }

/* ---------- Result panel (signature) ---------- */
.result {
  border-radius: var(--radius-xl); padding: clamp(20px, 3vw, 28px);
  position: sticky; inset-block-start: 20px; overflow: hidden;
}
.result-head { display: flex; align-items: center; justify-content: space-between; margin-block-end: 18px; }
.result-title { font-size: 14px; font-weight: 700; color: var(--text-2); letter-spacing: 0.02em; }
.source-badge {
  font-size: 11px; font-weight: 700; padding: 5px 11px; border-radius: 999px;
  color: var(--text-2); background: var(--field); border: 1px solid var(--field-brd);
}
.source-badge.live {
  color: var(--pos);
  background: color-mix(in srgb, var(--pos) 14%, transparent);
  border-color: color-mix(in srgb, var(--pos) 35%, transparent);
}

.total-block {
  text-align: center; padding: 22px 16px; margin-block-end: 16px;
  border-radius: var(--radius-lg);
  background: linear-gradient(160deg, var(--accent-soft), transparent 70%);
  border: 1px solid var(--field-brd);
}
.total-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.08em; }
.total-amount {
  display: flex; align-items: baseline; justify-content: center; gap: 8px;
  margin-block: 6px; font-weight: 800; line-height: 1;
}
.total-amount #totalPrice {
  font-size: clamp(40px, 8vw, 56px); letter-spacing: -0.02em;
  background: linear-gradient(120deg, var(--accent), var(--aurora-b) 90%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.total-amount.flash #totalPrice { animation: pop 0.4s var(--ease); }
@keyframes pop { 0% { transform: scale(0.94); } 60% { transform: scale(1.03); } 100% { transform: scale(1); } }
.cur { font-size: 17px; font-weight: 700; color: var(--text-2); }
.per-unit { font-size: 13px; color: var(--text-2); }

.breakdown { display: flex; flex-direction: column; }
.bd-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 2px; font-size: 14px; border-block-end: 1px solid var(--field-brd);
}
.bd-row:last-child { border-block-end: 0; }
.bd-row span:first-child { color: var(--text-2); }
.bd-row span:last-child { font-weight: 700; font-variant-numeric: tabular-nums; }

.result-empty { font-size: 13px; color: var(--text-3); text-align: center; margin-block-start: 14px; }
.result.has-result .result-empty { display: none; }
.result:not(.has-result) .breakdown { opacity: 0.35; }

.foot { text-align: center; font-size: 12px; color: var(--text-3); margin-block-start: 26px; }

/* ---------- Focus & motion ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
