/* ═══════════════════════════════════════════════════════════════
   Lux Nebulosa — Design System v2
   Modern SaaS dashboard theme
   ═══════════════════════════════════════════════════════════════ */

:root {
  --primary: #5B4CF0;
  --primary-light: #7B6FF2;
  --primary-dark: #4338CA;
  --primary-50: #EEF2FF;
  --primary-100: #E0E7FF;

  --bg-app: #F4F6FB;
  --bg-app-gradient: #F4F6FB;

  --surface: #ffffff;
  --surface-2: rgba(255, 255, 255, 0.92);
  --surface-border: #E5E7EB;

  --sidebar-bg-1: #2D1B69;
  --sidebar-bg-2: #1A0F3C;
  --sidebar-w: 72px;
  --sidebar-w-expanded: 240px;

  --header-h: 0px;

  --text: #1F2937;
  --text-muted: #6B7280;
  --text-light: #9CA3AF;

  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;

  --radius-xl: 20px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg-app);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ─── Layout Shell ─────────────────────────────────────────── */

body.has-shell {
  padding-top: 0;
  padding-left: var(--sidebar-w);
  transition: padding-left .2s cubic-bezier(.4,0,.2,1);
}
body.has-shell.sidebar-expanded {
  padding-left: var(--sidebar-w-expanded);
}

/* ─── Header (embedded in content area now) ──────────────── */

.app-header {
  display: none;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
  margin-bottom: 20px;
}

.page-header-left h1 {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.02em;
}
.page-header-left .page-breadcrumb {
  font-size: 12px;
  color: var(--text-light);
  font-weight: 500;
  margin-bottom: 2px;
}

.page-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.system-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #ECFDF5;
  border: 1px solid #D1FAE5;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  color: #065F46;
}

.system-status-pill--warn {
  background: #FFF7ED;
  border-color: #FED7AA;
  color: #C2410C;
}

.system-status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}

.system-status-pill--warn .dot {
  background: #F59E0B;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.header-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--primary-100);
  border: 2px solid var(--primary-50);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: box-shadow .15s;
}
.header-avatar:hover {
  box-shadow: 0 0 0 3px rgba(91, 76, 240, 0.2);
}
.header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.header-logout {
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--surface-border);
  background: white;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
}
.header-logout:hover {
  background: #FEF2F2;
  color: var(--danger);
  border-color: #FECACA;
}

/* ─── Sidebar ──────────────────────────────────────────────── */

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #3B2A80 0%, #1E1154 35%, #150D3A 100%);
  z-index: 10001;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0 10px;
  gap: 4px;
  overflow: hidden;
  transition: width .2s cubic-bezier(.4,0,.2,1);
}

.app-sidebar::before {
  content: "";
  position: absolute;
  top: -40px;
  right: -40px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(91, 76, 240, 0.15);
  pointer-events: none;
}
.app-sidebar::after {
  content: "";
  position: absolute;
  bottom: 60px;
  left: -30px;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgba(139, 92, 246, 0.1);
  pointer-events: none;
}

body.sidebar-expanded .app-sidebar {
  width: var(--sidebar-w-expanded);
  align-items: stretch;
}

/* Logo area */
.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  margin-bottom: 8px;
  text-decoration: none;
  color: white;
  position: relative;
  z-index: 1;
}
.sidebar-brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary) 0%, #7C3AED 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 900;
  color: white;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(91, 76, 240, 0.4);
}
.sidebar-brand-text {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.03em;
  opacity: 0;
  max-width: 0;
  overflow: hidden;
  transition: opacity .15s, max-width .2s;
  margin-left: 10px;
  white-space: nowrap;
}
body.sidebar-expanded .sidebar-brand-text {
  opacity: 1;
  max-width: 160px;
}

.sidebar-divider {
  width: 32px;
  height: 1px;
  background: rgba(255,255,255,0.12);
  margin: 4px auto 8px;
}
body.sidebar-expanded .sidebar-divider {
  width: calc(100% - 28px);
}

/* Toggle */
.sidebar-toggle {
  width: 40px;
  height: 40px;
  margin: 0 auto 4px;
  border-radius: 10px;
  border: 0;
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.7);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0;
  cursor: pointer;
  transition: background .15s;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.12); }
.sidebar-toggle .sidebar-icon { width: 20px; height: 20px; }
body.sidebar-expanded .sidebar-toggle {
  width: calc(var(--sidebar-w-expanded) - 24px);
  justify-content: flex-start;
  padding: 0 12px;
}

/* Nav links */
.sidebar-link {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  color: rgba(255,255,255,0.55);
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  gap: 10px;
  overflow: hidden;
  white-space: nowrap;
  transition: all .15s;
  z-index: 1;
}
.sidebar-link:hover {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.9);
}
.sidebar-link.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(91, 76, 240, 0.4);
}
.sidebar-link.active::before { display: none; }

body.sidebar-expanded .sidebar-link {
  width: calc(var(--sidebar-w-expanded) - 24px);
  justify-content: flex-start;
  padding: 0 12px;
  margin: 0 12px;
}

.sidebar-icon {
  width: 20px;
  height: 20px;
  display: block;
  flex-shrink: 0;
}

.sidebar-label {
  display: inline-block;
  opacity: 0;
  max-width: 0;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
  transition: opacity .15s, max-width .2s;
  overflow: hidden;
}
body.sidebar-expanded .sidebar-label {
  opacity: 1;
  max-width: 160px;
}

.sidebar-link-install {
  margin-top: 0;
  margin-bottom: 0;
}

/* Remove per-link colors - unified look */
.sidebar-link--home,
.sidebar-link--orders,
.sidebar-link--deliveries,
.sidebar-link--rota,
.sidebar-link--labels,
.sidebar-link--products,
.sidebar-link--sales,
.sidebar-link--paylinks,
.sidebar-link--chat,
.sidebar-link--admin,
.sidebar-link--download,
.sidebar-link--integrations { color: rgba(255,255,255,0.55) !important; }

.chat-unread-badge {
  background: #25d366;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 9px;
  padding: 0 5px;
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}
body:not(.sidebar-expanded) .chat-unread-badge {
  right: 2px;
  top: 4px;
  transform: none;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  font-size: 9px;
}

.sidebar-link:hover,
.sidebar-link.active {
  color: white !important;
}

/* ─── Content Area ─────────────────────────────────────────── */

main, .shell-main {
  max-width: 100%;
  min-width: 0;
  margin: 0 auto;
  padding: 0 24px 24px;
  transition: max-width .2s cubic-bezier(.4,0,.2,1);
  overflow-x: hidden;
}

/* ─── Cards ────────────────────────────────────────────────── */

.card, article[data-order-id] {
  background: white;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.page-surface, .rounded-3xl.bg-white\/60, .mt-4.bg-white\/60, .bg-white\/70.backdrop-blur.rounded-3xl {
  background: var(--surface-2) !important;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-xl) !important;
  box-shadow: var(--shadow-md) !important;
}
.page-surface { padding: 20px !important; }

.rounded-2xl.bg-white\/80.shadow {
  background: white !important;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-sm) !important;
}

/* ─── Buttons ──────────────────────────────────────────────── */

.btn, .btn-primary, .btn-secondary, button.h-11, button.h-12, a.btn-primary {
  height: 38px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.btn:hover, .btn-primary:hover, .btn-secondary:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active, .btn-primary:active, .btn-secondary:active { transform: translateY(0); }

.btn-primary, a.btn-primary { background: var(--primary) !important; color: #fff !important; }
.btn-primary:hover { background: var(--primary-dark) !important; }
.btn-secondary { background: var(--success) !important; color: #fff !important; }

/* ─── Forms ────────────────────────────────────────────────── */

input, .input {
  border-radius: var(--radius-sm) !important;
  border: 1px solid var(--surface-border) !important;
  background: white;
  color: var(--text);
  font-size: 13px;
}
select:not(.status-pill) {
  border-radius: var(--radius-sm) !important;
  border: 1px solid var(--surface-border) !important;
  background: white;
  color: var(--text);
  font-size: 13px;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(91, 76, 240, 0.12);
}

/* ─── Tiles ────────────────────────────────────────────────── */

.tile { color: #fff !important; border: 0 !important; min-height: 96px; }
.tile .text-sm, .tile .text-xs { color: rgba(255,255,255,.75) !important; }
.tile .text-lg, .tile .font-extrabold { color: #fff !important; }
.tile .h-12.w-12, .tile .h-10.w-10 { background: rgba(255,255,255,.2) !important; color: #fff !important; }
.tile--blue { background: linear-gradient(135deg, #3b7dff, #2f46df) !important; }
.tile--green { background: linear-gradient(135deg, #37d85f, #21b99a) !important; }
.tile--teal { background: linear-gradient(135deg, #40b6ff, #4b57df) !important; }
.tile--orange { background: linear-gradient(135deg, #ffbc19, #f25a9a) !important; }
.tile--purple { background: linear-gradient(135deg, #b164ff, #6541d9) !important; }

/* ─── Kanban ───────────────────────────────────────────────── */

.kanban-col > .font-bold { font-size: 15px; }
.kanban-col .kanban-head { border-radius: 12px; color: #fff; padding: 8px 10px; font-weight: 700; }
.kanban-head--new { background: #355bf2; }
.kanban-head--sep { background: #f4ac05; }
.kanban-head--deliv { background: #8a50f3; }

.order-sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-50);
  color: var(--primary);
  border: 1px solid var(--primary-100);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
}

/* ─── Login ────────────────────────────────────────────────── */

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #1E1154 0%, #3B2A80 50%, #5B4CF0 100%);
}
.login-shell {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 24px;
}
.login-card {
  background: linear-gradient(145deg, #5B4CF0 0%, #3B2A80 100%);
  color: #fff;
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 40px rgba(0,0,0,0.3);
  padding: 28px;
}
.login-form-wrap {
  background: rgba(255,255,255,.95);
  border: 1px solid rgba(255,255,255,.6);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-xl);
  padding: 22px;
}

@media (max-width: 980px) {
  .login-shell { grid-template-columns: 1fr; }
}

/* ─── Force background on ALL pages ────────────────────────── */

body.has-shell,
body.rota-page,
body.min-h-screen {
  background: var(--bg-app) !important;
  background-image: none !important;
}

/* ─── Notebook / Laptop (≤1440px) ─────────────────────────── */

@media (max-width: 1440px) {
  main, .shell-main {
    padding: 0 16px 16px;
  }
  .page-header {
    padding: 14px 16px 0;
    margin-bottom: 14px;
  }
  .page-header-left h1 { font-size: 20px; }
}

@media (max-width: 1280px) {
  :root {
    --sidebar-w: 64px;
    --sidebar-w-expanded: 220px;
  }
  main, .shell-main {
    padding: 0 12px 12px;
  }
  .page-header {
    padding: 10px 12px 0;
    margin-bottom: 10px;
  }
  .page-header-left h1 { font-size: 18px; }
  .system-status-pill { font-size: 11px; padding: 4px 10px; }
  .header-user-name { font-size: 12px; }
  .header-avatar { width: 30px; height: 30px; }
  .page-surface { padding: 14px !important; }
}

/* ─── Tablet landscape ────────────────────────────────────── */

@media (max-width: 1024px) {
  :root {
    --sidebar-w: 56px;
  }
  .sidebar-brand-icon { width: 30px; height: 30px; font-size: 13px; }
  .sidebar-link { width: 36px; height: 36px; }
  .sidebar-toggle { width: 36px; height: 36px; }
  .sidebar-icon { width: 18px; height: 18px; }
}

/* ─── Mobile ───────────────────────────────────────────────── */

@media (max-width: 820px) {
  body.has-shell {
    padding-left: 0;
    padding-bottom: 72px;
  }
  .app-sidebar {
    width: 100% !important;
    height: 64px;
    top: auto;
    right: 0;
    flex-direction: row;
    justify-content: space-around;
    padding: 8px 10px;
    border-right: 0;
    border-top: 1px solid rgba(255,255,255,.12);
  }
  .app-sidebar::before, .app-sidebar::after { display: none; }
  .sidebar-toggle { display: none; }
  .sidebar-label { display: none !important; }
  .sidebar-brand { display: none; }
  .sidebar-divider { display: none; }
  .sidebar-link.active::before { display: none; }
  .sidebar-link-install { margin-top: 0; margin-bottom: 0; }
  .page-header { padding: 16px 16px 0; }
  main, .shell-main { padding: 0 16px 16px; }
}

/* ─── Legacy harmonization ─────────────────────────────────── */

.relative.w-full.isolate > .pointer-events-none.absolute,
.pointer-events-none.absolute.inset-x-0.top-0,
.pointer-events-none.absolute.inset-x-0.top-0.-mx-4 { display: none !important; }

.relative.max-w-\[1200px\].mx-auto.px-4.py-4,
.relative.max-w-\[1000px\].mx-auto.px-4.py-4,
.max-w-\[980px\].mx-auto.px-4.pt-4.pb-8,
.relative.max-w-\[760px\].mx-auto.px-4.py-4 {
  max-width: 1320px !important;
  margin: 0 auto !important;
  padding: 18px !important;
}

.h-11.px-4.rounded-2xl.bg-white\/70.backdrop-blur.shadow,
.h-11.px-4.rounded-2xl.bg-white\/80.backdrop-blur.shadow,
.h-11.px-4.rounded-xl.bg-white\/70.backdrop-blur.shadow {
  background: var(--primary) !important;
  color: #fff !important;
  border: 0 !important;
}

/* ─── Rota embed ───────────────────────────────────────────── */

body.route-embed-page { overflow: hidden; }
body.route-embed-page .route-shell-main {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: 10px;
  padding-bottom: 8px;
}
body.route-embed-page .route-toolbar { min-height: 46px; }
body.route-embed-page .route-toolbar-title { font-size: 1.6rem; line-height: 1.05; }
body.route-embed-page .route-toolbar-sub { margin-top: 2px; font-size: 12px; line-height: 1.1; }
body.route-embed-page .route-frame { flex: 1 1 auto; min-height: 0; display: flex; padding: 8px !important; }
body.route-embed-page .route-iframe { flex: 1 1 auto; min-height: 0; display: block; }

@media (max-width: 820px) {
  body.route-embed-page .route-shell-main {
    height: calc(100vh - 72px);
    padding-top: 8px;
    padding-bottom: 8px;
  }
  body.route-embed-page .route-toolbar-title { font-size: 1.35rem; }
  body.route-embed-page .route-toolbar-sub { display: none; }
}

/* ─── Typography helpers ───────────────────────────────────── */

.h1 { font-size: clamp(1.4rem, 2vw, 1.8rem); font-weight: 800; letter-spacing: -0.02em; }
.h2 { font-size: clamp(1.1rem, 1.3vw, 1.3rem); font-weight: 700; }
.muted { color: var(--text-muted); font-size: .875rem; }

.app-header-inner { display: none; }
