/* ==========================================================
   فاتورة أونلاين — واجهة الموقع
   ========================================================== */
:root {
  --bg: #f3f5fa;
  --bg-2: #eaeef6;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #e2e7f0;
  --border-2: #d3dae6;
  --text: #121826;
  --muted: #667085;
  --primary: #1f6fe0;
  --primary-2: #1658bf;
  --primary-soft: #e9f1fd;
  --dark: #23272f;
  --success: #12a150;
  --danger: #e03a3a;
  --warning: #e8890c;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 6px 24px -8px rgba(16, 24, 40, .14), 0 2px 6px -2px rgba(16, 24, 40, .06);
  --shadow-lg: 0 24px 60px -16px rgba(16, 24, 40, .28);
  --header-h: 64px;
  --bottom-h: 0px;
  --font: 'Tajawal', system-ui, sans-serif;
  color-scheme: light;
}
html[lang="fr"], html[lang="en"] { --font: 'Inter', 'Tajawal', system-ui, sans-serif; }
html[data-theme="dark"] {
  --bg: #0e1118;
  --bg-2: #141924;
  --surface: #171c27;
  --surface-2: #1d2330;
  --border: #283042;
  --border-2: #34405a;
  --text: #eef1f7;
  --muted: #98a2b8;
  --primary: #4c8ff0;
  --primary-2: #3a7be0;
  --primary-soft: #1b2a45;
  --dark: #e7ebf3;
  --shadow: 0 8px 28px -10px rgba(0, 0, 0, .6);
  --shadow-lg: 0 24px 60px -16px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom, 0px));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
a { color: var(--primary); text-decoration: none; }
.hidden { display: none !important; }
svg.i { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[dir="rtl"] .flip-rtl { transform: scaleX(-1); }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--border);
}
.header-in {
  max-width: 1480px; margin: 0 auto; height: 100%;
  display: flex; align-items: center; gap: 14px; padding: 0 20px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); min-width: 0; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  background: linear-gradient(135deg, var(--primary), #0b3f91);
  display: grid; place-items: center; color: #fff; position: relative; overflow: hidden;
  box-shadow: 0 6px 16px -6px rgba(31, 111, 224, .7);
}
.brand-mark::after { content: ''; position: absolute; width: 22px; height: 60px; background: rgba(255,255,255,.14); transform: rotate(35deg); inset-inline-end: -4px; top: -10px; }
.brand-mark svg { width: 20px; height: 20px; position: relative; z-index: 1; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name { font-weight: 800; font-size: 17px; white-space: nowrap; }
.brand-tag { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main-nav { display: flex; gap: 4px; margin-inline-start: 18px; }
.main-nav a {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 10px;
  color: var(--muted); font-weight: 600; font-size: 14.5px; white-space: nowrap;
}
.main-nav a:hover { background: var(--surface-2); color: var(--text); }
.main-nav a.active { background: var(--primary-soft); color: var(--primary); }
.header-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }
.lang-switch { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 3px; }
.lang-switch button {
  border: 0; background: transparent; padding: 5px 10px; border-radius: 8px; font-size: 13px; font-weight: 700; color: var(--muted);
  font-family: 'Tajawal', 'Inter', sans-serif; min-width: 38px;
}
.lang-switch button.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface);
  display: grid; place-items: center; color: var(--text); flex: none;
}
.icon-btn:hover { border-color: var(--border-2); background: var(--surface-2); }
.icon-btn.danger { color: var(--danger); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 700; font-size: 14.5px; white-space: nowrap; transition: .15s background, .15s border-color, .15s transform;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 8px 18px -8px rgba(31,111,224,.7); }
.btn-primary:hover { background: var(--primary-2); }
.btn-dark { background: var(--dark); color: var(--surface); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border-2); }
.btn-soft { background: var(--primary-soft); color: var(--primary); }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.btn-sm { height: 36px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btn-lg { height: 52px; padding: 0 26px; font-size: 16px; border-radius: 14px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; pointer-events: none; }

/* ---------- Layout ---------- */
.page { max-width: 1480px; margin: 0 auto; padding: 24px 20px 48px; }
.page-narrow { max-width: 980px; }
.page-title { font-size: 26px; font-weight: 800; margin: 4px 0 18px; }
.app-footer { text-align: center; color: var(--muted); font-size: 13px; padding: 10px 20px 28px; }
.app-footer b { color: var(--text); font-family: 'Inter', sans-serif; letter-spacing: .02em; }

/* ---------- Hero ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 26px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 64px 56px; box-shadow: var(--shadow);
  display: grid; grid-template-columns: 1.1fr .9fr; gap: 40px; align-items: center;
}
.hero-deco { position: absolute; inset: 0; pointer-events: none; color: var(--primary); }
.hero-deco .waves { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .5; }
.hero-deco .corner { position: absolute; top: 0; inset-inline-end: 0; width: 230px; height: 200px; }
.hero-deco .corner-b { position: absolute; bottom: 0; inset-inline-start: 0; width: 170px; height: 150px; }
[dir="rtl"] .hero-deco .corner, [dir="rtl"] .hero-deco .corner-b { transform: scaleX(-1); }
.hero-text { position: relative; z-index: 1; }
.hero-badge {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 99px;
  background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 13px; margin-bottom: 18px;
}
.hero h1 { font-size: clamp(30px, 4.2vw, 50px); line-height: 1.18; margin: 0 0 16px; font-weight: 800; letter-spacing: -.01em; }
html[lang="ar"] .hero h1 { letter-spacing: 0; line-height: 1.35; }
.hero h1 span { color: var(--primary); }
.hero p { font-size: 17px; color: var(--muted); margin: 0 0 28px; max-width: 560px; }
.hero-cta { display: flex; flex-wrap: wrap; gap: 12px; }
.hero-visual { position: relative; z-index: 1; display: flex; justify-content: center; }
.hero-paper {
  width: min(100%, 360px); aspect-ratio: 210 / 297; background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg);
  transform: rotate(-3deg); overflow: hidden; position: relative; color: #1f2937;
}
[dir="rtl"] .hero-paper { transform: rotate(3deg); }
.hero-paper .mini { position: absolute; inset: 0; width: 100%; height: 100%; }

.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 26px 0; }
.feature {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px;
  display: flex; gap: 14px; align-items: flex-start;
}
.feature-ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.feature h3 { margin: 0 0 4px; font-size: 16px; }
.feature p { margin: 0; color: var(--muted); font-size: 14px; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 30px 0 14px; }
.section-head h2 { margin: 0; font-size: 20px; display: flex; align-items: center; gap: 10px; }
.section-head h2::before { content: ''; width: 12px; height: 22px; background: var(--primary); transform: skewX(-18deg); border-radius: 2px; }

/* ---------- Invoice list ---------- */
.inv-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.inv-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 12px; transition: .15s border-color, .15s box-shadow; min-width: 0;
}
.inv-card:hover { border-color: var(--border-2); box-shadow: var(--shadow); }
.inv-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.inv-card-no { font-weight: 800; font-size: 16px; overflow-wrap: anywhere; }
.inv-card-type { font-size: 12.5px; color: var(--muted); }
.inv-card-client { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-card-meta { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; }
.inv-card-total { font-weight: 800; font-size: 18px; color: var(--primary); overflow-wrap: anywhere; }
.inv-card-date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.inv-card-actions { display: flex; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.inv-card-actions .btn { flex: 1; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.paid { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.badge.unpaid { background: color-mix(in srgb, var(--danger) 13%, transparent); color: var(--danger); }
.badge.partial { background: color-mix(in srgb, var(--warning) 15%, transparent); color: var(--warning); }
.badge.none { background: var(--surface-2); color: var(--muted); }

.empty {
  text-align: center; padding: 48px 20px; background: var(--surface); border: 1.5px dashed var(--border-2); border-radius: var(--radius);
}
.empty-ic { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 18px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; }
.empty-ic svg { width: 30px; height: 30px; }
.empty h3 { margin: 0 0 6px; }
.empty p { margin: 0 0 18px; color: var(--muted); }

.toolbar-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.search { position: relative; flex: 1 1 260px; }
.search svg { position: absolute; top: 50%; transform: translateY(-50%); inset-inline-start: 13px; color: var(--muted); }
.search input { padding-inline-start: 42px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.stat b { display: block; font-size: 24px; font-weight: 800; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.paid b { color: var(--success); } .stat.unpaid b { color: var(--danger); } .stat.partial b { color: var(--warning); }

/* ---------- Forms ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; }
.card-head h3 { margin: 0; font-size: 16px; font-weight: 800; flex: 1; min-width: 0; }
.card-head .ic { width: 34px; height: 34px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; flex: none; }
.card-head .ic svg { width: 18px; height: 18px; }
.card-sub { color: var(--muted); font-size: 13.5px; margin: -8px 0 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin-bottom: 12px; }
.grid2 .field, .grid3 .field { margin-bottom: 0; }
.grid2 + .field, .grid2 + .grid2, .field + .grid2, .grid3 + .field { margin-top: 12px; }
.field > label, .lbl { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; height: 44px; padding: 0 13px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); outline: none; transition: .15s border-color, .15s box-shadow, .15s background; min-width: 0;
}
.textarea { height: auto; min-height: 92px; padding: 11px 13px; resize: vertical; line-height: 1.6; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 16%, transparent); }
.input[readonly] { background: var(--bg-2); font-weight: 700; color: var(--text); }
.input.num { direction: ltr; text-align: center; }
html[dir="rtl"] input[type="date"] { text-align: right; }
.select { appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 13px center; padding-inline-end: 34px; }
html[dir="rtl"] .select { background-position: left 13px center; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); padding: 8px 14px; border-radius: 11px;
  font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 7px; color: var(--text);
}
.chip:hover { border-color: var(--border-2); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.st-paid.active { background: var(--success); border-color: var(--success); }
.chip.st-unpaid.active { background: var(--danger); border-color: var(--danger); }
.chip.st-partial.active { background: var(--warning); border-color: var(--warning); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; padding: 8px 6px; border-radius: 9px; font-weight: 700; font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg button.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

/* uploader */
.uploader { display: flex; align-items: center; gap: 14px; }
.up-thumb {
  width: 76px; height: 76px; border-radius: 14px; border: 1.5px dashed var(--border-2); background: var(--surface-2);
  display: grid; place-items: center; overflow: hidden; flex: none; color: var(--muted);
}
.up-thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.up-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* items */
.items { display: flex; flex-direction: column; gap: 10px; }
.item {
  border: 1px solid var(--border); border-radius: 14px; padding: 12px; background: var(--surface-2); position: relative;
}
.item-top { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.item-no { width: 28px; height: 28px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); font-weight: 800; font-size: 13px; display: grid; place-items: center; flex: none; }
.item-top .input { flex: 1; background: var(--surface); }
.item-top .icon-btn { width: 40px; height: 40px; }
.item-grid { display: grid; grid-template-columns: 1fr 1.3fr 1.3fr; gap: 8px; }
.item-grid .field { margin: 0; gap: 4px; }
.item-grid .field > label { font-size: 12px; }
.item-grid .input { background: var(--surface); height: 42px; padding: 0 8px; }
.add-item { border: 1.5px dashed var(--border-2); background: transparent; color: var(--primary); height: 48px; border-radius: 14px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; }
.add-item:hover { background: var(--primary-soft); border-color: var(--primary); }
.sum-box { margin-top: 14px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); padding: 12px 14px; }
.sum-row { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: 14px; color: var(--muted); }
.sum-row b { color: var(--text); direction: ltr; unicode-bidi: isolate; text-align: end; overflow-wrap: anywhere; }
.sum-row.big { font-size: 16px; color: var(--text); font-weight: 800; border-top: 1px dashed var(--border-2); margin-top: 6px; padding-top: 10px; }
.sum-row.big b { color: var(--primary); font-size: 18px; }

/* toggles */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.toggle:last-child { border-bottom: 0; }
.toggle span { font-weight: 600; font-size: 14px; }
.switch { position: relative; width: 46px; height: 27px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--border-2); transition: .2s; }
.switch i::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 21px; height: 21px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: .2s; }
.switch input:checked + i { background: var(--primary); }
.switch input:checked + i::after { inset-inline-start: 22px; }
.range-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.range-row .lbl-row { display: flex; justify-content: space-between; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.range-row .lbl-row em { font-style: normal; color: var(--primary); direction: ltr; }
input[type="range"] { width: 100%; accent-color: var(--primary); height: 24px; }

/* design */
.tpl-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tpl {
  border: 2px solid var(--border); border-radius: 13px; padding: 6px; background: var(--surface-2); text-align: center;
  font-weight: 700; font-size: 13px; color: var(--text); display: flex; flex-direction: column; gap: 6px; min-width: 0;
}
.tpl svg { width: 100%; height: auto; border-radius: 7px; display: block; background: #fff; box-shadow: var(--shadow-sm); }
.tpl.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.pal-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.pal { width: 46px; height: 46px; border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 1.5px var(--border-2); padding: 0; overflow: hidden; display: flex; transform: rotate(-45deg); }
.pal i { flex: 1; }
.pal.active { box-shadow: 0 0 0 2.5px var(--primary); }
.colors { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.color-field {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); min-width: 0; cursor: pointer;
}
.color-field input[type="color"] { width: 34px; height: 34px; border: 0; padding: 0; border-radius: 9px; background: none; flex: none; cursor: pointer; }
.color-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-field input[type="color"]::-webkit-color-swatch { border: 1px solid rgba(0,0,0,.12); border-radius: 9px; }
.color-field input[type="color"]::-moz-color-swatch { border: 1px solid rgba(0,0,0,.12); border-radius: 9px; }
.color-field span { font-size: 13px; font-weight: 600; line-height: 1.3; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: minmax(380px, 470px) minmax(0, 1fr); gap: 22px; align-items: start; }
.ed-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.ed-head h1 { margin: 0; font-size: 22px; font-weight: 800; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-state { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.save-state::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--warning); }
.save-state.ok::before { background: var(--success); }
.ed-tabs { margin-bottom: 14px; position: sticky; top: calc(var(--header-h) + 8px); z-index: 20; box-shadow: var(--shadow-sm); background: var(--surface); }
.ed-tabs .tab-preview { display: none; }
.ed-preview {
  position: sticky; top: calc(var(--header-h) + 16px);
  height: calc(100vh - var(--header-h) - 32px); min-height: 520px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; overflow: hidden;
  display: flex; flex-direction: column;
}
.pv-bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.pv-bar .seg { flex: 0 1 auto; }
.pv-actions { display: flex; gap: 8px; margin-inline-start: auto; flex-wrap: wrap; }
.pv-stage {
  flex: 1; overflow: auto; padding: 24px 16px 40px;
  background-color: var(--bg-2);
  background-image: radial-gradient(color-mix(in srgb, var(--muted) 22%, transparent) 1px, transparent 1px);
  background-size: 18px 18px;
}
.pv-scaler { margin: 0 auto; direction: ltr; position: relative; }
.pv-inner { transform-origin: 0 0; position: absolute; top: 0; left: 0; box-shadow: 0 18px 50px -14px rgba(16,24,40,.35), 0 0 0 1px rgba(16,24,40,.06); }
.mobile-actions { display: none; }

/* ---------- Modal / sheet ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 14, 24, .5); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .18s ease; }
.sheet { background: var(--surface); border-radius: 22px; width: min(440px, 100%); box-shadow: var(--shadow-lg); padding: 22px; animation: pop .2s ease; max-height: 90vh; overflow: auto; }
.sheet h3 { margin: 0 0 6px; font-size: 19px; }
.sheet p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.sheet-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet-opt {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 16px; padding: 16px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; text-align: center; color: var(--text);
}
.sheet-opt:hover { border-color: var(--primary); background: var(--primary-soft); }
.sheet-opt .ic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.sheet-opt.wa .ic { background: #e6f8ee; color: #128c4b; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.98); } }

.toast-wrap { position: fixed; top: calc(var(--header-h) + 12px); left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; width: max-content; max-width: calc(100vw - 24px); pointer-events: none; }
.toast { background: var(--dark); color: var(--surface); padding: 11px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px; animation: pop .2s ease; }
.toast.err { background: var(--danger); color: #fff; }
.toast.ok svg { color: #3ddc84; }
.loading-ov { position: fixed; inset: 0; z-index: 95; background: rgba(10,14,24,.45); display: grid; place-items: center; }
.loading-box { background: var(--surface); border-radius: 18px; padding: 22px 26px; display: flex; align-items: center; gap: 14px; font-weight: 700; box-shadow: var(--shadow-lg); }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--primary-soft); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .main-nav a span { display: none; }
  .main-nav a { padding: 9px 11px; }
}
@media (max-width: 1023px) {
  .editor { grid-template-columns: 1fr; }
  .ed-tabs .tab-preview { display: block; }
  .ed-preview { display: none; position: static; height: auto; min-height: 0; border-radius: 18px; }
  .editor.show-preview .ed-preview { display: flex; }
  .editor.show-preview .ed-panes { display: none; }
  .pv-stage { min-height: 60vh; padding: 16px 10px 28px; }
  .pv-bar .pv-actions { display: none; }
  .pv-bar .seg { flex: 1; }
  body.route-editor { --bottom-h: 72px; }
  body.route-editor .bottom-nav { display: none; }
  .mobile-actions {
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
  }
  .mobile-actions button {
    border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; gap: 3px;
    font-size: 11.5px; font-weight: 700; color: var(--muted); padding: 6px 2px; border-radius: 12px; min-width: 0;
  }
  .mobile-actions button span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .mobile-actions button.primary { background: var(--primary); color: #fff; }
}
@media (max-width: 900px) {
  :root { --header-h: 60px; }
  .main-nav { display: none; }
  body { --bottom-h: 66px; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11.5px; font-weight: 700; padding: 6px 2px; border-radius: 12px; min-width: 0; }
  .bottom-nav a span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .bottom-nav a.active { color: var(--primary); }
  .bottom-nav a.new-btn svg { background: var(--primary); color: #fff; width: 40px; height: 30px; padding: 5px; border-radius: 10px; }
  .hero { grid-template-columns: 1fr; padding: 40px 28px; text-align: start; }
  .hero-visual { display: none; }
  .features { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .toast-wrap { top: auto; bottom: calc(var(--bottom-h) + 16px + env(safe-area-inset-bottom, 0px)); }
  .overlay { align-items: flex-end; padding: 0; }
  .sheet { width: 100%; border-radius: 22px 22px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 600px) {
  .header-in { padding: 0 12px; gap: 8px; }
  .brand-tag { display: none; }
  .brand-name { font-size: 15.5px; }
  .brand-mark { width: 34px; height: 34px; }
  .lang-switch button { padding: 5px 7px; min-width: 32px; font-size: 12px; }
  .icon-btn { width: 36px; height: 36px; }
  .page { padding: 16px 12px 32px; }
  .hero { padding: 30px 20px; border-radius: 20px; }
  .hero p { font-size: 15.5px; }
  .hero-cta .btn { flex: 1 1 100%; }
  .features { grid-template-columns: 1fr; gap: 10px; }
  .feature { padding: 16px; }
  .card { padding: 14px; border-radius: 14px; }
  .inv-list { grid-template-columns: 1fr; }
  .tpl-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .colors { grid-template-columns: 1fr; }
  .page-title { font-size: 22px; }
  .hero-deco .corner { width: 140px; height: 120px; }
  .hero-deco .corner-b { width: 100px; height: 90px; }
}
@media (max-width: 380px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .grid2 .field + .field, .grid3 .field + .field { margin-top: 0; }
  .item-grid { grid-template-columns: 1fr 1fr; }
  .item-grid .field:last-child { grid-column: 1 / -1; }
  .sheet-grid { grid-template-columns: 1fr; }
  #installBtn { display: none !important; }
}

/* ---------- Print ---------- */
#print-root { display: none; }
@media print {
  body > *:not(#print-root) { display: none !important; }
  body { background: #fff !important; padding: 0 !important; margin: 0 !important; }
  #print-root { display: block !important; }
  #print-root .inv { box-shadow: none !important; transform: none !important; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}
