:root{
  --brown:#7c6cf2; --brown-d:#5a4fcf; --cream:#eef4ff; --cream-d:#dbe7fb;
  --green:#4aa8e0; --green-d:#2f86bf; --ink:#1f2540; --muted:#6b7694;
  --red:#e0566e; --radius:14px;
}
*{box-sizing:border-box; -webkit-tap-highlight-color:transparent}
html{font-size:16px}
body{
  margin:0; font-family:'Cairo',system-ui,'Segoe UI',Tahoma,sans-serif;
  background:var(--cream); color:var(--ink);
  padding-bottom:76px;
}
.appbar{
  position:sticky; top:0; z-index:20; background:var(--brown); color:var(--cream);
  padding:calc(10px + env(safe-area-inset-top)) 16px 12px; box-shadow:0 2px 8px rgba(0,0,0,.15);
}
.appbar-title{display:flex; align-items:center; gap:10px; font-weight:900; font-size:1.2rem}
.appbar-logo{width:30px; height:30px; border-radius:8px}
main{padding:14px; max-width:640px; margin:0 auto}
.tab{display:none}
.tab.active{display:block; animation:fade .18s ease}
@keyframes fade{from{opacity:0; transform:translateY(4px)} to{opacity:1}}

.tabbar{
  position:fixed; bottom:0; left:0; right:0; z-index:20;
  display:flex; background:var(--brown-d);
  padding-bottom:env(safe-area-inset-bottom);
}
.tabbtn{
  flex:1; background:none; border:0; color:#cfcaf7; font-family:inherit;
  padding:8px 2px calc(8px + env(safe-area-inset-bottom)); font-size:1.25rem;
  display:flex; flex-direction:column; align-items:center; gap:1px;
}
.tabbtn span{font-size:.68rem; font-weight:700}
.tabbtn.active{color:#fff; background:rgba(255,255,255,.08)}

.card{background:#fff; border-radius:var(--radius); padding:14px; margin-bottom:12px;
  box-shadow:0 1px 4px rgba(var(--shc),.12); border:1px solid var(--cream-d)}
.section-title{font-size:.95rem; color:var(--brown); margin:16px 4px 8px; font-weight:800}

.chips{display:flex; gap:8px; overflow-x:auto; padding:2px 2px 10px; scrollbar-width:none}
.chips::-webkit-scrollbar{display:none}
.chip{
  white-space:nowrap; border:1.5px solid var(--brown); color:var(--brown); background:#fff;
  border-radius:999px; padding:6px 14px; font-family:inherit; font-weight:700; font-size:.85rem;
}
.chip.active{background:var(--brown); color:var(--cream)}

.size-row{
  display:flex; align-items:center; gap:10px; background:#fff; border:1px solid var(--cream-d);
  border-radius:12px; padding:10px 12px; margin-bottom:8px;
}
.size-row .info{flex:1; min-width:0}
.size-row .name{font-weight:800; font-size:.92rem}
.size-row .dims{color:var(--muted); font-size:.82rem; direction:ltr; text-align:right}
.size-row .ratio{font-size:.72rem; background:var(--cream-d); color:var(--brown-d);
  border-radius:6px; padding:1px 7px; margin-inline-start:6px; font-weight:700}
.iconbtn{border:1px solid var(--cream-d); background:var(--cream); border-radius:9px;
  padding:6px 9px; font-size:.78rem; font-family:inherit; font-weight:700; color:var(--brown-d)}

.btn{border:0; border-radius:11px; padding:11px 16px; font-family:inherit;
  font-weight:800; font-size:.92rem; cursor:pointer}
.btn.primary{background:var(--brown); color:var(--cream)}
.btn.primary:disabled{opacity:.5}
.btn.ghost{background:var(--cream-d); color:var(--brown-d)}
.btn.danger{background:#fde3e8; color:var(--red)}
.btn.block{width:100%}
.btn.small{padding:7px 11px; font-size:.8rem}
.row{display:flex; align-items:center}
.gap{gap:8px}
.grow{flex:1}

.form-card summary{list-style:none; text-align:center; cursor:pointer}
.form-card summary::-webkit-details-marker{display:none}
.form-card[open] summary{margin-bottom:10px}
.form-body{display:flex; flex-direction:column; gap:10px; margin-top:4px}
label{font-size:.82rem; font-weight:700; color:var(--brown-d); display:flex; flex-direction:column; gap:4px}
input,select,textarea{
  font-family:inherit; font-size:.95rem; padding:10px 12px; border-radius:10px;
  border:1.5px solid var(--cream-d); background:#fff; color:var(--ink); width:100%;
}
input:focus,select:focus{outline:2px solid var(--green); border-color:var(--green)}

.brief-card{min-height:150px}
.brief-empty{color:var(--muted); text-align:center; padding:34px 10px; font-weight:600}
.brief-field{display:flex; gap:8px; padding:7px 0; border-bottom:1px dashed var(--cream-d); font-size:.9rem}
.brief-field:last-child{border-bottom:0}
.brief-field .k{color:var(--green-d); font-weight:800; min-width:86px}
.brief-actions{display:flex; gap:6px; margin-top:8px}

.stats{display:flex; gap:8px; margin-bottom:12px}
.stat{flex:1; background:#fff; border:1px solid var(--cream-d); border-radius:12px;
  padding:10px 8px; text-align:center}
.stat .v{font-size:1.15rem; font-weight:900; color:var(--brown)}
.stat .v.warn{color:var(--red)}
.stat .l{font-size:.72rem; color:var(--muted); font-weight:700}

.client-head{display:flex; align-items:center; gap:8px}
.client-head .nm{flex:1; font-weight:900}
.badge{font-size:.7rem; font-weight:800; border-radius:999px; padding:2px 9px}
.badge.ok{background:#dff1fb; color:var(--green-d)}
.badge.late{background:#fde3e8; color:var(--red)}
.badge.due{background:#fff3d6; color:#9a7418}
.proj{border-top:1px dashed var(--cream-d); padding:8px 0; font-size:.88rem}
.proj .top{display:flex; align-items:center; gap:8px}
.proj .pn{flex:1; font-weight:800}
.proj .meta{color:var(--muted); font-size:.78rem; margin-top:2px}
.proj .meta .over{color:var(--red); font-weight:800}
.status-sel{width:auto; padding:5px 8px; font-size:.78rem; font-weight:700}
.mini{font-size:.75rem; padding:4px 9px}

.qitem{display:flex; gap:8px; margin-bottom:8px; align-items:center}
.qitem input[type=text]{flex:1}
.qitem input[type=number]{width:96px}
.total-row{display:flex; justify-content:space-between; align-items:center;
  background:var(--cream-d); border-radius:10px; padding:10px 14px; margin:10px 0;
  font-weight:800; color:var(--brown-d)}
.total-row strong{font-size:1.2rem}

.saved-row{display:flex; align-items:center; gap:8px; background:#fff;
  border:1px solid var(--cream-d); border-radius:11px; padding:9px 12px; margin-bottom:8px; font-size:.86rem}
.saved-row .t{flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight:700}
.saved-row .d{color:var(--muted); font-size:.74rem}
.empty-note{color:var(--muted); font-size:.85rem; text-align:center; padding:12px}

/* ===== print quote ===== */
#printQuote{display:none}
@media print{
  @page{size:A4; margin:14mm}
  body>*:not(#printQuote){display:none !important}
  html,body{max-width:none !important; box-shadow:none !important; padding:0 !important; margin:0 !important; background:#fff !important; height:auto !important; overflow:visible !important}
  #printQuote{display:block !important; color:#222; font-size:13px; padding:8px; direction:rtl; -webkit-print-color-adjust:exact; print-color-adjust:exact}
  #printQuote .pq-head{display:flex; justify-content:space-between; align-items:flex-start;
    border-bottom:3px solid var(--brown); padding-bottom:10px; margin-bottom:14px}
  #printQuote h1{font-size:20px; margin:0; color:var(--brown-d)}
  #printQuote .pq-meta{font-size:12px; color:#555; line-height:1.7}
  #printQuote table{width:100%; border-collapse:collapse; margin-top:8px}
  #printQuote th{background:var(--brown); color:#fff; padding:7px 10px; text-align:right; font-size:12px}
  #printQuote td{border-bottom:1px solid #ddd; padding:7px 10px}
  #printQuote .pq-total{margin-top:12px; text-align:left; font-size:14px}
  #printQuote .pq-total .grand{font-size:17px; font-weight:900; color:var(--brown-d)}
  #printQuote .pq-foot{margin-top:26px; font-size:11px; color:#777; border-top:1px solid #ddd; padding-top:8px}
}

/* ===== v4 additions ===== */
[hidden]{display:none !important}
.ic{vertical-align:middle; flex:none}
.btn .ic,.iconbtn .ic{margin-inline-end:4px}
.iconbtn .ic{margin:0}
summary .ic{margin-inline-end:6px}
.tabbtn span{font-size:.64rem}
.tool-title{margin:0 0 4px; font-size:1.05rem; font-weight:900; color:var(--brown-d)}
.hint{margin:0 0 10px; color:var(--muted); font-size:.84rem; font-weight:600}
.card label{margin-bottom:10px}
textarea{resize:vertical; min-height:70px}
.filebtn{border:1.5px dashed var(--brown); border-radius:12px; padding:12px; text-align:center; color:var(--brown-d); background:var(--cream)}
.filebtn input{display:none}
.filebtn{cursor:pointer; font-weight:700; display:block}
.preview{display:block; max-width:100%; max-height:260px; margin:6px auto 10px; border-radius:10px; border:1px solid var(--cream-d)}
.err{color:var(--red); font-weight:700; font-size:.9rem; background:#fff5f7}
.note-warn{background:#fff3d6; color:#7a5a10; border-radius:10px; padding:8px 12px; font-size:.82rem; font-weight:700; margin:8px 0}
.score-row{display:flex; gap:12px; align-items:center; margin-bottom:6px}
.score{font-size:2.1rem; font-weight:900; color:var(--brown); line-height:1; white-space:nowrap}
.score small{font-size:.9rem; color:var(--muted)}
.score-sum{font-size:.9rem; font-weight:700; flex:1}
.sub{margin:12px 0 4px; font-size:.9rem; color:var(--green-d); font-weight:900}
ul.plain{margin:0; padding-inline-start:20px; font-size:.88rem; line-height:1.8}
.swatches{display:grid; grid-template-columns:repeat(3,1fr); gap:8px; margin-top:10px}
.swatch{border:1px solid rgba(0,0,0,.08); border-radius:12px; height:78px; font-family:inherit; font-weight:800;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px; direction:ltr}
.swatch span{font-size:.82rem}
.swatch small{font-size:.7rem; opacity:.8}
.timer-clock{font-size:2.6rem; font-weight:900; text-align:center; direction:ltr; color:var(--brown-d); margin:6px 0 12px; font-variant-numeric:tabular-nums}
details.sess{margin-top:6px}
details.sess summary{cursor:pointer; color:var(--brown-d); font-weight:700; font-size:.82rem; padding:4px 0}
.chal-meta{color:var(--muted); font-size:.78rem; font-weight:800}
.chal-desc{font-size:.92rem; line-height:1.8; margin:4px 0 8px}
.chal-time{font-weight:800; color:var(--green-d); margin-bottom:10px; direction:rtl}
.dots{display:grid; grid-template-columns:repeat(7,1fr); gap:6px; margin-top:8px}
.dot{aspect-ratio:1; border-radius:7px; background:var(--cream-d)}
.dot.on{background:var(--brown)}
.dot.today{outline:2px solid var(--green)}
.cap-text{font-size:.95rem; line-height:1.9; white-space:pre-wrap}
.tags-line{font-size:.88rem; line-height:2; color:var(--brown-d); font-weight:700; word-break:break-word}
.lib-grid{display:grid; grid-template-columns:1fr 1fr; gap:10px}
.lib-item{border:1px solid var(--cream-d); background:#fff; border-radius:12px; padding:0; overflow:hidden; font-family:inherit; text-align:start}
.lib-item img{display:block; width:100%; height:130px; object-fit:cover}
.lib-link{height:130px; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:8px; color:var(--brown); background:var(--cream-d); font-size:.78rem; font-weight:700; padding:6px; text-align:center; overflow:hidden}
.lib-cap{padding:7px 9px; font-size:.78rem; font-weight:700; color:var(--ink); overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.viewer{position:fixed; inset:0; z-index:50; background:rgba(31,37,64,.72); display:flex; align-items:center; justify-content:center; padding:16px}
.viewer[hidden]{display:none !important}
.viewer-in{background:#fff; border-radius:16px; padding:12px; max-width:560px; width:100%; max-height:92vh; overflow:auto}
.viewer-in img{display:block; width:100%; max-height:60vh; object-fit:contain; border-radius:10px; margin-bottom:10px}
.v-title{font-weight:800; margin:6px 0 10px}
.v-tags{margin-top:10px; display:flex; gap:6px; flex-wrap:wrap}

/* ===== v6 additions ===== */
#toolChips{flex-wrap:wrap; overflow:visible}
.mini-sw{display:flex; gap:6px; margin:8px 0}
.mini-sw span{width:34px; height:34px; border-radius:9px; border:1px solid rgba(0,0,0,.1)}
.font-sample{border-radius:10px; padding:14px; line-height:1.7; border:1px solid var(--cream-d); overflow-wrap:anywhere}
.fav-on{color:#e0a020}
.fav-on svg{fill:#e0a020}
.harm-row{display:flex; gap:10px; align-items:center; margin-bottom:8px}
.harm-sw{flex:1; height:56px; border:1px solid rgba(0,0,0,.08); border-radius:12px; font-family:inherit; font-weight:800; display:flex; align-items:center; justify-content:space-between; padding:0 14px; direction:ltr}
.harm-info{width:120px; font-size:.74rem; color:var(--muted); font-weight:700; line-height:1.5}
.harm-info b{color:var(--ink)}
.harm-info .lv{color:var(--green-d)}
.pairs{display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:6px}
.pair{display:flex; align-items:center; gap:6px; font-size:.82rem; background:var(--cream); padding:6px 10px; border-radius:10px}
.dotc{width:16px; height:16px; border-radius:50%; border:1px solid rgba(0,0,0,.1)}
.meta{font-size:.82rem; color:var(--muted); font-weight:700; margin:4px 0}
#hmChips,#tpChips,#ftChips{flex-wrap:wrap; overflow:visible}
input[type=color]{width:100%; height:44px; padding:3px; border:1px solid var(--cream-d); border-radius:10px; background:#fff}

/* account tab v7.1 */
.ac-head{text-align:center}
.ac-hero{width:54px;height:54px;margin:0 auto 8px;border-radius:50%;background:linear-gradient(135deg,var(--brown),var(--brown-d));display:flex;align-items:center;justify-content:center;color:#fff;box-shadow:0 4px 12px rgba(var(--shc),.28)}
.ac-or{display:flex;align-items:center;gap:10px;color:var(--muted);font-size:.8rem;font-weight:800;margin:12px 0 6px}
.ac-or:before,.ac-or:after{content:"";flex:1;height:1px;background:var(--cream-d)}
.ac-mailwrap{position:relative;display:block}
.ac-mailwrap input{width:100%}
.ac-gbadge{position:absolute;left:8px;top:50%;transform:translateY(-50%);width:26px;height:26px;border-radius:50%;background:#fff;border:1px solid var(--cream-d);display:flex;align-items:center;justify-content:center;box-shadow:0 1px 3px rgba(31,37,64,.12)}
.ac-gbadge svg{display:block}
.ac-id{display:flex;align-items:center;gap:12px;padding:2px 0 12px;border-bottom:1px dashed var(--cream-d);margin-bottom:4px}
.ac-avatar{position:relative;width:52px;height:52px;border-radius:50%;background:linear-gradient(135deg,var(--brown),var(--brown-d));color:#fff;font-size:22px;font-weight:900;display:flex;align-items:center;justify-content:center;flex-shrink:0}
.ac-gbadge-mini{position:absolute;bottom:-3px;inset-inline-end:-3px;top:auto;left:auto;transform:none;width:22px;height:22px}
.ac-gbadge-mini svg{width:13px;height:13px}
.ac-idtxt .nm{font-weight:900;font-size:1.05rem}
.ac-mail{color:var(--muted);font-size:.82rem;direction:ltr;text-align:end}
.ac-syncrow{display:flex;align-items:center;gap:8px;padding:10px 0;font-size:.9rem}
.ac-syncrow .k{color:var(--green-d);font-weight:800}
.ac-dot{width:9px;height:9px;border-radius:50%;background:var(--green);box-shadow:0 0 0 3px rgba(74,168,224,.18);flex-shrink:0}
.ac-pair{margin-top:12px;background:var(--cream);border-radius:var(--radius);padding:10px 12px}
.btn.google{background:#fff;color:var(--ink);border:1.5px solid var(--cream-d);display:flex;align-items:center;justify-content:center;gap:10px;font-weight:800;box-shadow:0 1px 4px rgba(31,37,64,.08)}
.btn.google .gic{display:flex;align-items:center}

/* mandatory sign-in gate */
body.auth-gated main, body.auth-gated nav.tabbar{display:none !important}
body.auth-gated #tab-account{display:block !important}

/* ===== themes ===== */
html[data-theme="blue"]{--brown:#3b82f6; --brown-d:#2563eb; --green:#0ea5e9; --green-d:#0284c7; --cream:#eef5ff; --cream-d:#d8e7fb}
html[data-theme="green"]{--brown:#10b981; --brown-d:#059669; --green:#34d399; --green-d:#059669; --cream:#eefaf3; --cream-d:#d5f0e2}
html[data-theme="rose"]{--brown:#f0566e; --brown-d:#d43d56; --green:#fb7a95; --green-d:#d43d56; --cream:#fdf0f2; --cream-d:#f9dce1}
html[data-theme="dark"]{
  --brown:#8b80f7; --brown-d:#6a5fd9; --cream:#141831; --cream-d:#2a3052;
  --green:#5fb6ea; --green-d:#8ecbf0; --ink:#e9ecfa; --muted:#9aa3c4; --red:#f0728a;
}
html[data-theme="dark"] body{background:#10142c}
html[data-theme="dark"] .card, html[data-theme="dark"] .chip, html[data-theme="dark"] .size-row,
html[data-theme="dark"] .stat, html[data-theme="dark"] .saved-row, html[data-theme="dark"] .lib-item,
html[data-theme="dark"] .viewer-in, html[data-theme="dark"] .btn.google,
html[data-theme="dark"] input:not([type=color]):not([type=checkbox]):not([type=radio]),
html[data-theme="dark"] select, html[data-theme="dark"] textarea{
  background:#1d2344; color:var(--ink); border-color:var(--cream-d)
}
html[data-theme="dark"] input::placeholder, html[data-theme="dark"] textarea::placeholder{color:var(--muted)}
html[data-theme="dark"] .tabbtn{color:#b7b0e6}
html[data-theme="dark"] .iconbtn{background:#232a4e}
html[data-theme="dark"] .ac-gbadge{background:#fff}
html[data-theme="dark"] .chip.active{color:#fff}
html[data-theme="dark"] .opt-panel, html[data-theme="dark"] .sheet-panel{background:#1a2040; color:var(--ink)}
html[data-theme="dark"] .opt-row{background:#232a4e; color:var(--ink)}
html[data-theme="dark"] .theme-card{background:#232a4e; border-color:var(--cream-d); color:var(--ink)}

/* options button in header */
.optbtn{
  margin-inline-start:auto; background:rgba(255,255,255,.16); border:0; color:#fff;
  width:36px; height:36px; border-radius:10px; display:flex; align-items:center; justify-content:center;
  font-family:inherit; cursor:pointer
}
.optbtn:active{transform:scale(.94)}

/* bottom sheets */
.sheet{position:fixed; inset:0; z-index:60}
.sheet-back{position:absolute; inset:0; background:rgba(15,18,38,.45); opacity:0; transition:opacity .3s ease}
.sheet.open .sheet-back{opacity:1}
.sheet-panel{
  position:absolute; left:0; right:0; bottom:0; max-width:640px; margin:0 auto;
  background:var(--cream); border-radius:22px 22px 0 0; padding:14px 16px calc(18px + env(safe-area-inset-bottom));
  transform:translateY(105%); transition:transform .34s cubic-bezier(.22,.9,.3,1);
  box-shadow:0 -6px 30px rgba(15,18,38,.25); max-height:82vh; overflow:auto
}
.sheet.open .sheet-panel{transform:none}
.sheet-grab{width:42px; height:5px; border-radius:99px; background:var(--cream-d); margin:0 auto 10px}
.sheet-title{font-weight:900; font-size:1.05rem; text-align:center; margin-bottom:12px; color:var(--ink)}
.sheet-head{display:flex; align-items:center; gap:10px; margin-bottom:12px}
.sheet-head .sheet-title{flex:1; margin:0; text-align:center}
.sheet-backbtn{border:0; background:none; color:var(--brown); width:36px; height:36px; display:flex; align-items:center; justify-content:center; cursor:pointer}
.opt-row{
  display:flex; align-items:center; gap:12px; width:100%; border:0; cursor:pointer;
  background:#fff; border-radius:14px; padding:13px 14px; margin-bottom:10px;
  font-family:inherit; font-size:.95rem; font-weight:800; color:var(--ink); text-align:start;
  border:1px solid var(--cream-d)
}
.opt-row:not(.static):active{transform:scale(.985)}
.opt-ic{color:var(--brown); display:flex; align-items:center}
.opt-txt{flex:1}
.opt-val{color:var(--muted); font-size:.82rem; font-weight:700}

/* themes grid */
.theme-grid{display:grid; grid-template-columns:1fr 1fr; gap:10px}
.theme-card{
  border:2px solid var(--cream-d); background:#fff; border-radius:16px; padding:14px 12px;
  display:flex; flex-direction:column; align-items:center; gap:9px; cursor:pointer;
  font-family:inherit; position:relative; transition:border-color .2s ease, transform .15s ease
}
.theme-card:active{transform:scale(.96)}
.theme-card.sel{border-color:var(--brown); box-shadow:0 0 0 3px color-mix(in srgb,var(--brown) 18%,transparent)}
.theme-dots{display:flex; gap:6px}
.theme-dots i{width:22px; height:22px; border-radius:50%; border:1px solid rgba(31,37,64,.08)}
.theme-name{font-weight:800; font-size:.92rem; color:var(--ink)}
.theme-check{
  position:absolute; top:8px; inset-inline-start:8px; width:24px; height:24px; border-radius:50%;
  background:var(--brown); color:#fff; display:none; align-items:center; justify-content:center
}
.theme-card.sel .theme-check{display:flex}

/* theme switch reveal */
.theme-reveal{
  position:fixed; z-index:999; width:300vmax; height:300vmax; border-radius:50%;
  transform:translate(-50%,-50%) scale(0); opacity:1; pointer-events:none;
  transition:transform .65s cubic-bezier(.25,.7,.3,1), opacity .45s ease
}

/* ===== prompt chat ===== */
#prChat{margin:4px 0 10px}
.pc-row{display:flex; margin:8px 0}
.pc-row.user{justify-content:flex-start}
.pc-row.bot{justify-content:flex-end}
.pc-bub{max-width:88%; padding:10px 13px; border-radius:14px; font-size:.92rem; line-height:1.75; white-space:pre-wrap; word-break:break-word}
.pc-row.user .pc-bub{background:var(--brown); color:#fff; border-end-start-radius:5px}
.pc-row.bot .pc-bub{background:var(--cream-d); color:var(--ink); border-end-end-radius:5px}
.pc-wait{opacity:.7}
.pc-cards{margin:2px 0 10px}
#prComposer textarea{width:100%}

.pc-models{display:flex;flex-wrap:wrap;gap:6px;justify-content:center;margin:0 0 10px}.pc-models span{font-size:.78rem;font-weight:700;padding:4px 10px;border-radius:99px;background:var(--card,#fff2);border:1px solid var(--line,#8884);color:var(--muted)}

.fmt-list{display:grid;gap:6px;margin:8px 0 14px}
.fmt-row{display:flex;flex-wrap:wrap;align-items:center;gap:8px;width:100%;padding:10px 12px;border:1px solid var(--line,#ddd);border-radius:10px;background:transparent;color:inherit;font:inherit;text-align:left;cursor:pointer}
.fmt-k{min-width:52px;font-weight:700;opacity:.7;font-size:12px}
.fmt-v{flex:1;font-family:ui-monospace,Menlo,monospace;font-size:14px;word-break:break-all}
.fmt-n{flex-basis:100%;opacity:.7;font-size:12px}
