/* ==========================================================
   A to Z Sanitary — Udhar Manager
   Design tokens: Deep Teal (#0F766E) + Copper (#C2793D) accent
   Fonts: Plus Jakarta Sans (display) / Inter (body)
   ========================================================== */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@500;600;700;800&family=Inter:wght@400;500;600;700&display=swap');

:root{
  --teal-50:#eefbfa;  --teal-100:#d3f4f1; --teal-500:#0f766e; --teal-600:#0c5f59; --teal-700:#0a4d47;
  --copper-400:#d8925a; --copper-500:#c2793d; --copper-600:#a4632f;
  --bg:#f5f7f9; --surface:#ffffff; --surface-2:#f0f3f5;
  --text:#16221f; --text-muted:#5b6b68;
  --border:#e4e9ea;
  --success:#16a34a; --danger:#dc2626; --warning:#d97706; --info:#2563eb;
  --radius:14px; --radius-sm:9px;
  --shadow-sm:0 1px 2px rgba(16,40,38,.06);
  --shadow-md:0 6px 20px rgba(16,40,38,.08);
  --sidebar-w:250px;
  --font-display:'Plus Jakarta Sans',sans-serif;
  --font-body:'Inter',sans-serif;
}

[data-bs-theme="dark"]{
  --bg:#0b1a18; --surface:#112524; --surface-2:#0e1f1d;
  --text:#eaf3f1; --text-muted:#8fa6a2;
  --border:#1c3634; --teal-50:#0e2b28; --teal-100:#123a36;
  --shadow-sm:0 1px 2px rgba(0,0,0,.3);
  --shadow-md:0 10px 30px rgba(0,0,0,.4);
}

*{box-sizing:border-box;}
body{
  font-family:var(--font-body);
  background:var(--bg);
  color:var(--text);
  margin:0;
}
h1,h2,h3,h4,h5,h6{font-family:var(--font-display); color:var(--text);}

a{text-decoration:none;}

/* ---------------- Splash Screen ---------------- */
.app-splash{
  position:fixed; inset:0; z-index:99999;
  background:linear-gradient(160deg,var(--teal-700),var(--teal-600) 55%,var(--copper-600));
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:.35rem; opacity:1; transition:opacity .4s ease;
}
.app-splash.splash-hide{opacity:0; pointer-events:none;}
.app-splash-logo{
  width:84px; height:84px; border-radius:24px; background:rgba(255,255,255,.14);
  display:flex; align-items:center; justify-content:center; font-size:2.2rem; color:#fff;
  margin-bottom:.5rem; animation:splashPop .5s ease; overflow:hidden;
}
.app-splash-logo img{width:100%; height:100%; object-fit:cover;}
.app-splash-title{font-family:var(--font-display); font-weight:800; font-size:1.3rem; color:#fff;}
.app-splash-sub{color:#bfe9e2; font-size:.85rem; margin-bottom:1.5rem;}
.app-splash-spinner{
  width:26px; height:26px; border-radius:50%;
  border:3px solid rgba(255,255,255,.3); border-top-color:#fff;
  animation:splashSpin .7s linear infinite;
}
@keyframes splashSpin{to{transform:rotate(360deg);}}
@keyframes splashPop{from{transform:scale(.7); opacity:0;} to{transform:scale(1); opacity:1;}}

/* ---------------- Login Screen (native-app style) ---------------- */
.login-body{
  margin:0; min-height:100vh; min-height:100dvh; overflow-x:hidden;
  background:var(--teal-700);
}
.login-screen{
  min-height:100vh; min-height:100dvh; display:flex; flex-direction:column;
}
.login-hero{
  flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center;
  background:linear-gradient(160deg,var(--teal-700),var(--teal-600) 65%,var(--copper-600));
  color:#fff; padding:3rem 1.5rem 2.5rem; padding-top:calc(3rem + env(safe-area-inset-top));
  text-align:center; min-height:38vh;
}
.login-hero-logo{
  width:76px; height:76px; border-radius:22px; background:rgba(255,255,255,.15);
  display:flex; align-items:center; justify-content:center; font-size:2rem; margin-bottom:1rem; overflow:hidden;
}
.login-hero-logo img{width:100%; height:100%; object-fit:cover;}
.login-hero-title{font-family:var(--font-display); font-weight:800; margin:0; color:#fff;}
.login-hero-sub{color:#bfe9e2; font-size:.9rem; margin:.15rem 0 0;}
.login-sheet{
  background:var(--surface); border-radius:26px 26px 0 0;
  padding:2rem 1.75rem calc(2rem + env(safe-area-inset-bottom));
  box-shadow:0 -10px 30px rgba(0,0,0,.12);
  flex-shrink:0;
}
@media (min-width:576px){
  .login-body{display:flex; align-items:center; justify-content:center; padding:1.5rem;}
  .login-screen{
    min-height:auto; max-width:400px; width:100%; border-radius:26px; overflow:hidden;
    box-shadow:0 20px 60px rgba(0,0,0,.35);
  }
  .login-hero{min-height:auto; padding:2.5rem 1.5rem;}
  .login-sheet{border-radius:0; padding:2rem 1.75rem;}
}

/* ---------------- App Shell ---------------- */
.app-wrapper{display:flex; min-height:100vh; min-height:100dvh; width:100%;}

.sidebar{
  width:var(--sidebar-w); flex-shrink:0;
  background:linear-gradient(180deg,var(--teal-700),var(--teal-600));
  color:#eafffb; display:flex; flex-direction:column;
  position:fixed; top:0; left:0; bottom:0; z-index:1030;
  transition:transform .25s ease;
}
.sidebar-brand{display:flex; align-items:center; gap:.65rem; padding:1.25rem 1.1rem; border-bottom:1px solid rgba(255,255,255,.12);}
.sidebar-brand i{font-size:1.4rem; color:var(--copper-400);}
.sidebar-logo-img{width:34px; height:34px; border-radius:9px; object-fit:cover; background:#fff;}
.brand-title{font-family:var(--font-display); font-weight:700; font-size:.98rem; color:#fff;}
.brand-sub{font-size:.72rem; color:#bfe9e2;}
.sidebar-nav{flex:1; padding:1rem .7rem; display:flex; flex-direction:column; gap:.15rem;}
.sidebar-nav .nav-link{
  color:#d9f2ee; padding:.65rem .85rem; border-radius:var(--radius-sm);
  display:flex; align-items:center; gap:.7rem; font-size:.9rem; font-weight:500;
}
.sidebar-nav .nav-link i{width:18px; text-align:center; opacity:.9;}
.sidebar-nav .nav-link:hover{background:rgba(255,255,255,.08); color:#fff;}
.sidebar-nav .nav-link.active{background:var(--copper-500); color:#fff; box-shadow:var(--shadow-sm);}
.sidebar-footer{padding:1rem; border-top:1px solid rgba(255,255,255,.1); color:#a9d8d1;}

.app-main{margin-left:var(--sidebar-w); flex:1; min-width:0; min-height:100vh; min-height:100dvh; display:flex; flex-direction:column;}

.topbar{
  height:64px; background:var(--surface); border-bottom:1px solid var(--border);
  position:sticky; top:0; z-index:1020; min-width:0;
}
.topbar > div{min-width:0;}
.btn-icon{
  background:transparent; border:none; color:var(--text); width:38px; height:38px;
  border-radius:50%; display:flex; align-items:center; justify-content:center;
}
.btn-icon:hover{background:var(--surface-2);}
.dropdown-toggle-noicon::after{display:none;}
.user-avatar{
  width:36px; height:36px; border-radius:50%; background:var(--teal-500); color:#fff;
  display:flex; align-items:center; justify-content:center; font-weight:700;
}

.global-search{width:320px; max-width:100%;}
.global-search .search-icon, .icon-input .search-icon{position:absolute; left:12px; top:50%; transform:translateY(-50%); color:var(--text-muted); font-size:.85rem;}
.global-search input, .icon-input input{padding-left:34px; background:var(--surface-2); border:1px solid var(--border); color:var(--text);}
.search-results{
  position:absolute; top:110%; left:0; right:0; background:var(--surface);
  border-radius:var(--radius-sm); max-height:340px; overflow-y:auto; z-index:1050; display:none;
  border:1px solid var(--border);
}
.search-results.show{display:block;}
.search-results a{display:block; padding:.6rem .9rem; color:var(--text); border-bottom:1px solid var(--border); font-size:.85rem;}
.search-results a:hover{background:var(--surface-2);}

.topbar-title{font-family:var(--font-display); font-weight:700; font-size:1.02rem;}

.mobile-search-results{max-height:60vh; overflow-y:auto;}
.mobile-search-results a{
  display:block; padding:.8rem .2rem; border-bottom:1px solid var(--border); color:var(--text); font-size:.9rem;
}

.app-content{flex:1;}

/* ---------------- Cards / Widgets ---------------- */
.stat-card{
  background:var(--surface); border-radius:var(--radius); padding:1.25rem 1.4rem;
  box-shadow:var(--shadow-sm); border:1px solid var(--border); height:100%;
  display:flex; align-items:center; gap:1rem;
}
.stat-icon{
  width:52px; height:52px; border-radius:14px; display:flex; align-items:center; justify-content:center;
  font-size:1.3rem; color:#fff; flex-shrink:0;
}
.stat-card .label{font-size:.8rem; color:var(--text-muted); font-weight:500;}
.stat-card .value{font-family:var(--font-display); font-size:1.45rem; font-weight:800;}

.card-panel{
  background:var(--surface); border-radius:var(--radius); border:1px solid var(--border);
  box-shadow:var(--shadow-sm); padding:1.25rem;
}
.card-panel .panel-title{font-family:var(--font-display); font-weight:700; font-size:1.02rem; margin-bottom:1rem;}

/* ---------------- Tables ---------------- */
.table{color:var(--text);}
.table thead th{
  font-size:.74rem; text-transform:uppercase; letter-spacing:.04em; color:var(--text-muted);
  border-bottom:1px solid var(--border); font-weight:700; background:var(--surface-2);
}
.table td{vertical-align:middle; border-bottom:1px solid var(--border); font-size:.88rem;}
.table-hover tbody tr:hover{background:var(--surface-2);}

.avatar-sm{width:36px; height:36px; border-radius:50%; object-fit:cover; background:var(--surface-2);}
.avatar-placeholder{
  width:36px; height:36px; border-radius:50%; background:var(--teal-100); color:var(--teal-600);
  display:flex; align-items:center; justify-content:center; font-weight:700; font-size:.85rem;
}

.badge-due{background:rgba(220,38,38,.12); color:var(--danger); font-weight:600;}
.badge-clear{background:rgba(22,163,74,.12); color:var(--success); font-weight:600;}

/* ---------------- Buttons ---------------- */
.btn-primary{background:var(--teal-500); border-color:var(--teal-500);}
.btn-primary:hover{background:var(--teal-600); border-color:var(--teal-600);}
.btn-copper{background:var(--copper-500); border-color:var(--copper-500); color:#fff;}
.btn-copper:hover{background:var(--copper-600); border-color:var(--copper-600); color:#fff;}
.btn-soft{background:var(--surface-2); border:1px solid var(--border); color:var(--text);}
.btn-soft:hover{background:var(--teal-50); color:var(--teal-600);}

/* ---------------- Camera Capture ---------------- */
.camera-box{
  position:relative; width:100%; max-width:320px; margin:0 auto; border-radius:var(--radius-sm);
  overflow:hidden; background:#000; aspect-ratio:1/1;
}
.camera-box video, .camera-box canvas, .camera-box img{width:100%; height:100%; object-fit:cover;}
.photo-preview-wrap{
  width:120px; height:120px; border-radius:50%; overflow:hidden; border:3px solid var(--border);
  margin:0 auto; background:var(--surface-2); display:flex; align-items:center; justify-content:center;
}
.photo-preview-wrap img{width:100%; height:100%; object-fit:cover;}

.logo-preview-wrap{
  width:64px; height:64px; border-radius:16px; overflow:hidden; flex-shrink:0;
  background:var(--surface-2); border:1px solid var(--border);
  display:flex; align-items:center; justify-content:center; font-size:1.4rem; color:var(--text-muted);
}
.logo-preview-wrap img{width:100%; height:100%; object-fit:cover;}

/* ---------------- Misc ---------------- */
.chip{padding:.25rem .65rem; border-radius:20px; font-size:.72rem; font-weight:600; display:inline-block;}
.text-copper{color:var(--copper-500);}
.divider-label{font-size:.72rem; text-transform:uppercase; color:var(--text-muted); letter-spacing:.05em; margin:1rem 0 .5rem;}

.more-link{
  display:flex; align-items:center; gap:.9rem; padding:.85rem 1rem; border-radius:12px;
  color:var(--text); font-weight:600; font-size:.95rem;
}
.more-link i:first-child{width:22px; text-align:center; color:var(--teal-500); font-size:1.1rem;}
.more-link:active, .more-link:hover{background:var(--surface-2); color:var(--text);}
.more-link.text-danger i:first-child{color:var(--danger);}

@media (max-width:991.98px){
  .app-main{margin-left:0;}
}

/* ---------------- Mobile app shell polish ---------------- */
html{-webkit-tap-highlight-color:transparent;}
body{overflow-x:hidden; overscroll-behavior-y:contain; -webkit-overflow-scrolling:touch;}
img{max-width:100%;}
canvas{max-width:100%;}

.mobile-brand{
  width:34px; height:34px; border-radius:9px; flex-shrink:0;
  background:linear-gradient(135deg,var(--teal-500),var(--copper-500));
  color:#fff; display:flex; align-items:center; justify-content:center; font-size:1rem; overflow:hidden;
}
.mobile-brand img{width:100%; height:100%; object-fit:cover;}

@media (max-width:991.98px){
  .topbar{padding-top:env(safe-area-inset-top); height:calc(60px + env(safe-area-inset-top)); padding-left:.75rem; padding-right:.75rem;}
  .app-content{padding-bottom:calc(88px + env(safe-area-inset-bottom)) !important;}
}

/* ---------------- Bottom tab bar (mobile app feel) ---------------- */
.bottom-nav{
  position:fixed; left:0; right:0; bottom:0; z-index:1035;
  background:var(--surface); border-top:1px solid var(--border);
  display:flex; align-items:center; justify-content:space-around;
  padding:.35rem .15rem calc(.35rem + env(safe-area-inset-bottom));
  box-shadow:0 -4px 20px rgba(16,40,38,.1);
}
.bn-item{
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:2px; color:var(--text-muted); font-size:.64rem; font-weight:600;
  flex:1; padding:.35rem 0; border-radius:10px; min-width:0; -webkit-tap-highlight-color:transparent;
}
.bn-item i{font-size:1.2rem;}
.bn-item.active{color:var(--teal-500);}
.bn-item:active{background:var(--surface-2);}
.bn-fab{
  background:linear-gradient(135deg,var(--teal-500),var(--copper-500));
  color:#fff !important; width:54px; height:54px; border-radius:50%;
  margin-top:-28px; box-shadow:0 6px 18px rgba(15,118,110,.45); flex:0 0 54px;
  border:4px solid var(--surface);
}
.bn-fab i{font-size:1.35rem;}
.bn-fab span{display:none;}

/* CRITICAL FIX: the empty toast container sits fixed bottom-right with padding,
   which - even with no visible toast inside - was silently intercepting taps
   on the bottom-nav icons underneath it (Ledger/More) on both Android and iPhone.
   Only the toast bubbles themselves should be clickable, never the empty wrapper. */
.toast-container{pointer-events:none;}
.toast-container .toast{pointer-events:auto;}
@media (max-width:991.98px){
  .toast-container{bottom:calc(76px + env(safe-area-inset-bottom)) !important;}
}

.bn-item, .bn-fab{touch-action:manipulation;}

/* ---------------- Responsive tables ---------------- */
@media (max-width:767.98px){
  .table-responsive{-webkit-overflow-scrolling:touch;}
  .table thead th, .table td{white-space:nowrap; font-size:.82rem; padding:.55rem .6rem;}
  .card-panel{padding:1rem;}
  .stat-card{padding:.9rem;}
  .stat-card .value{font-size:1.15rem;}
  .stat-icon{width:44px; height:44px; font-size:1.1rem;}
  .app-content{padding:.85rem !important;}
  h4{font-size:1.15rem;}
}

/* ---------------- Responsive modals: full-screen bottom sheet on phones/small tablets ---------------- */
@media (max-width:767.98px){
  .modal{padding-right:0 !important;}
  .modal-dialog{
    margin:0; max-width:100%; width:100%; height:100%;
    display:flex; align-items:flex-end;
  }
  .modal-content{
    border-radius:18px 18px 0 0; max-height:92vh; overflow-y:auto;
    padding-bottom:env(safe-area-inset-bottom);
  }
  .modal.fade .modal-dialog{transition:transform .3s ease-out; transform:translateY(100%);}
  .modal.show .modal-dialog{transform:translateY(0);}
  .modal-body{padding:1rem;}
}

/* ---------------- Global search sizing ---------------- */
@media (max-width:991.98px){ .global-search{width:100%; max-width:260px;} }
@media (max-width:420px){ .global-search{max-width:170px;} .global-search input{font-size:.82rem; padding-left:30px;} }

/* ---------------- Touch target sizing ---------------- */
@media (max-width:767.98px){
  .btn{min-height:38px;}
  .btn-sm{min-height:32px;}
  .table .btn-sm{padding:.3rem .5rem; margin-bottom:2px;}
  .user-avatar{width:32px; height:32px; font-size:.85rem;}
  .btn-icon{width:34px; height:34px;}
}

/* ---------------- Forms stack cleanly on mobile ---------------- */
@media (max-width:575.98px){
  .modal-footer{flex-wrap:wrap; gap:.4rem;}
  .modal-footer .btn{flex:1; min-width:120px;}
}

/* ---------------- Camera box responsive ---------------- */
.camera-box{max-width:100%;}
@media (max-width:575.98px){
  .camera-box{max-width:100%; aspect-ratio:3/4;}
}

@media print{
  .sidebar, .topbar, .bottom-nav, .no-print{display:none !important;}
  .app-main{margin-left:0 !important;}
  .app-content{padding-bottom:0 !important;}
}
