/* =============================================================
   Kaaalshelf — Full Mobile Responsive CSS
   Covers: Customer site + Admin Dashboard
   All breakpoints: 980px / 920px / 860px / 760px / 640px / 480px / 380px
   ============================================================= */

/* -------------------------------------------------------
   1. SHARED UTILITIES
------------------------------------------------------- */
@media (max-width: 980px) {
  .ks-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .ks-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .ks-footer-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}

@media (max-width: 920px) {
  /* Navbar */
  .ks-nav-links,
  .ks-nav-desktop-cta { display: none !important; }
  .ks-hamburger  { display: flex !important; }
  .ks-mobile-drawer { display: block !important; }
}

@media (max-width: 760px) {
  .ks-section-head {
    flex-direction: column;
    align-items: flex-start;
  }
  .ks-section-head > .ks-btn { align-self: flex-start; }
}

@media (max-width: 640px) {
  .ks-section { padding: 36px 0; }
  .ks-container { width: calc(100% - 28px); }

  /* All grids → single column */
  .ks-grid-2,
  .ks-grid-3,
  .ks-grid-4,
  .ks-footer-grid { grid-template-columns: 1fr !important; }

  /* Navbar */
  .ks-nav-inner  { min-height: 62px; gap: 10px; }
  .ks-logo-ring  { width: 42px; height: 42px; }
  .ks-brand-name { font-size: 1.08rem; }
  .ks-cart-pill span.ks-cart-label { display: none; }
  .ks-promo-bar  { font-size: .74rem; padding: 6px 0; }

  /* Buttons */
  .ks-btn { min-height: 44px; }

  /* Forms */
  .ks-field input,
  .ks-field select,
  .ks-field textarea { font-size: 16px !important; padding: 13px 14px; }

  /* Section heads */
  .ks-section-head h2 { font-size: 1.5rem; }
  .ks-section-head > .ks-btn { padding: 9px 14px; }

  /* Footer */
  .ks-footer { padding: 36px 0 18px; }
  .ks-footer-grid { gap: 20px !important; }
  .ks-footer-bottom { flex-direction: column; gap: 6px; font-size: .76rem; }

  /* Hero */
  .ks-hero-stage { padding: 24px 0 16px !important; }
  .ks-hero-title { font-size: clamp(2rem, 9vw, 2.6rem) !important; margin: 12px 0 !important; }
  .ks-hero-sub   { font-size: .95rem !important; margin-bottom: 18px !important; }
  .ks-hero-ctas  { flex-direction: column; gap: 10px; }
  .ks-hero-ctas .ks-btn { width: 100%; text-align: center; }
  .ks-hero-stats { grid-template-columns: repeat(3, 1fr) !important; gap: 8px !important; }
  .ks-hero-stats > div { padding: 10px !important; }
  .ks-hero-3d-frame .ks-glass-card { padding: 14px !important; }
  #ksFinishSwatches { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  #ksFinishSwatches::-webkit-scrollbar { display: none; }
  #ksFinishSwatches .ks-btn { white-space: nowrap; }

  /* Product cards */
  .ks-product-card { padding: 12px; }
  .ks-product-card h3 { font-size: 1rem !important; }
  .ks-price { font-size: 1.2rem; }

  /* Steps (How it works) */
  .ks-steps { grid-template-columns: 1fr !important; gap: 12px; }
  .ks-steps::before { display: none; }
  .ks-step {
    display: grid;
    grid-template-columns: 50px 1fr;
    gap: 4px 14px;
    text-align: left;
    align-items: center;
    padding: 14px;
  }
  .ks-step-ico { grid-row: span 2; margin: 0; }
  .ks-step p   { margin: 0; }
}

@media (max-width: 480px) {
  .ks-container { width: calc(100% - 20px); }
  .ks-btn-sm    { font-size: .78rem; padding: 8px 11px; }
  .ks-glass-card { border-radius: 16px; }
  .ks-price-row  { flex-wrap: wrap; gap: 6px; }
}

/* -------------------------------------------------------
   2. BOTTOM NAV BAR (customer pages, ≤920px)
------------------------------------------------------- */
@media (max-width: 920px) {
  .ks-header .ks-cart-pill { display: none; }
  .ks-brand-sub { display: none; }

  body.ks-body {
    padding-bottom: calc(84px + env(safe-area-inset-bottom));
  }

  .ks-bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: end;
    position: fixed;
    left: 10px; right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 85;
    padding: 6px;
    border-radius: 22px;
    background: rgba(19, 10, 14, .92);
    backdrop-filter: blur(22px) saturate(160%);
    -webkit-backdrop-filter: blur(22px) saturate(160%);
    border: 1px solid var(--ks-border);
    box-shadow: 0 14px 40px rgba(0, 0, 0, .55);
    transition: transform .35s ease;
  }
  .ks-bottom-nav.is-hidden { transform: translateY(140%); }
  .ks-bottom-nav a {
    display: flex; flex-direction: column; align-items: center;
    gap: 2px; padding: 7px 2px; border-radius: 16px;
    font-size: .66rem; font-weight: 700; color: var(--ks-muted);
    transition: color .2s, background .2s;
  }
  .ks-bottom-nav a i { font-style: normal; font-size: 1.2rem; line-height: 1; position: relative; }
  .ks-bottom-nav a.active { color: var(--ks-text); background: rgba(255,255,255,.07); }
  .ks-bottom-nav-cta i {
    display: grid; place-items: center;
    width: 50px; height: 50px; margin-top: -24px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ks-accent), #9F1239);
    box-shadow: 0 8px 22px rgba(225,29,72,.55), 0 0 0 4px rgba(19,10,14,.9);
  }
  .ks-bottom-nav-cta { color: var(--ks-gold-soft) !important; background: transparent !important; }
  .ks-bn-badge {
    position: absolute; top: -8px; right: -10px;
    min-width: 17px; height: 17px; padding: 0 4px;
    border-radius: 99px; background: var(--ks-accent);
    color: #fff; font-size: .6rem; line-height: 17px; font-weight: 800;
    display: inline-flex; align-items: center; justify-content: center;
  }

  .ks-toast-wrap {
    left: 14px; right: 14px; max-width: none;
    bottom: calc(94px + env(safe-area-inset-bottom));
  }
  .ks-footer { margin-top: 40px; }

  /* Sticky buy bar on product page */
  .ks-sticky-buy {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: fixed;
    left: 10px; right: 10px;
    bottom: calc(84px + env(safe-area-inset-bottom));
    z-index: 84;
    padding: 10px 10px 10px 16px;
    border-radius: 18px;
    background: rgba(31,18,24,.95);
    border: 1px solid var(--ks-gold);
    backdrop-filter: blur(18px);
    box-shadow: 0 14px 34px rgba(0,0,0,.5);
    transform: translateY(160%);
    transition: transform .4s ease;
  }
  .ks-sticky-buy.show { transform: none; }
  .ks-sticky-buy small  { display: block; font-size: .7rem; color: var(--ks-muted); }
  .ks-sticky-buy strong { color: var(--ks-gold); font-size: 1.1rem; }
  .ks-sticky-buy .ks-btn { white-space: nowrap; padding: 11px 16px; }
}

/* -------------------------------------------------------
   3. SHOP PAGE filter toolbar
------------------------------------------------------- */
@media (max-width: 860px) {
  .ks-shop-filter-form { grid-template-columns: 1fr !important; }
}
@media (max-width: 640px) {
  .ks-shop-filter-form .ks-btn { width: 100%; }
}

/* -------------------------------------------------------
   4. PRODUCT PAGE — 2-column image + config
------------------------------------------------------- */
@media (max-width: 860px) {
  .ks-product-detail-grid { grid-template-columns: 1fr !important; }
}
@media (max-width: 640px) {
  .ks-product-inner-grid { grid-template-columns: 1fr !important; }
}

/* -------------------------------------------------------
   5. CART PAGE — items + order summary split
------------------------------------------------------- */
@media (max-width: 860px) {
  .ks-cart-grid { grid-template-columns: 1fr !important; }
}
@media (max-width: 640px) {
  /* Cart item row */
  .ks-cart-item-row {
    flex-direction: column;
    align-items: flex-start !important;
  }
  .ks-cart-item-row img { width: 100% !important; height: 180px !important; }
  .ks-cart-item-actions { width: 100%; justify-content: space-between; }
  .ks-cart-item-price   { width: 100%; text-align: left !important; }
}

/* -------------------------------------------------------
   6. CHECKOUT PAGE — form + summary split
------------------------------------------------------- */
@media (max-width: 860px) {
  .ks-checkout-grid { grid-template-columns: 1fr !important; }
}

/* -------------------------------------------------------
   7. CONTACT & CUSTOM-QUOTE — 2-col form + info
------------------------------------------------------- */
@media (max-width: 760px) {
  .ks-contact-grid,
  .ks-quote-grid { grid-template-columns: 1fr !important; }
}

/* -------------------------------------------------------
   8. SWIPEABLE ROWS (categories + featured on home)
------------------------------------------------------- */
@media (max-width: 640px) {
  .ks-swipe-row {
    display: grid !important;
    grid-auto-flow: column;
    grid-template-columns: none !important;
    grid-auto-columns: 78%;
    gap: 14px !important;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain;
    margin: 0 -14px;
    padding: 4px 14px 14px;
    scrollbar-width: none;
  }
  .ks-swipe-row::-webkit-scrollbar { display: none; }
  .ks-swipe-row > * { scroll-snap-align: start; }
  .ks-grid-4.ks-swipe-row { grid-auto-columns: 48%; }
}

/* -------------------------------------------------------
   9. ADMIN DASHBOARD (admin.php)
------------------------------------------------------- */
@media (max-width: 1024px) {
  /* KPI 4→2 */
  .ks-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  /* Quick actions 4→2 */
  .ks-quick-actions { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  /* Quote line builder */
  .ks-line {
    grid-template-columns: 1fr 1fr 1fr !important;
    grid-template-areas: "head head head" "item item item" "vendor vendor vendor" "qty cost price" "sum sum sum" !important;
  }
  .ks-line-sum {
    display: flex !important;
    justify-content: space-between;
    align-items: baseline;
    padding-top: 6px;
    border-top: 1px dashed rgba(255,255,255,.1);
  }
}

@media (max-width: 900px) {
  /* Sidebar → off-canvas */
  .ks-admin-shell { grid-template-columns: 1fr !important; }
  .ks-admin-sidebar {
    position: fixed !important;
    left: -100% !important;
    top: 0 !important;
    width: 280px !important;
    height: 100vh !important;
    z-index: 80 !important;
    transition: left .32s ease !important;
  }
  .ks-admin-sidebar.open { left: 0 !important; }
  .ks-admin-main { padding: 14px 14px 92px !important; }

  /* Mobile bottom bar */
  .ks-admin-mobile-bar {
    display: flex !important;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 70;
    background: rgba(15,8,11,.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--ks-border);
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
    justify-content: space-around;
    gap: 4px;
  }
  .ks-admin-mobile-bar button {
    flex: 1; border: 0; background: transparent;
    color: var(--ks-muted); font-size: .68rem; font-weight: 700;
    padding: 6px 4px; border-radius: 10px; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
  }
  .ks-admin-mobile-bar button i { font-style: normal; font-size: 1.1rem; line-height: 1; }
  .ks-admin-mobile-bar button.active {
    background: rgba(225,29,72,.22);
    color: var(--ks-gold-soft);
  }
  .ks-admin-mobile-bar button b {
    position: absolute; top: 0; right: calc(50% - 20px);
    min-width: 16px; height: 16px; padding: 0 3px;
    border-radius: 99px; background: var(--ks-accent);
    color: #fff; font-size: .6rem; line-height: 16px;
  }

  /* Topbar */
  .ks-admin-topbar {
    position: sticky; top: 8px; z-index: 60;
    padding: 10px 12px !important; margin-bottom: 14px !important;
    flex-wrap: nowrap !important;
  }
  .ks-admin-topbar .ks-btn-gold { display: none !important; }
  .ks-admin-topbar .ks-btn { white-space: nowrap; }

  /* All form grids collapse to 1 col */
  .ks-admin-main .ks-glass-card { border-radius: 18px; }
  .ks-admin-main .ks-grid-2,
  .ks-admin-main .ks-grid-3,
  .ks-admin-main .ks-grid-4 { grid-template-columns: 1fr !important; }

  /* iOS zoom prevention */
  .ks-admin-main input,
  .ks-admin-main select,
  .ks-admin-main textarea { font-size: 16px !important; }

  /* Toast */
  .ks-toast-wrap { left: 12px; right: 12px; bottom: 86px; }

  /* Overview bottom panels */
  .ks-overview-bottom { gap: 14px !important; }
  .ks-overview-bottom > .ks-glass-card { padding: 14px !important; }
  .ks-activity-scroll  { max-height: 240px; }
  .ks-movement-scroll  { max-height: none; overflow: visible; }

  /* ---- TABLES → stacked label cards ---- */
  .ks-admin-main table.ks-table thead { display: none; }
  .ks-admin-main table.ks-table,
  .ks-admin-main table.ks-table tbody,
  .ks-admin-main table.ks-table tr,
  .ks-admin-main table.ks-table td { display: block !important; width: 100% !important; box-sizing: border-box; }
  .ks-admin-main table.ks-table tr {
    margin-bottom: 12px; padding: 10px 12px; border-radius: 14px;
    background: rgba(255,255,255,.045); border: 1px solid var(--ks-border-soft);
  }
  .ks-admin-main table.ks-table td {
    position: relative; border: 0 !important;
    padding: 5px 0 5px 106px !important; min-height: 28px;
  }
  .ks-admin-main table.ks-table td::before {
    content: attr(data-label);
    position: absolute; left: 0; top: 7px;
    width: 98px; font-size: .6rem; font-weight: 800;
    text-transform: uppercase; letter-spacing: .04em;
    line-height: 1.3; color: var(--ks-gold-soft);
  }
  /* First td = row title — no indent, no label (title is self-explanatory) */
  .ks-admin-main table.ks-table td:first-child {
    padding-left: 0 !important; font-size: .96rem;
    padding-bottom: 8px !important;
    border-bottom: 1px solid rgba(255,255,255,.07) !important;
  }
  .ks-admin-main table.ks-table td:first-child::before { display: none; }

  /* Last td = actions (buttons) — no label, full width, no indent */
  /* Only suppress label when the td contains buttons (data-label="Actions") */
  .ks-admin-main table.ks-table td[data-label="Actions"] {
    padding-left: 0 !important; padding-top: 10px !important;
  }
  .ks-admin-main table.ks-table td[data-label="Actions"]::before { display: none; }

  .ks-table-wrap { overflow-x: visible !important; }

  /* Modals → slide up from bottom as full-width sheet */
  .ks-modal-backdrop { align-items: flex-end !important; padding: 0 !important; }
  .ks-modal {
    width: 100% !important;
    max-height: 90dvh !important;
    border-radius: 24px 24px 0 0 !important;
    padding: 0 !important;
    transform: translateY(100%) !important;
    overflow-y: auto;
  }
  .ks-modal-backdrop.open .ks-modal { transform: none !important; }

  /* Sticky modal header */
  .ks-modal > div:first-child {
    position: sticky; top: 0; z-index: 10;
    padding: 14px 18px 12px !important;
    background: rgba(28,15,22,.98) !important;
    border-bottom: 1px solid var(--ks-border-soft);
    border-radius: 24px 24px 0 0;
    margin-bottom: 0 !important;
    display: flex !important;
    align-items: center;
    justify-content: space-between;
  }
  /* Modal body content */
  .ks-modal > .ks-form-grid,
  .ks-modal > div:not(:first-child) {
    padding: 16px 18px;
  }
  .ks-modal h3 { font-size: 1rem !important; margin: 0 !important; max-width: calc(100% - 48px); }
  .ks-modal h4 { margin-top: 10px; }

  /* Modal inputs: 16px prevents iOS zoom */
  .ks-modal .ks-field input,
  .ks-modal .ks-field select,
  .ks-modal .ks-field textarea { font-size: 16px !important; width: 100%; }
  .ks-modal .ks-field { min-width: 0; }

  /* Qty stepper — MUST stay 3-column */
  .ks-qty-stepper {
    display: grid !important;
    grid-template-columns: 54px 1fr 54px !important;
    gap: 8px !important;
  }
  .ks-qty-stepper input {
    text-align: center !important;
    font-size: 1.1rem !important;
    /* width stays auto inside its grid cell */
    width: auto !important;
    min-width: 0;
  }
  .ks-qty-step { min-height: 46px !important; font-size: 1.3rem !important; }

  /* Summary / payment modal layout */
  .ks-sm-info  { width: 100%; flex-wrap: wrap; }
  .ks-sm-nums  { width: 100%; justify-content: space-between; }
  .ks-sum-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .ks-sum-kpis > div { padding: 9px !important; min-width: 0; }
  .ks-sum-kpis strong { font-size: .92rem !important; overflow-wrap: anywhere; }
  .ks-modal .ks-grid-2 { grid-template-columns: 1fr 1fr !important; }
}

@media (max-width: 560px) {
  .ks-kpi-grid { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
  .ks-kpi-card { padding: 14px !important; }
  .ks-kpi-val  { font-size: 1.25rem !important; }
  .ks-kpi-sub  { font-size: .7rem !important; }
  .ks-qa { padding: 14px 12px !important; font-size: .84rem !important; }
  .ks-qty-stepper { grid-template-columns: 46px 1fr 46px !important; }
}

@media (max-width: 400px) {
  .ks-kpi-grid { grid-template-columns: 1fr !important; }
  .ks-qty-stepper { grid-template-columns: 42px 1fr 42px !important; }
  .ks-admin-mobile-bar button { font-size: .62rem !important; padding: 5px 2px !important; }
}
