:root {
  --bg: #f5f7fb;
  --surface: rgba(255,255,255,.92);
  --surface-solid: #ffffff;
  --surface-soft: #f8fafc;
  --line: #e8edf4;
  --line-strong: #dde5ee;
  --text: #172033;
  --muted: #718096;
  --muted-2: #94a3b8;
  --sidebar: #172033;
  --sidebar-2: #1d293d;
  --sidebar-text: #cbd5e1;
  --primary: #5b6ee1;
  --primary-dark: #4b5fd0;
  --primary-soft: #eef1ff;
  --success: #36a77a;
  --success-soft: #eaf8f2;
  --warning: #d79a3b;
  --warning-soft: #fff7e8;
  --danger: #d96b78;
  --danger-soft: #fff0f2;
  --info: #5a91c8;
  --info-soft: #edf5fc;
  --shadow-sm: 0 2px 12px rgba(30, 45, 70, .045);
  --shadow: 0 10px 32px rgba(30, 45, 70, .07);
  --shadow-hover: 0 16px 42px rgba(30, 45, 70, .11);
  --radius: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

::selection { background: #e3e8ff; color: #303d78; }

.app-shell { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 258px;
  flex: 0 0 258px;
  background: linear-gradient(180deg, var(--sidebar) 0%, #141d2e 100%);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
  box-shadow: 8px 0 28px rgba(21, 31, 49, .08);
  border-right: 1px solid rgba(255,255,255,.035);
}
.sidebar-brand {
  height: 76px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 22px;
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -.01em;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-brand i {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(126,143,255,.16);
  color: #b9c2ff;
  font-size: 1.05rem;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
.sidebar-nav { padding: 18px 12px 24px; overflow-y: auto; }
.sidebar-section {
  margin: 20px 10px 8px;
  color: #748198;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
}
.sidebar-nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 3px 0;
  padding: 11px 13px;
  border-radius: 12px;
  color: #aeb9ca;
  text-decoration: none;
  font-size: .9rem;
  font-weight: 500;
  transition: background .22s ease, color .22s ease, transform .22s ease;
}
.sidebar-nav a i { width: 20px; text-align: center; font-size: 1rem; opacity: .88; }
.sidebar-nav a:hover {
  background: rgba(255,255,255,.055);
  color: #fff;
  transform: translateX(2px);
}
.sidebar-nav a.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(105,121,234,.22), rgba(105,121,234,.09));
  box-shadow: inset 0 0 0 1px rgba(144,157,255,.11);
}
.sidebar-nav a.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 0 4px 4px 0;
  background: #8d9aff;
}

/* ---------- Top bar ---------- */
.topbar {
  min-height: 76px;
  background: rgba(255,255,255,.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  padding-left: 28px !important;
  padding-right: 28px !important;
  position: sticky;
  top: 0;
  z-index: 40;
}
.page-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: #202a3d;
}
.topbar .dropdown > .btn {
  border: 1px solid var(--line) !important;
  background: #fff !important;
  color: #455166 !important;
  border-radius: 11px;
  padding: 8px 12px;
  box-shadow: var(--shadow-sm);
}
.topbar .dropdown > .btn:hover { border-color: #d7dfeb !important; background: #fbfcfe !important; }
.dropdown-menu {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 7px;
  box-shadow: var(--shadow-hover);
  margin-top: 8px !important;
}
.dropdown-item { border-radius: 9px; padding: 9px 11px; color: #455166; }
.dropdown-item:hover { background: var(--surface-soft); color: var(--text); }

main.p-4 { padding: 28px !important; }

/* ---------- Premium cards ---------- */
.kpi-card, .card-panel {
  background: var(--surface);
  border: 1px solid rgba(221,229,238,.82);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease;
}
.kpi-card {
  position: relative;
  min-height: 128px;
  padding: 21px 22px;
  overflow: hidden;
}
.kpi-card::after {
  content: "";
  position: absolute;
  width: 100px;
  height: 100px;
  right: -42px;
  bottom: -48px;
  border-radius: 50%;
  background: rgba(91,110,225,.045);
}
.kpi-card:hover, .card-panel:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: #dce4ee;
}
.kpi-label {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .075em;
}
.kpi-value {
  margin-top: 5px;
  color: #1e293b;
  font-size: 1.72rem;
  line-height: 1.15;
  font-weight: 750;
  letter-spacing: -.035em;
}
.kpi-icon {
  position: relative;
  z-index: 1;
  width: 45px !important;
  height: 45px !important;
  border-radius: 14px !important;
  display: grid !important;
  place-items: center !important;
  font-size: 1.05rem !important;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.5);
}
.card-panel { padding: 22px; }
.card-panel h6, .card-panel .fw-bold { color: #263248; letter-spacing: -.01em; }
.card-panel .text-muted { color: var(--muted) !important; }

/* ---------- Buttons ---------- */
.btn {
  border-radius: 10px;
  font-weight: 600;
  letter-spacing: -.005em;
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  box-shadow: 0 5px 14px rgba(91,110,225,.16);
}
.btn-primary:hover { background: var(--primary-dark) !important; border-color: var(--primary-dark) !important; box-shadow: 0 8px 18px rgba(91,110,225,.21); }
.btn-outline-primary { color: var(--primary); border-color: #ccd4f7; background: #fbfcff; }
.btn-outline-primary:hover { color: var(--primary-dark); background: var(--primary-soft); border-color: #bbc5f4; }
.btn-outline-secondary { color: #64748b; border-color: var(--line-strong); background: #fff; }
.btn-outline-secondary:hover { color: #334155; background: var(--surface-soft); border-color: #ccd6e2; }
.btn-light { border-color: var(--line); }

/* ---------- Forms / filters ---------- */
.form-label {
  color: #526078;
  font-size: .76rem;
  font-weight: 700;
  margin-bottom: 7px;
}
.form-control, .form-select {
  min-height: 42px;
  border: 1px solid #dfe6ef;
  border-radius: 11px;
  background: #fbfcfe;
  color: #334155;
  box-shadow: inset 0 1px 2px rgba(20,30,50,.015);
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}
.form-control::placeholder { color: #a4afbf; }
.form-control:focus, .form-select:focus {
  border-color: #aeb8ed;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(91,110,225,.09);
}
.form-check-input { border-color: #ccd6e2; }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }

/* ---------- Tables ---------- */
.table-responsive { border-radius: 13px; }
.table {
  --bs-table-bg: transparent;
  color: #465267;
  margin-bottom: 0;
}
.table > :not(caption) > * > * {
  padding: .82rem .78rem;
  border-bottom-color: #edf1f5;
  vertical-align: middle;
}
.table thead th {
  color: #8490a3;
  background: #fafbfd;
  border-bottom: 1px solid var(--line) !important;
  font-size: .69rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: .065em;
  white-space: nowrap;
}
.table tbody tr { transition: background .18s ease; }
.table tbody tr:hover { background: #fafbfe; }
.table tbody td { font-size: .86rem; }
.table tbody tr:last-child td { border-bottom: 0; }

/* ---------- Status pills ---------- */
.badge {
  border-radius: 999px !important;
  padding: .43em .72em;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .015em;
}
.badge-status-clear { background: var(--success-soft) !important; color: #2b8a67 !important; }
.badge-status-pending { background: var(--warning-soft) !important; color: #aa7425 !important; }
.badge-status-not_deliver { background: var(--danger-soft) !important; color: #b4515d !important; }

.alert {
  border-radius: 14px;
  border-width: 1px;
  box-shadow: var(--shadow-sm);
}

/* ---------- Pagination ---------- */
.pagination { gap: 5px; }
.pagination .page-link {
  border: 1px solid var(--line);
  border-radius: 9px !important;
  color: #66758c;
  background: #fff;
  min-width: 36px;
  text-align: center;
}
.pagination .page-item.active .page-link {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.pagination .page-link:hover { background: var(--surface-soft); }

/* ---------- Login ---------- */
.login-wrap {
  position: fixed !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  min-height: 100svh;
  padding: 24px;
  display: grid !important;
  place-items: center !important;
  overflow-y: auto;
  background:
    radial-gradient(circle at 15% 20%, rgba(139,153,255,.15), transparent 34%),
    radial-gradient(circle at 85% 80%, rgba(97,177,151,.10), transparent 30%),
    #f3f6fb;
}
.login-card {
  width: min(430px, calc(100vw - 48px));
  max-width: 430px;
  margin: 0 auto !important;
  justify-self: center !important;
  padding: 42px;
  background: rgba(255,255,255,.94);
  border: 1px solid rgba(220,228,238,.9);
  border-radius: 24px;
  box-shadow: 0 24px 70px rgba(34,48,73,.12);
  backdrop-filter: blur(18px);
}
.login-card .form-control { min-height: 46px; }
.security-puzzle {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(90px, 120px);
  gap: 10px;
  align-items: center;
}
.security-question {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid #dce4ee;
  border-radius: 10px;
  background: #f7f9fc;
  color: #27364d;
  font-weight: 700;
  letter-spacing: .03em;
}

/* ---------- Soft chart / canvas presentation ---------- */
canvas { max-width: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 1199px) {
  .sidebar { width: 238px; flex-basis: 238px; }
  main.p-4 { padding: 22px !important; }
}
@media (max-width: 992px) {
  .sidebar {
    position: fixed;
    left: -270px;
    top: 0;
    bottom: 0;
    transition: left .28s cubic-bezier(.2,.8,.2,1);
  }
  .sidebar.open { left: 0; }
  .topbar { min-height: 68px; padding-left: 18px !important; padding-right: 18px !important; }
  main.p-4 { padding: 18px !important; }
}
@media (max-width: 576px) {
  .kpi-card { min-height: 112px; padding: 17px; }
  .kpi-value { font-size: 1.42rem; }
  .card-panel { padding: 17px; border-radius: 15px; }
  .sidebar-brand { height: 68px; }
  .login-card { padding: 30px 24px; border-radius: 20px; }
}

/* Reduced motion accessibility */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

/* Customer/order status pills */
.badge-status-new_order { background: #eef2f7 !important; color: #66758c !important; }

/* Dashboard order pipeline - soft visual legend */
.pipeline-legend{display:grid;grid-template-columns:1fr 1fr;gap:8px 14px;margin-top:12px;color:#64748b;font-size:.78rem}
.pipeline-legend>div{display:flex;align-items:center;gap:7px}
.pipeline-legend strong{margin-left:auto;color:#0f172a;font-weight:700}
.pipeline-legend .dot{width:8px;height:8px;border-radius:50%;display:inline-block;flex:0 0 8px}
.dot-new{background:#94a3b8}.dot-cut{background:#d97706}.dot-stitch{background:#2563eb}.dot-delivered{background:#059669}

/* ---------- Desktop sidebar collapse / premium toggle ---------- */
.sidebar {
  transition: width .28s cubic-bezier(.22,.61,.36,1), flex-basis .28s cubic-bezier(.22,.61,.36,1);
}
.sidebar-brand { position: relative; justify-content: space-between; }
.sidebar-brand-main { min-width: 0; display: flex; align-items: center; gap: 12px; }
.sidebar-brand-main > span { white-space: nowrap; overflow: hidden; transition: opacity .2s ease, width .28s ease; }

/* Premium circular sidebar toggle */
.sidebar-collapse {
  position: absolute;
  right: 14px;
  top: 20px;
  width: 40px;
  height: 40px;
  padding: 0;
  flex: 0 0 40px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 13px;
  background: linear-gradient(145deg, rgba(255,255,255,.11), rgba(255,255,255,.045));
  color: #dbe5f5;
  cursor: pointer;
  z-index: 60;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 6px 18px rgba(0,0,0,.12), inset 0 1px 0 rgba(255,255,255,.06);
  transition: transform .2s ease, background .2s ease, border-color .2s ease, box-shadow .2s ease, color .2s ease;
}
.sidebar-collapse i {
  font-size: 1rem;
  line-height: 1;
  transition: transform .25s cubic-bezier(.22,.61,.36,1);
}
.sidebar-collapse:hover {
  background: linear-gradient(145deg, rgba(255,255,255,.17), rgba(255,255,255,.07));
  border-color: rgba(255,255,255,.23);
  color: #fff;
  box-shadow: 0 10px 24px rgba(0,0,0,.2), inset 0 1px 0 rgba(255,255,255,.08);
  transform: translateY(-1px);
}
.sidebar-collapse:active { transform: scale(.93); }
.sidebar-collapse:focus-visible {
  outline: 3px solid rgba(141,154,255,.34);
  outline-offset: 3px;
}
.sidebar-nav a span { white-space: nowrap; overflow: hidden; transition: opacity .2s ease, width .28s ease; }

/* Collapsed state on desktop/tablet */
@media (min-width: 993px) {
  .app-shell.sidebar-is-collapsed .sidebar {
    width: 82px;
    flex-basis: 82px;
  }
  .app-shell.sidebar-is-collapsed .sidebar-brand {
    padding: 0 14px;
    justify-content: center;
  }
  .app-shell.sidebar-is-collapsed .sidebar-brand-main {
    justify-content: center;
  }
  .app-shell.sidebar-is-collapsed .sidebar-brand-main > span,
  .app-shell.sidebar-is-collapsed .sidebar-nav a span,
  .app-shell.sidebar-is-collapsed .sidebar-section span {
    width: 0;
    opacity: 0;
    pointer-events: none;
  }
  .app-shell.sidebar-is-collapsed .sidebar-brand-main { gap: 0; }
  .app-shell.sidebar-is-collapsed .sidebar-brand-main > i { width: 38px; }

  /* Toggle moves to the sidebar edge and becomes an expand chevron */
  .app-shell.sidebar-is-collapsed .sidebar-collapse {
    right: -20px;
    top: 18px;
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,.96);
    color: #53627a;
    border-color: #dfe6ef;
    box-shadow: 0 8px 24px rgba(20,30,50,.16);
  }
  .app-shell.sidebar-is-collapsed .sidebar-collapse:hover {
    background: #fff;
    color: #1f2937;
    border-color: #cbd5e1;
    box-shadow: 0 10px 28px rgba(20,30,50,.2);
  }
  .app-shell.sidebar-is-collapsed .sidebar-collapse i { transform: translateX(1px); }
  .app-shell.sidebar-is-collapsed .sidebar-nav { padding-left: 12px; padding-right: 12px; }
  .app-shell.sidebar-is-collapsed .sidebar-nav a {
    justify-content: center;
    gap: 0;
    padding-left: 0;
    padding-right: 0;
  }
  .app-shell.sidebar-is-collapsed .sidebar-nav a i { width: 38px; font-size: 1.08rem; }
  .app-shell.sidebar-is-collapsed .sidebar-section {
    height: 18px;
    margin-left: 0;
    margin-right: 0;
    overflow: hidden;
    opacity: .55;
  }
  .app-shell.sidebar-is-collapsed .sidebar-nav a:hover { transform: none; }
  .app-shell.sidebar-is-collapsed .sidebar-nav a.active::before { left: -1px; }
}

/* Mobile: keep the existing slide-out behavior; collapse button is not used */
@media (max-width: 992px) {
  .sidebar-collapse { display: none; }
  .sidebar-brand { justify-content: flex-start; }
}

/* Login centering hard-stop: keeps the authentication card centered even if a host/theme overrides layout rules. */
html.login-page, body.login-page {
  width: 100% !important;
  min-width: 100% !important;
  min-height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
}
body.login-page .login-wrap {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  display: grid !important;
  place-items: center !important;
  padding: 24px !important;
}
body.login-page .login-card {
  position: relative !important;
  left: auto !important;
  top: auto !important;
  right: auto !important;
  bottom: auto !important;
  margin: 0 auto !important;
  justify-self: center !important;
  align-self: center !important;
}

/* FINAL LOGIN CENTERING OVERRIDE */
body.login-page {
  width: 100vw !important;
  min-width: 100vw !important;
  min-height: 100vh !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow-x: hidden !important;
}
body.login-page .login-wrap {
  position: fixed !important;
  left: 0 !important;
  top: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  margin: 0 !important;
  padding: 24px !important;
  display: block !important;
  overflow-y: auto !important;
  z-index: 1 !important;
}
body.login-page .login-card {
  position: fixed !important;
  left: 50vw !important;
  top: 50vh !important;
  right: auto !important;
  bottom: auto !important;
  width: min(430px, calc(100vw - 48px)) !important;
  max-width: 430px !important;
  margin: 0 !important;
  transform: translate(-50%, -50%) !important;
  z-index: 2 !important;
}
@media (max-height: 700px) {
  body.login-page .login-card {
    top: 24px !important;
    transform: translateX(-50%) !important;
    margin-bottom: 24px !important;
  }
  body.login-page .login-wrap {
    overflow-y: auto !important;
  }
}
