:root{
  --bg: #FBF3F1;
  --surface: #FFFFFF;
  --surface-2: #FBEFEC;
  --border: #EFDAD7;
  --text: #3A2A2C;
  --text-muted: #93777A;
  --rose-1: #E9BDBE;
  --rose-2: #C4858A;
  --rose-3: #9C5A63;
  --gold: #D8B482;
  --danger: #B3564F;
  --shadow: 0 8px 24px rgba(156, 90, 99, 0.14);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

[data-theme="dark"]{
  --bg: #1C1315;
  --surface: #251A1D;
  --surface-2: #2E2023;
  --border: #3D2A2D;
  --text: #F5E7E6;
  --text-muted: #B79599;
  --rose-1: #7A4A50;
  --rose-2: #C4858A;
  --rose-3: #E9BDBE;
  --gold: #D8B482;
  --danger: #E28A83;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);
}

*{box-sizing:border-box;}

html,body{
  margin:0;
  padding:0;
  background:var(--bg);
  color:var(--text);
  font-family: "Vazirmatn","IRANSans",Tahoma,"Segoe UI",Arial,sans-serif;
  -webkit-font-smoothing:antialiased;
  font-variant-numeric: normal;
}

b, .mat-info span, .p-price, .p-meta, .result-row b, .qty-probe b, .qty-probe input,
input[type="number"], .calc-mat-line, .p-raw{
  font-family:"Vazirmatn",Tahoma,Arial,sans-serif;
}

body{
  min-height:100vh;
  padding-bottom: 84px;
}

h1,h2,h3{ margin:0; font-weight:700; }

.topbar{
  position:sticky; top:0; z-index:20;
  display:flex; align-items:center; justify-content:space-between;
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--rose-1), var(--rose-2));
  box-shadow: var(--shadow);
}
.brand{ display:flex; align-items:center; gap:10px; }
.brand-mark{
  width:26px; height:26px; border-radius:8px;
  background: linear-gradient(145deg, #fff, var(--gold));
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.5);
}
.brand-name{ font-weight:800; font-size:18px; color:#fff; letter-spacing:.3px; }

.install-btn{
  border:none; border-radius:999px; padding:8px 14px;
  background: rgba(255,255,255,.9); color:var(--rose-3);
  font-weight:700; font-size:13px; cursor:pointer;
}
.hidden{ display:none !important; }

.app{ max-width:560px; margin:0 auto; padding:18px 16px 8px; }

.tab{ display:none; animation: fade .25s ease; }
.tab.active{ display:block; }
@keyframes fade{ from{opacity:0; transform:translateY(6px);} to{opacity:1; transform:none;} }

.section-head{ margin-bottom:16px; }
.section-head h1{ font-size:21px; }
.section-head p{ margin:4px 0 0; color:var(--text-muted); font-size:13.5px; }

.card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  padding:16px;
  margin-bottom:14px;
  box-shadow: var(--shadow);
}

.form-card .field{ margin-bottom:12px; }
.field label{ display:block; font-size:13px; color:var(--text-muted); margin-bottom:6px; font-weight:600; }
.row-2{ display:grid; grid-template-columns:1fr 1fr; gap:10px; }

input[type="text"], input[type="number"]{
  width:100%;
  background: var(--surface-2);
  border:1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  color: var(--text);
  font-size:14.5px;
  font-family: inherit;
  outline:none;
  transition: border-color .15s;
}
input:focus{ border-color: var(--rose-2); }

.select-wrap{ position:relative; }
.select-wrap select{
  width:100%;
  appearance:none; -webkit-appearance:none; -moz-appearance:none;
  background: var(--surface-2);
  border:1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px 11px 34px;
  color: var(--text);
  font-size:14.5px;
  font-family:"Vazirmatn",inherit;
  outline:none;
  cursor:pointer;
  transition: border-color .15s, box-shadow .15s;
}
.select-wrap select:focus{
  border-color: var(--rose-2);
  box-shadow: 0 0 0 3px rgba(196,133,138,.15);
}
.select-wrap::after{
  content:"";
  position:absolute;
  left:14px; top:44%;
  width:9px; height:9px;
  transform: translateY(-50%) rotate(45deg);
  border-right:2px solid var(--rose-3);
  border-bottom:2px solid var(--rose-3);
  pointer-events:none;
}

.btn{
  border:none; border-radius: var(--radius-sm);
  padding: 12px 16px; font-size:14.5px; font-weight:700;
  cursor:pointer; font-family:inherit;
  transition: transform .1s ease, opacity .15s;
}
.btn:active{ transform: scale(.97); }
.btn-primary{
  width:100%;
  background: linear-gradient(120deg, var(--rose-2), var(--rose-3));
  color:#fff;
}
.btn-ghost{
  background: var(--surface-2);
  color: var(--rose-3);
  border:1px solid var(--border);
}
.btn-save{
  width:100%;
  background: linear-gradient(120deg, var(--gold), var(--rose-2));
  color:#fff;
  margin-top:14px;
}
.btn-danger{
  background: transparent;
  color: var(--danger);
  border:1px solid var(--danger);
  margin-top:10px;
}

.stack{ display:flex; flex-direction:column; gap:10px; }
.small-stack{ margin-top:10px; }

.mat-card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius: var(--radius-md);
  padding:13px 14px;
  display:flex; align-items:center; justify-content:space-between;
  gap:10px;
  box-shadow: var(--shadow);
}
.mat-info b{ display:block; font-size:15px; }
.mat-info span{ display:block; font-size:12.5px; color:var(--text-muted); margin-top:2px; }
.mat-actions{ display:flex; gap:6px; flex-shrink:0; }
.icon-btn{
  border:none; background:var(--surface-2); color:var(--rose-3);
  width:34px; height:34px; border-radius:10px; cursor:pointer;
  display:flex; align-items:center; justify-content:center;
  font-size:14px;
}
.icon-btn.danger{ color: var(--danger); }

.add-mat-row{
  display:grid;
  grid-template-columns: 1.4fr 0.8fr 0.8fr auto;
  gap:8px;
}
.add-mat-row .btn{ padding:11px 12px; white-space:nowrap; }

.calc-mat-line{
  display:flex; align-items:center; justify-content:space-between;
  background:var(--surface-2);
  border:1px solid var(--border);
  border-radius: var(--radius-sm);
  padding:10px 12px;
  font-size:13.5px;
}
.calc-mat-line .line-cost{ color: var(--rose-3); font-weight:700; }
.calc-mat-line .remove-line{
  background:none; border:none; color:var(--danger);
  cursor:pointer; font-size:15px; padding:0 2px;
}

.calc-actions{ display:flex; gap:10px; margin-top:6px; }
.calc-actions .btn-primary{ flex:2; }
.calc-actions .btn-ghost{ flex:1; }

.editing-notice{
  margin-top:12px; font-size:13px; color: var(--rose-3);
  background: var(--surface-2); border-radius: var(--radius-sm);
  padding:10px 12px;
}
.link-btn{ background:none; border:none; color:var(--danger); text-decoration:underline; cursor:pointer; font-size:13px; font-family:inherit; }

.result-card{
  border-radius: var(--radius-lg);
  padding:18px;
  background: linear-gradient(155deg, var(--rose-2), var(--rose-3) 70%);
  color:#fff;
  box-shadow: var(--shadow);
  position:relative;
  overflow:hidden;
}
.result-card::after{
  content:"";
  position:absolute; inset:0;
  background: radial-gradient(circle at 85% -10%, rgba(255,255,255,.35), transparent 55%);
  pointer-events:none;
}
.result-row{
  display:flex; align-items:center; justify-content:space-between;
  padding:8px 0;
  font-size:13.5px;
  border-bottom: 1px solid rgba(255,255,255,.18);
}
.result-row:last-of-type{ border-bottom:none; }
.result-row b{ font-size:15px; }
.result-row.total b{ font-size:16px; }
.result-row.highlight{
  margin-top:4px;
  padding-top:12px;
  border-top: 1px dashed rgba(255,255,255,.4);
}
.result-row.highlight span{ font-weight:700; }
.result-row.highlight b{ font-size:20px; }

.product-card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:16px;
  box-shadow: var(--shadow);
}
.product-card .p-head{
  display:flex; align-items:center; justify-content:space-between;
  margin-bottom:10px;
}
.product-card .p-head b{ font-size:16px; }
.product-card .p-price{
  color: var(--rose-3); font-weight:800; font-size:15px;
}
.product-card .p-meta{ font-size:12.5px; color:var(--text-muted); margin-bottom:4px; }
.product-card .p-raw{ font-size:12.5px; color:var(--text-muted); margin-bottom:10px; }
.product-card .p-actions{ display:flex; gap:8px; margin-top:10px; }
.product-card .p-actions .icon-btn{ width:auto; padding:0 12px; font-size:12.5px; font-weight:700; }

.qty-probe{
  display:flex; gap:8px; margin-top:10px; align-items:center;
  background:var(--surface-2); border-radius: var(--radius-sm); padding:8px 10px;
}
.qty-probe input{ width:80px; padding:8px; }
.qty-probe span{ font-size:12.5px; color:var(--text-muted); }
.qty-probe b{ margin-inline-start:auto; color:var(--rose-3); font-size:14px; }

.missing-warning{ color: var(--danger); font-size:12px; margin-top:6px; }

.settings-row{ display:flex; align-items:center; justify-content:space-between; }
.settings-row .hint{ margin:2px 0 0; }
.hint{ color:var(--text-muted); font-size:12.5px; margin:8px 0 0; line-height:1.7; }

.switch{ position:relative; width:48px; height:28px; flex-shrink:0; }
.switch input{ opacity:0; width:0; height:0; }
.slider{
  position:absolute; inset:0; background: var(--border);
  border-radius:999px; cursor:pointer; transition:.2s;
}
.slider::before{
  content:""; position:absolute; width:22px; height:22px; border-radius:50%;
  background:#fff; top:3px; right:3px; transition:.2s;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.switch input:checked + .slider{ background: linear-gradient(120deg, var(--rose-2), var(--rose-3)); }
.switch input:checked + .slider::before{ transform: translateX(-20px); }

.danger-zone{ border-color: var(--danger); }

.empty-state{
  text-align:center; padding: 34px 16px; color:var(--text-muted);
  border:1px dashed var(--border); border-radius: var(--radius-lg);
  font-size:13.5px;
}

.tabbar{
  position:fixed; bottom:0; inset-inline:0; z-index:20;
  display:flex;
  background: var(--surface);
  border-top:1px solid var(--border);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 20px rgba(156,90,99,.1);
}
.tab-btn{
  flex:1; display:flex; flex-direction:column; align-items:center; gap:3px;
  background:none; border:none; padding:8px 4px; cursor:pointer;
  color: var(--text-muted); font-family:inherit; font-size:11px;
}
.tab-btn svg{ width:22px; height:22px; fill: currentColor; }
.tab-btn.active{ color: var(--rose-3); }
.tab-btn.active svg{ fill: var(--rose-2); }

.toast{
  position:fixed; bottom:92px; left:50%; transform:translateX(-50%);
  background: var(--text); color: var(--bg);
  padding:10px 18px; border-radius:999px; font-size:13px;
  z-index:50; box-shadow: var(--shadow);
}

.modal-overlay{
  position:fixed; inset:0; z-index:100;
  background: rgba(30,15,17,.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display:flex; align-items:center; justify-content:center;
  padding:20px;
  opacity:0;
  transition: opacity .18s ease;
}
.modal-overlay.show{ opacity:1; }

.modal-card{
  background: var(--surface);
  border:1px solid var(--border);
  border-radius: var(--radius-lg);
  padding:20px;
  width:100%;
  max-width:340px;
  box-shadow: var(--shadow);
  transform: translateY(10px) scale(.97);
  transition: transform .18s ease;
}
.modal-overlay.show .modal-card{ transform:none; }

.modal-icon{
  width:44px; height:44px;
  border-radius:14px;
  display:flex; align-items:center; justify-content:center;
  margin-bottom:12px;
  background: linear-gradient(135deg, var(--rose-1), var(--rose-2));
  color:#fff;
  font-size:20px;
}
.modal-icon.danger{ background: linear-gradient(135deg, var(--danger), #8a3d38); }

.modal-title{ font-size:16.5px; margin:0 0 6px; font-weight:700; }
.modal-msg{ font-size:13.5px; color:var(--text-muted); line-height:1.85; margin:0 0 6px; }
.modal-card .field{ margin-top:14px; }
.modal-actions{ display:flex; gap:10px; margin-top:18px; }
.modal-actions .btn{ flex:1; margin:0; }

.btn-danger-solid{
  background: linear-gradient(120deg, var(--danger), #8a3d38);
  color:#fff;
}

@media (max-width:360px){
  .add-mat-row{ grid-template-columns: 1fr 1fr; }
  .add-mat-row select#calcMatSelect{ grid-column: 1 / -1; }
}
