/* ==========================================================================
   BOOKISH BD CRM - World-Class Modern SaaS Design (Desktop & Mobile)
   ========================================================================== */

:root {
  --navy: #0f172a;
  --navy-light: #1e293b;
  --blue: #2563eb;
  --blue-hover: #1d4ed8;
  --blue-l: #eff6ff;
  --blue-border: #bfdbfe;
  
  --green: #10b981;
  --green-l: #ecfdf5;
  --green-text: #047857;
  
  --red: #f43f5e;
  --red-l: #fff1f2;
  --red-text: #be123c;
  
  --amber: #f59e0b;
  --amber-l: #fffbeb;
  --amber-text: #b45309;
  
  --purple: #8b5cf6;
  --purple-l: #f5f3ff;
  
  --bg-page: #f8fafc;
  --card-bg: #ffffff;
  --gray1: #f1f5f9;
  --gray2: #e2e8f0;
  --gray3: #cbd5e1;
  --gray4: #94a3b8;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-light: #64748b;
  
  --radius: 14px;
  --radius-sm: 8px;
  --radius-pill: 9999px;
  
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 14px -2px rgba(0, 0, 0, 0.06), 0 2px 6px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 25px -3px rgba(0, 0, 0, 0.08), 0 4px 10px -2px rgba(0, 0, 0, 0.04);
  --shadow-card: 0 1px 3px rgba(0,0,0,0.04), 0 6px 16px rgba(0,0,0,0.04);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-page);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  margin: 0;
  padding: 0;
  letter-spacing: -0.1px;
}

/* ==================== LOGIN SCREEN ==================== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 10% 20%, #1e293b 0%, #0f172a 90%);
}

.login-box {
  background: #ffffff;
  border-radius: 20px;
  padding: 36px 30px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.login-logo { text-align: center; font-size: 46px; margin-bottom: 10px; }
.login-title { text-align: center; font-size: 22px; font-weight: 800; color: var(--navy); margin-bottom: 4px; letter-spacing: -0.5px; }
.login-sub { text-align: center; font-size: 13px; color: var(--text-light); margin-bottom: 24px; }
.login-box input { border: 1.5px solid var(--gray2); border-radius: 10px; padding: 12px 14px; font-family: inherit; font-size: 14px; width: 100%; margin-bottom: 12px; outline: none; background: #fff; transition: all .2s; }
.login-box input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.login-btn { width: 100%; background: var(--blue); color: #fff; border: none; border-radius: 10px; padding: 13px; font-family: inherit; font-size: 14px; font-weight: 700; cursor: pointer; transition: background .2s; }
.login-btn:hover { background: var(--blue-hover); }
.login-err { color: var(--red); font-size: 12px; text-align: center; margin-top: 8px; display: none; font-weight: 600; }
.reset-btn { width: 100%; background: none; border: none; color: var(--gray4); font-size: 12px; margin-top: 12px; cursor: pointer; font-family: inherit; padding: 6px; }

/* ==================== BADGES & PILLS ==================== */
.role-badge { display: inline-block; padding: 4px 12px; border-radius: var(--radius-pill); font-size: 11px; font-weight: 700; letter-spacing: 0.2px; }
.rb-admin { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.rb-staff { background: var(--blue-l); color: var(--blue); border: 1px solid var(--blue-border); }
.rb-viewer { background: var(--green-l); color: var(--green-text); border: 1px solid #a7f3d0; }

.badge { display: inline-block; padding: 3px 8px; border-radius: var(--radius-pill); font-size: 10px; font-weight: 700; margin-left: 4px; }
.b-c { background: #dcfce7; color: #15803d; }
.b-pre { background: #f3e8ff; color: #7e22ce; }
.b-p { background: #fef3c7; color: #b45309; }
.b-x { background: #ffe4e6; color: #be123c; }
.b-d { background: #dbeafe; color: #1d4ed8; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 9px; border: none; font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s ease; box-shadow: var(--shadow-sm); }
.btn:hover { opacity: .92; transform: translateY(-1px); }
.btn-b { background: var(--blue); color: #fff; }
.btn-g { background: var(--green); color: #fff; }
.btn-r { background: var(--red); color: #fff; }
.ibtn { width: 28px; height: 28px; border-radius: 7px; border: none; cursor: pointer; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; transition: background .15s; }
.ibtn-e { background: var(--blue-l); color: var(--blue); }
.ibtn-e:hover { background: #dbeafe; }
.ibtn-d { background: var(--red-l); color: var(--red); }
.ibtn-d:hover { background: #fee2e2; }

/* ==================== FORM INPUTS ==================== */
.fg { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.fg.half { width: calc(50% - 5px); }
.frow { display: flex; gap: 10px; flex-wrap: wrap; width: 100%; }
label.lb { font-size: 11.5px; font-weight: 600; color: var(--text-muted); display: block; margin-bottom: 2px; }
input, select, textarea { border: 1.5px solid var(--gray2); border-radius: 9px; padding: 9px 12px; font-family: inherit; font-size: 14px !important; color: var(--text-main); background: #ffffff; outline: none; width: 100%; transition: border-color .2s, box-shadow .2s; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
textarea { resize: vertical; min-height: 65px; }

/* ==================== KPI CARDS (DASHBOARD) ==================== */
.krow { display: flex; gap: 10px; margin-bottom: 12px; }
.kpi {
  flex: 1;
  border-radius: var(--radius);
  padding: 16px 14px;
  color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.kpi:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}

.kpi label {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.92;
  display: block;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.kpi .v {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.5px;
}

/* Modern Gradient Color Themes */
.bg-g { background: linear-gradient(135deg, #059669 0%, #10b981 100%); }
.bg-b { background: linear-gradient(135deg, #1d4ed8 0%, #3b82f6 100%); }
.bg-n { background: linear-gradient(135deg, #0f172a 0%, #334155 100%); }
.bg-r { background: linear-gradient(135deg, #be123c 0%, #f43f5e 100%); }
.bg-a { background: linear-gradient(135deg, #b45309 0%, #f59e0b 100%); }
.bg-p { background: linear-gradient(135deg, #6d28d9 0%, #8b5cf6 100%); }

/* ==================== ORDER CARDS ==================== */
.card { background: var(--card-bg); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow-card); border: 1px solid var(--gray2); }
.oc {
  background: var(--card-bg);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--gray2);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.oc:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.oc.confirmed { border-left: 4px solid var(--green); }
.oc.pending { border-left: 4px solid var(--amber); }
.oc.delivered { border-left: 4px solid var(--blue); }
.oc.cancel { border-left: 4px solid var(--red); opacity: 0.9; }

.oh { display: flex; justify-content: space-between; align-items: flex-start; padding: 14px 16px 8px; }
.oid { font-weight: 800; font-size: 13px; color: var(--navy); }
.odate { font-size: 11px; color: var(--text-light); margin-top: 2px; }
.obdy { padding: 4px 16px 12px; font-size: 12px; color: var(--text-muted); }
.obooks { background: var(--gray1); border-radius: 8px; padding: 8px 12px; margin: 6px 0; line-height: 1.5; font-size: 11.5px; color: var(--text-main); border: 1px solid var(--gray2); }
.oftr { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: #fafafa; border-top: 1px solid var(--gray2); }
.ototal { font-weight: 800; font-size: 14px; color: var(--green-text); }

/* ==================== SEARCH & FILTER CHIPS ==================== */
.chips { display: flex; gap: 7px; overflow-x: auto; scrollbar-width: none; margin-bottom: 14px; padding-bottom: 2px; }
.chip {
  flex: none;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--gray2);
  background: #ffffff;
  color: var(--text-muted);
  box-shadow: var(--shadow-sm);
  transition: all .15s ease;
}
.chip:hover {
  background: var(--gray1);
  color: var(--text-main);
}
.chip.on {
  border-color: var(--blue);
  color: #ffffff;
  background: var(--blue);
  box-shadow: 0 4px 12px rgba(37,99,235,0.25);
}

.srch { position: relative; margin-bottom: 12px; }
.srch input { padding-left: 36px; font-size: 14px; border-radius: 10px; border: 1.5px solid var(--gray2); }
.srch::before { content: '🔍'; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 13px; }
.sl { font-size: 11px; font-weight: 800; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.8px; margin: 16px 0 10px; }

/* In-stock, reports and tables */
.si { background: #fff; border-radius: var(--radius); padding: 14px 16px; margin-bottom: 8px; box-shadow: var(--shadow-card); display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--gray2); }
.sqty { font-size: 22px; font-weight: 800; color: var(--blue); }
.sqty.low { color: var(--red); }

.mrow { background: #fff; border-radius: var(--radius); margin-bottom: 8px; overflow: hidden; box-shadow: var(--shadow-card); border: 1px solid var(--gray2); }
.mhead { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; cursor: pointer; }
.mn, .mp { font-weight: 700; font-size: 13.5px; }
.mp.pos { color: var(--green); }
.mp.neg { color: var(--red); }
.mdet { display: none; padding: 0 16px 14px; border-top: 1px solid var(--gray2); }
.mdet.on { display: block; }
.dr { display: flex; justify-content: space-between; padding: 7px 0; font-size: 12px; border-bottom: 1px solid var(--gray1); }
.dr:last-child { border: none; font-weight: 700; font-size: 13px; padding-top: 8px; }

.rank-item { background: #fff; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 8px; box-shadow: var(--shadow-card); display: flex; align-items: center; gap: 12px; cursor: pointer; border: 1px solid var(--gray2); }
.rank-no { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12px; flex-shrink: 0; }
.rank-1 { background: #FFD700; color: #000; }
.rank-2 { background: #E2E8F0; color: #334155; }
.rank-3 { background: #FED7AA; color: #9A3412; }
.rank-other { background: var(--gray1); color: var(--text-muted); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 11px 24px; border-radius: var(--radius-pill); font-size: 13px; font-weight: 600; z-index: 99999; display: none; white-space: nowrap; box-shadow: var(--shadow-lg); }
.toast.on { display: block; }
.loader { text-align: center; padding: 36px; color: var(--text-light); font-size: 13px; }
.spin { display: inline-block; width: 28px; height: 28px; border: 3px solid var(--gray2); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==================== MODALS ==================== */
.mover { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.6); z-index: 200; align-items: flex-end; justify-content: center; backdrop-filter: blur(4px); }
.mover.on { display: flex; }
.modal { background: #fff; border-radius: 20px 20px 0 0; width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh; overflow-y: auto; overflow-x: hidden; padding: 22px 18px 0; position: relative; }
.mtitle { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.mtitle span { font-size: 16px; font-weight: 800; color: var(--navy); }
.xbtn { width: 30px; height: 30px; border-radius: 50%; background: var(--gray1); border: none; font-size: 15px; cursor: pointer; color: var(--text-muted); display: flex; align-items: center; justify-content: center; transition: background .15s; }
.xbtn:hover { background: var(--gray2); color: var(--text-main); }
.sticky-save { position: sticky; bottom: 0; background: #fff; padding: 14px 0 calc(14px + env(safe-area-inset-bottom)); margin-top: 14px; border-top: 1px solid var(--gray1); z-index: 5; }

/* GMODAL */
#gmodal { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.6); z-index: 250; display: none; backdrop-filter: blur(4px); }
#gmodal.on { display: block; }

/* ==================== MOBILE LAYOUT (< 900px) ==================== */
@media (max-width: 899px) {
  #main-app {
    display: block;
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
  }
  .top {
    background: var(--navy);
    color: #fff;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
  }
  .top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .top h1 { font-size: 15px; font-weight: 800; letter-spacing: -0.3px; }
  .logout-btn { background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.15); color: #fff; border-radius: 8px; padding: 5px 11px; font-size: 11px; cursor: pointer; font-family: inherit; font-weight: 600; }
  .hbtn { display: flex; align-items: center; gap: 8px; margin-top: 10px; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.15); color: #fff; border-radius: 10px; padding: 10px 14px; font-size: 13.5px; font-weight: 700; cursor: pointer; width: 100%; }
  
  #hmenu { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); z-index: 200; display: none; backdrop-filter: blur(2px); }
  #hmenu.on { display: block; }
  #hmenu .hmenu-inner { position: absolute; top: 0; left: 0; bottom: 0; width: 80%; max-width: 320px; background: #fff; box-shadow: 4px 0 24px rgba(0,0,0,0.15); overflow-y: auto; padding: 16px 12px; transform: translateX(-100%); transition: transform .22s cubic-bezier(0.4, 0, 0.2, 1); }
  #hmenu.on .hmenu-inner { transform: translateX(0); }
  .hmenu-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 11px 14px; border-radius: 9px; font-size: 14px; color: var(--text-muted); background: none; border: none; cursor: pointer; margin-bottom: 3px; font-weight: 600; }
  .hmenu-item.on { background: var(--blue-l); color: var(--blue); font-weight: 800; }
  #hmenu .hmenu-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px 14px; border-bottom: 1px solid var(--gray2); margin-bottom: 10px; }
  
  .tabs { display: none; }
  .pg { display: none; padding: 14px 14px 60px; }
  .pg.on { display: block; }
}

/* ==================== DESKTOP LAYOUT (>= 900px) ==================== */
@media (min-width: 900px) {
  body {
    background: #f8fafc;
  }

  #main-app {
    display: flex !important;
    flex-direction: row !important;
    min-height: 100vh !important;
    width: 100% !important;
  }

  /* Desktop Permanent Left Sidebar */
  #hmenu {
    display: block !important;
    position: sticky !important;
    top: 0 !important;
    height: 100vh !important;
    width: 260px !important;
    min-width: 260px !important;
    max-width: 260px !important;
    background: #ffffff !important;
    border-right: 1px solid var(--gray2) !important;
    z-index: 100 !important;
    box-shadow: 2px 0 12px rgba(0,0,0,0.02) !important;
    flex-shrink: 0 !important;
  }

  #hmenu .hmenu-inner {
    position: relative !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    transform: none !important;
    transition: none !important;
    box-shadow: none !important;
    padding: 22px 14px !important;
    overflow-y: auto !important;
    box-sizing: border-box !important;
  }

  #hmenu .hmenu-head {
    display: flex !important;
    align-items: center !important;
    padding: 4px 8px 18px !important;
    border-bottom: 1px solid var(--gray2) !important;
    margin-bottom: 14px !important;
  }

  #hmenu .hmenu-head button {
    display: none !important;
  }

  #hmenu .hmenu-head span {
    font-size: 17px !important;
    color: var(--navy) !important;
    font-weight: 900 !important;
    letter-spacing: -0.4px !important;
  }

  .hmenu-item {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    width: 100% !important;
    text-align: left !important;
    padding: 10px 14px !important;
    border-radius: 9px !important;
    font-size: 13.5px !important;
    color: var(--text-muted) !important;
    background: none !important;
    border: none !important;
    cursor: pointer !important;
    margin-bottom: 3px !important;
    font-weight: 600 !important;
    transition: background 0.15s ease, color 0.15s ease !important;
  }

  .hmenu-item:hover {
    background: var(--gray1) !important;
    color: var(--text-main) !important;
  }

  .hmenu-item.on {
    background: var(--blue-l) !important;
    color: var(--blue) !important;
    font-weight: 800 !important;
  }

  /* Main Content Area */
  .main-content-wrapper {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    min-width: 0 !important;
    background: var(--bg-page) !important;
  }

  .top {
    position: sticky !important;
    top: 0 !important;
    z-index: 90 !important;
    padding: 16px 40px !important;
    background: #0f172a !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08) !important;
  }

  .top-row {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
  }

  .top h1 {
    font-size: 19px !important;
    font-weight: 800 !important;
    letter-spacing: -0.4px !important;
  }

  .logout-btn {
    background: rgba(255,255,255,0.12) !important;
    border: 1px solid rgba(255,255,255,0.2) !important;
    color: #fff !important;
    border-radius: 8px !important;
    padding: 7px 16px !important;
    font-size: 12px !important;
    cursor: pointer !important;
    font-family: inherit !important;
    font-weight: 700 !important;
    transition: background .15s ease !important;
  }

  .logout-btn:hover {
    background: rgba(255,255,255,0.2) !important;
  }

  .hbtn {
    display: none !important;
  }

  .tabs {
    display: none !important;
  }

  .pg {
    display: none;
    padding: 30px 40px 60px !important;
    max-width: 1440px !important;
    margin: 0 auto !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .pg.on {
    display: block !important;
  }

  /* Desktop KPI Cards Grid */
  .krow {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)) !important;
    gap: 16px !important;
    margin-bottom: 18px !important;
  }

  .kpi {
    padding: 20px 18px !important;
    border-radius: 16px !important;
  }

  .kpi label {
    font-size: 11.5px !important;
    margin-bottom: 6px !important;
    letter-spacing: 0.6px !important;
  }

  .kpi .v {
    font-size: 26px !important;
    letter-spacing: -0.5px !important;
  }

  /* Multi-Column Cards Layout */
  #ord-list, #recent {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(370px, 1fr)) !important;
    gap: 18px !important;
  }

  #ord-list > div:first-child, #ord-list > button:last-child {
    grid-column: 1 / -1 !important;
  }

  .oc {
    margin-bottom: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
  }

  .srch {
    max-width: 520px !important;
  }

  /* Centered Desktop Modals */
  .mover {
    align-items: center !important;
    justify-content: center !important;
    padding: 24px !important;
  }

  .modal {
    border-radius: 20px !important;
    max-width: 700px !important;
    max-height: 88vh !important;
    padding: 28px 24px !important;
    box-shadow: 0 25px 70px rgba(0,0,0,0.3) !important;
  }
}


/* ==================== SUB-TABS & SELECTS (ALL PAGES) ==================== */
.stabs {
  display: flex !important;
  gap: 6px !important;
  margin-bottom: 12px !important;
  overflow-x: auto !important;
  scrollbar-width: none !important;
  padding-bottom: 2px !important;
}
.stabs::-webkit-scrollbar { display: none; }

.stab {
  flex: none !important;
  padding: 6px 12px !important;
  border-radius: var(--radius-pill) !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  cursor: pointer !important;
  background: #ffffff !important;
  color: var(--text-muted) !important;
  box-shadow: var(--shadow-sm) !important;
  border: 1.5px solid var(--gray2) !important;
  transition: all .15s ease !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}
.stab:hover {
  background: var(--gray1) !important;
  color: var(--text-main) !important;
}
.stab.on {
  background: var(--navy) !important;
  color: #ffffff !important;
  border-color: var(--navy) !important;
  box-shadow: 0 4px 12px rgba(15,23,42,0.25) !important;
}

.yr-sel {
  background: var(--navy) !important;
  color: #ffffff !important;
  border: none !important;
  border-radius: 8px !important;
  padding: 7px 12px !important;
  font-family: inherit !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  cursor: pointer !important;
  margin-bottom: 10px !important;
  outline: none !important;
}

.pub-sg-item:hover, .pub-sg-item:active {
  background: var(--blue-l) !important;
}

.no-access {
  text-align: center !important;
  padding: 60px 20px !important;
  color: var(--text-light) !important;
}

.staff-locked .hbtn {
  display: none !important;
}
