/* ============================================================
   MEESHO PROFIT CALCULATOR — DESIGN SYSTEM
   Display: Lexend | Body: Inter | Figures: JetBrains Mono
   ============================================================ */

:root{
  --primary:#5B3DF5;
  --primary-dark:#4529D6;
  --primary-light:#EFEBFF;
  --profit:#16A34A;
  --profit-light:#E7F8ED;
  --warning:#F59E0B;
  --warning-light:#FEF3E2;
  --loss:#DC2626;
  --loss-light:#FDEBEB;
  --neutral:#6B7280;

  --bg:#F7F7FB;
  --surface:#FFFFFF;
  --surface-2:#F1F1F8;
  --border:#E6E6F0;
  --text:#15151F;
  --text-muted:#6C6C80;

  --radius-lg:18px;
  --radius-md:12px;
  --radius-sm:8px;
  --shadow-sm:0 1px 2px rgba(20,20,40,.04), 0 1px 1px rgba(20,20,40,.03);
  --shadow-md:0 8px 24px rgba(30,20,80,.08);
  --font-display:'Lexend', 'Inter', sans-serif;
  --font-body:'Inter', sans-serif;
  --font-mono:'JetBrains Mono', monospace;
}

[data-theme="dark"]{
  --primary:#8B7BFF;
  --primary-dark:#7461F0;
  --primary-light:#211C42;
  --profit:#3ED07A;
  --profit-light:#0F2A1B;
  --warning:#FBBF43;
  --warning-light:#332506;
  --loss:#FF6B6B;
  --loss-light:#3A1414;
  --neutral:#9A9AB0;

  --bg:#0B0B0F;
  --surface:#151520;
  --surface-2:#1C1C29;
  --border:#2A2A3A;
  --text:#F1F1F8;
  --text-muted:#9A9AB0;
  --shadow-sm:0 1px 2px rgba(0,0,0,.3);
  --shadow-md:0 8px 24px rgba(0,0,0,.4);
}

*,*::before,*::after{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
  font-family:var(--font-body);
  background:var(--bg);
  color:var(--text);
  -webkit-font-smoothing:antialiased;
  transition:background .2s ease, color .2s ease;
}
h1,h2,h3,h4{font-family:var(--font-display); margin:0; font-weight:700; letter-spacing:-0.01em;}
p{margin:0;}
input,select,button{font-family:var(--font-body);}
.muted{color:var(--text-muted); font-size:14px; margin-top:4px;}
.hint{color:var(--text-muted); font-size:12.5px; line-height:1.5; margin:6px 0 12px;}
::selection{background:var(--primary-light); color:var(--primary-dark);}

/* ============ TOPBAR ============ */
.topbar{
  position:sticky; top:0; z-index:50;
  display:flex; align-items:center; justify-content:space-between;
  padding:12px 20px; background:var(--surface); border-bottom:1px solid var(--border);
}
.topbar-left, .topbar-right{display:flex; align-items:center; gap:10px;}
.brand{display:flex; align-items:center; gap:10px;}
.brand-mark{
  width:38px; height:38px; border-radius:11px;
  background:linear-gradient(135deg, var(--primary), var(--primary-dark));
  display:flex; align-items:center; justify-content:center; color:#fff; flex-shrink:0;
  box-shadow:var(--shadow-sm);
}
.brand-mark i{width:20px; height:20px;}
.brand-text{display:flex; flex-direction:column; line-height:1.15;}
.brand-name{font-family:var(--font-display); font-weight:700; font-size:16px;}
.brand-sub{font-size:11.5px; color:var(--text-muted);}
.icon-btn{
  width:38px; height:38px; border-radius:10px; border:1px solid var(--border);
  background:var(--surface); color:var(--text); display:flex; align-items:center; justify-content:center;
  cursor:pointer; transition:background .15s, transform .1s;
}
.icon-btn:hover{background:var(--surface-2);}
.icon-btn:active{transform:scale(.94);}
.icon-btn i{width:18px; height:18px;}
.only-mobile{display:none;}

/* ============ SHELL ============ */
.app-shell{display:flex; max-width:1440px; margin:0 auto;}
.sidebar{
  width:230px; flex-shrink:0; padding:20px 14px; display:flex; flex-direction:column; gap:4px;
  position:sticky; top:63px; height:calc(100vh - 63px); border-right:1px solid var(--border);
}
.nav-item{
  display:flex; align-items:center; gap:12px; padding:10px 12px; border-radius:10px;
  border:none; background:transparent; color:var(--text-muted); font-size:14px; font-weight:500;
  cursor:pointer; text-align:left; width:100%; transition:background .15s, color .15s;
}
.nav-item i{width:18px; height:18px; flex-shrink:0;}
.nav-item:hover{background:var(--surface-2); color:var(--text);}
.nav-item.active{background:var(--primary-light); color:var(--primary-dark); font-weight:600;}
.sidebar-footer{
  margin-top:auto; display:flex; gap:8px; align-items:flex-start; color:var(--text-muted);
  font-size:11.5px; padding:12px; background:var(--surface-2); border-radius:10px; line-height:1.4;
}
.sidebar-footer i{width:16px; height:16px; flex-shrink:0; margin-top:1px;}

.content{flex:1; min-width:0; padding:24px 28px 100px;}
.view-head{display:flex; align-items:flex-start; justify-content:space-between; gap:16px; margin-bottom:20px; flex-wrap:wrap;}
.view-head-actions{display:flex; gap:8px;}

/* ============ BUTTONS ============ */
.btn{
  display:inline-flex; align-items:center; gap:7px; padding:10px 16px; border-radius:10px;
  font-size:13.5px; font-weight:600; border:1px solid transparent; cursor:pointer;
  transition:transform .1s, background .15s, box-shadow .15s; white-space:nowrap;
}
.btn i{width:16px; height:16px;}
.btn:active{transform:scale(.97);}
.btn-primary{background:linear-gradient(135deg, var(--primary), var(--primary-dark)); color:#fff; box-shadow:var(--shadow-sm);}
.btn-primary:hover{box-shadow:var(--shadow-md);}
.btn-ghost{background:var(--surface); color:var(--text); border-color:var(--border);}
.btn-ghost:hover{background:var(--surface-2);}
.btn-danger-ghost{background:var(--loss-light); color:var(--loss); border-color:transparent;}
.btn-sm{padding:7px 12px; font-size:12.5px;}
.file-btn{position:relative; overflow:hidden;}

/* ============ STAT GRID ============ */
.stat-grid{display:grid; grid-template-columns:repeat(auto-fit, minmax(200px,1fr)); gap:14px; margin-bottom:22px;}
.stat-card{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg);
  padding:16px 18px; box-shadow:var(--shadow-sm); position:relative; overflow:hidden;
}
.stat-card .stat-icon{
  width:34px; height:34px; border-radius:9px; display:flex; align-items:center; justify-content:center;
  background:var(--primary-light); color:var(--primary-dark); margin-bottom:10px;
}
.stat-card .stat-icon i{width:17px; height:17px;}
.stat-card .stat-label{font-size:12px; color:var(--text-muted); font-weight:600; text-transform:uppercase; letter-spacing:.03em;}
.stat-card .stat-value{font-family:var(--font-mono); font-size:22px; font-weight:700; margin-top:4px;}
.stat-card.profit .stat-icon{background:var(--profit-light); color:var(--profit);}
.stat-card.warning .stat-icon{background:var(--warning-light); color:var(--warning);}
.stat-card.loss .stat-icon{background:var(--loss-light); color:var(--loss);}

.dash-actions{display:grid; grid-template-columns:repeat(auto-fit,minmax(160px,1fr)); gap:12px; margin-bottom:22px;}
.action-card{
  display:flex; flex-direction:column; align-items:flex-start; gap:10px; padding:16px;
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-md);
  cursor:pointer; transition:border-color .15s, transform .1s; color:var(--text); font-size:13.5px; font-weight:600;
}
.action-card:hover{border-color:var(--primary); transform:translateY(-1px);}
.action-card i{width:20px; height:20px; color:var(--primary);}

/* ============ PANEL ============ */
.panel{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg);
  padding:18px 20px; margin-bottom:16px; box-shadow:var(--shadow-sm);
}
.panel h3{display:flex; align-items:center; gap:8px; font-size:15px; margin-bottom:12px;}
.panel h3 i{width:17px; height:17px; color:var(--primary);}
.panel h4{font-size:12.5px; text-transform:uppercase; letter-spacing:.04em; color:var(--text-muted); margin:16px 0 8px;}
.panel h4:first-of-type{margin-top:0;}

.collapsible summary{
  cursor:pointer; display:flex; align-items:center; gap:8px; font-family:var(--font-display); font-weight:700; font-size:15px;
  list-style:none;
}
.collapsible summary::-webkit-details-marker{display:none;}
.collapsible summary i{width:17px; height:17px; color:var(--primary);}
.collapsible summary::after{content:'▾'; margin-left:auto; color:var(--text-muted); font-size:12px;}
.collapsible[open] summary::after{content:'▴';}
.subsection{margin-top:14px;}

.optional-tag{font-size:10px; font-weight:500; text-transform:none; letter-spacing:0; color:var(--text-muted); background:var(--surface-2); padding:2px 7px; border-radius:6px;}

/* ============ FORM FIELDS ============ */
.field-grid{display:grid; grid-template-columns:repeat(auto-fit, minmax(180px,1fr)); gap:12px;}
.packaging-grid{grid-template-columns:repeat(auto-fit, minmax(110px,1fr));}
label{display:flex; flex-direction:column; gap:6px; font-size:12.5px; font-weight:600; color:var(--text-muted);}
input[type="text"], input[type="number"], input[type="search"], select{
  padding:10px 12px; border-radius:9px; border:1px solid var(--border); background:var(--bg); color:var(--text);
  font-size:14px; font-weight:500; outline:none; transition:border-color .15s, box-shadow .15s;
  font-family:var(--font-body);
}
input:focus, select:focus{border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-light);}
[data-theme="dark"] input, [data-theme="dark"] select{background:var(--surface-2);}

.custom-expense-list{display:flex; flex-direction:column; gap:8px; margin:10px 0;}
.custom-expense-row{display:grid; grid-template-columns:1.4fr 1fr auto; gap:8px; align-items:center;}
.custom-expense-row input{width:100%;}
.remove-row-btn{
  width:34px; height:34px; border-radius:8px; border:1px solid var(--border); background:var(--loss-light);
  color:var(--loss); display:flex; align-items:center; justify-content:center; cursor:pointer;
}
.remove-row-btn i{width:15px; height:15px;}

/* ============ CALCULATOR LAYOUT ============ */
.calc-grid{display:grid; grid-template-columns:minmax(0,1.35fr) minmax(320px, 1fr); gap:20px; align-items:flex-start;}
.calc-results{position:sticky; top:80px; display:flex; flex-direction:column;}

/* ============ SIGNATURE ELEMENT: THE RECEIPT ============ */
.receipt{
  background:var(--surface); position:relative; padding-top:26px;
  border-style:dashed; border-color:var(--border);
}
.receipt-tear{
  position:absolute; top:0; left:0; right:0; height:10px;
  background-image:radial-gradient(circle at 8px 0, transparent 6px, var(--bg) 6.5px);
  background-size:16px 10px; background-repeat:repeat-x;
}
.receipt-header{display:flex; flex-direction:column; align-items:center; text-align:center; gap:4px; padding-bottom:14px;}
.receipt-label{font-size:11.5px; letter-spacing:.12em; color:var(--text-muted); font-weight:700; text-transform:uppercase;}
.receipt-amount{font-family:var(--font-mono); font-size:40px; font-weight:700; line-height:1.1; color:var(--profit);}
.receipt-amount.is-loss{color:var(--loss);}
.receipt-margin{font-size:13px; color:var(--text-muted); font-weight:600;}
.status-pill{
  margin-top:6px; padding:5px 14px; border-radius:999px; font-size:12.5px; font-weight:700;
  background:var(--profit-light); color:var(--profit);
}
.status-pill.warning{background:var(--warning-light); color:var(--warning);}
.status-pill.loss{background:var(--loss-light); color:var(--loss);}

.receipt-modes{display:grid; grid-template-columns:1fr 1fr; gap:10px; padding:12px 0;}
.mode-box{background:var(--surface-2); border-radius:10px; padding:10px 12px; text-align:center;}
.mode-label{display:block; font-size:11px; color:var(--text-muted); font-weight:600; margin-bottom:4px;}
.mode-value{font-family:var(--font-mono); font-size:17px; font-weight:700;}

.receipt-divider{border-top:1px dashed var(--border); margin:4px 0;}
.receipt-lines{padding:12px 0; display:flex; flex-direction:column; gap:7px;}
.rline{display:flex; justify-content:space-between; font-size:13px; font-family:var(--font-mono);}
.rline .rl-name{font-family:var(--font-body); font-weight:500; color:var(--text-muted);}
.rline.rl-total{font-weight:700; font-size:14.5px; padding-top:6px; border-top:1px solid var(--border); color:var(--text);}
.rline.rl-total .rl-name{color:var(--text); font-weight:700;}
.rline .rl-neg{color:var(--loss);}

.receipt-metrics{display:grid; grid-template-columns:repeat(3,1fr); gap:8px; padding:8px 0;}
.receipt-metrics div{background:var(--surface-2); border-radius:9px; padding:8px 6px; text-align:center;}
.receipt-metrics span{display:block; font-size:10.5px; color:var(--text-muted); font-weight:600; margin-bottom:3px;}
.receipt-metrics b{font-family:var(--font-mono); font-size:14px;}

/* ============ WARNINGS ============ */
.warn-list{list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:8px;}
.warn-list li{
  display:flex; align-items:flex-start; gap:8px; font-size:13px; padding:9px 11px; border-radius:9px;
  background:var(--warning-light); color:var(--text);
}
.warn-list li.good{background:var(--profit-light);}
.warn-list li.bad{background:var(--loss-light);}
.warn-list li i{width:15px; height:15px; flex-shrink:0; margin-top:1px;}
.warn-list li.good i{color:var(--profit);}
.warn-list li.bad i{color:var(--loss);}
.warn-list li:not(.good):not(.bad) i{color:var(--warning);}

/* ============ SCORE ============ */
.score-row{display:flex; align-items:center; gap:16px;}
.score-ring{
  width:74px; height:74px; border-radius:50%; flex-shrink:0;
  background:conic-gradient(var(--primary) calc(var(--pct,0)*1%), var(--surface-2) 0);
  display:flex; align-items:center; justify-content:center; position:relative;
}
.score-ring::before{content:''; position:absolute; inset:6px; border-radius:50%; background:var(--surface);}
.score-ring span{position:relative; font-family:var(--font-mono); font-weight:700; font-size:18px;}
.score-breakdown{flex:1; display:flex; flex-wrap:wrap; gap:6px 14px; font-size:12px; color:var(--text-muted);}
.score-breakdown b{color:var(--text); font-family:var(--font-mono);}
.verdict{margin-top:14px; padding:12px 14px; border-radius:10px; background:var(--profit-light); color:var(--profit); font-weight:700; font-size:14px;}
.verdict.warn{background:var(--warning-light); color:var(--warning);}
.verdict.bad{background:var(--loss-light); color:var(--loss);}
.verdict ul{margin:8px 0 0; padding-left:18px; font-weight:500; font-size:12.5px; color:var(--text);}

/* ============ BREAK EVEN / PRICE REC ============ */
.be-grid{display:grid; grid-template-columns:repeat(auto-fit,minmax(120px,1fr)); gap:8px; margin-bottom:14px;}
.be-cell{background:var(--surface-2); border-radius:9px; padding:10px; text-align:center;}
.be-cell span{display:block; font-size:11px; color:var(--text-muted); margin-bottom:3px;}
.be-cell b{font-family:var(--font-mono); font-size:14px;}
.target-profit-box label{margin-bottom:8px;}
.target-result{background:var(--primary-light); color:var(--primary-dark); border-radius:10px; padding:12px; font-size:13px; line-height:1.7;}
.target-result b{font-family:var(--font-mono);}

.price-rec-grid{display:grid; grid-template-columns:repeat(3,1fr); gap:10px;}
.price-rec-cell{background:var(--surface-2); border-radius:12px; padding:12px; text-align:center;}
.price-rec-cell.recommended{background:var(--primary-light); border:1.5px solid var(--primary);}
.price-rec-cell span{display:block; font-size:11px; color:var(--text-muted); font-weight:600; margin-bottom:5px;}
.price-rec-cell b{display:block; font-family:var(--font-mono); font-size:18px;}
.price-rec-cell small{display:block; font-size:11px; color:var(--text-muted); margin-top:4px;}

/* ============ TOOLBAR / TABLES ============ */
.toolbar{display:flex; gap:10px; margin-bottom:14px; flex-wrap:wrap;}
.toolbar input[type="search"]{flex:1; min-width:180px;}
.table-wrap{overflow-x:auto; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius-lg); box-shadow:var(--shadow-sm);}
.data-table{width:100%; border-collapse:collapse; font-size:13px; min-width:720px;}
.data-table th{
  text-align:left; padding:12px 14px; font-size:11px; text-transform:uppercase; letter-spacing:.04em;
  color:var(--text-muted); border-bottom:1px solid var(--border); background:var(--surface-2); white-space:nowrap;
}
.data-table td{padding:12px 14px; border-bottom:1px solid var(--border); white-space:nowrap;}
.data-table tbody tr:last-child td{border-bottom:none;}
.data-table tbody tr:hover{background:var(--surface-2);}
.data-table .num{font-family:var(--font-mono);}
.data-table .profit-pos{color:var(--profit); font-weight:700;}
.data-table .profit-neg{color:var(--loss); font-weight:700;}
.row-actions{display:flex; gap:6px;}
.row-actions button{
  width:30px; height:30px; border-radius:7px; border:1px solid var(--border); background:var(--surface);
  display:flex; align-items:center; justify-content:center; cursor:pointer; color:var(--text-muted);
}
.row-actions button:hover{color:var(--primary); border-color:var(--primary);}
.row-actions button i{width:14px; height:14px;}
.badge{padding:3px 9px; border-radius:999px; font-size:11px; font-weight:700;}
.badge.high{background:var(--profit-light); color:var(--profit);}
.badge.medium{background:var(--warning-light); color:var(--warning);}
.badge.low{background:var(--surface-2); color:var(--text-muted);}
.badge.loss{background:var(--loss-light); color:var(--loss);}

.empty-state{display:flex; flex-direction:column; align-items:center; gap:10px; padding:50px 20px; color:var(--text-muted); text-align:center;}
.empty-state i{width:38px; height:38px; opacity:.5;}

/* ============ SIMULATOR ============ */
.scenario-grid{display:grid; grid-template-columns:repeat(auto-fit,minmax(160px,1fr)); gap:12px;}
.scenario-card{background:var(--surface-2); border-radius:12px; padding:14px; text-align:center;}
.scenario-card b{display:block; font-family:var(--font-mono); font-size:19px; margin:6px 0 2px; color:var(--profit);}
.scenario-card span{font-size:11.5px; color:var(--text-muted); font-weight:600;}
.sim-grid{display:grid; grid-template-columns:repeat(auto-fit,minmax(140px,1fr)); gap:10px;}
.sim-cell{background:var(--surface-2); border-radius:10px; padding:12px; text-align:center;}
.sim-cell span{display:block; font-size:11px; color:var(--text-muted); margin-bottom:4px;}
.sim-cell b{font-family:var(--font-mono); font-size:16px;}

/* ============ INSIGHTS ============ */
.insight-list{list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:10px;}
.insight-list li{
  display:flex; align-items:center; gap:10px; font-size:13.5px; padding:11px 13px;
  background:var(--surface-2); border-radius:10px;
}
.insight-list li i{width:16px; height:16px; color:var(--primary); flex-shrink:0;}

/* ============ DATA ACTIONS / DISCLAIMER ============ */
.data-actions{display:flex; gap:10px; flex-wrap:wrap;}
.disclaimer{display:flex; gap:12px; background:var(--surface-2); border-color:transparent;}
.disclaimer i{width:20px; height:20px; color:var(--text-muted); flex-shrink:0; margin-top:2px;}
.disclaimer p{font-size:12px; color:var(--text-muted); line-height:1.6;}

/* ============ TOAST ============ */
.toast{
  position:fixed; bottom:90px; left:50%; transform:translateX(-50%) translateY(20px);
  background:var(--text); color:var(--bg); padding:11px 20px; border-radius:10px; font-size:13.5px; font-weight:600;
  opacity:0; pointer-events:none; transition:opacity .2s, transform .2s; z-index:200; box-shadow:var(--shadow-md);
}
.toast.show{opacity:1; transform:translateX(-50%) translateY(0);}

/* ============ BOTTOM NAV ============ */
.bottom-nav{display:none;}

/* ============ RESPONSIVE ============ */
@media (max-width: 980px){
  .calc-grid{grid-template-columns:1fr;}
  .calc-results{position:static;}
}

@media (max-width: 860px){
  .only-mobile{display:flex;}
  .sidebar{
    position:fixed; left:0; top:0; height:100vh; z-index:100; background:var(--surface);
    transform:translateX(-100%); transition:transform .2s ease; box-shadow:var(--shadow-md);
    padding-top:76px; width:250px;
  }
  .sidebar.open{transform:translateX(0);}
  .content{padding:16px 14px 90px;}
  .bottom-nav{
    display:flex; position:fixed; bottom:0; left:0; right:0; z-index:60;
    background:var(--surface); border-top:1px solid var(--border); padding:6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bn-item{
    flex:1; display:flex; flex-direction:column; align-items:center; gap:3px; padding:7px 2px;
    background:none; border:none; color:var(--text-muted); font-size:10.5px; font-weight:600; cursor:pointer;
  }
  .bn-item i{width:20px; height:20px;}
  .bn-item.active{color:var(--primary);}
  .view-head{flex-direction:column;}
  .price-rec-grid{grid-template-columns:1fr 1fr;}
  .brand-sub{display:none;}
}

@media (max-width: 480px){
  .receipt-amount{font-size:32px;}
  .price-rec-grid{grid-template-columns:1fr;}
}

/* focus visibility */
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible{
  outline:2px solid var(--primary); outline-offset:2px;
}

@media (prefers-reduced-motion: reduce){
  *{transition:none !important;}
}
