/* ============================================================
   YutiFlow WMS — App Shell Styles
   Sidebar, Header, Layout, Charts, Navigation
   ============================================================ */

@import './global.css';

/* ── App Shell ── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-base);
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  left: 0; top: 0;
  z-index: var(--z-sidebar);
  transition: width var(--transition-slow);
  overflow: hidden;
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .sidebar-label { display: none; }
.sidebar.collapsed .sidebar-brand-text { display: none; }
.sidebar.collapsed .sidebar-section-title { display: none; }
.sidebar.collapsed .smart-layer { display: none; }
.sidebar.collapsed .nav-badge { display: none; }

/* Sidebar Brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  text-decoration: none;
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.sidebar-brand-text { flex: 1; min-width: 0; }
.sidebar-brand-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.sidebar-brand-sub {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 1px;
}

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sidebar-section-title {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-disabled);
  padding: 14px 10px 5px;
  margin-top: 2px;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  text-decoration: none;
  user-select: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 400;
  white-space: nowrap;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--primary-muted);
  color: var(--primary);
  font-weight: 500;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 5px;
  bottom: 5px;
  width: 2px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

.nav-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active .nav-icon,
.nav-item:hover .nav-icon {
  opacity: 1;
}

.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: var(--border-radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
}

.nav-badge-warning { background: var(--warning); color: #000; }
.nav-badge-success { background: var(--success); }

/* Operations Intelligence Panel */
.smart-layer {
  margin: 8px;
  padding: 12px;
  background: rgba(37,99,235,0.06);
  border: 1px solid rgba(37,99,235,0.2);
  border-radius: var(--border-radius-lg);
  flex-shrink: 0;
}

.smart-layer-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  margin-bottom: 5px;
}

.smart-layer-desc {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 10px;
}

.smart-layer .btn {
  width: 100%;
  font-size: 11px;
  padding: 7px;
  background: rgba(37,99,235,0.12);
  border: 1px solid rgba(37,99,235,0.2);
  color: var(--primary);
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: background var(--transition-fast);
  font-weight: 600;
}

.smart-layer .btn:hover { background: rgba(37,99,235,0.2); }

/* ── Main Content Area ── */
.main-area {
  flex: 1;
  margin-left: var(--sidebar-width);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: margin-left var(--transition-slow);
}

.main-area.sidebar-collapsed { margin-left: var(--sidebar-collapsed); }

/* ── Header ── */
.header {
  height: var(--header-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-5);
  flex-shrink: 0;
  z-index: var(--z-header);
}

.header-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.header-search { flex: 1; max-width: 300px; margin: 0 auto; }

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* Notification Bell */
.notif-btn {
  position: relative;
  width: 34px; height: 34px;
  border-radius: var(--border-radius);
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.notif-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.notif-badge {
  position: absolute;
  top: 7px; right: 7px;
  width: 7px; height: 7px;
  background: var(--danger);
  border-radius: 50%;
  border: 1.5px solid var(--bg-surface);
  animation: pulse 2s ease-in-out infinite;
}

/* User Avatar */
.user-avatar {
  width: 32px; height: 32px;
  border-radius: var(--border-radius);
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: opacity var(--transition-fast);
  flex-shrink: 0;
}

.user-avatar:hover { opacity: 0.85; }

/* User Menu */
.user-menu-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.user-menu-name { font-size: var(--text-sm); font-weight: 600; color: var(--text-primary); }
.user-menu-email { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Page Content ── */
.page-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5) var(--space-6);
  display: none;
}

.page-content.active { display: block; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  gap: var(--space-4);
  flex-wrap: wrap;
}

.page-header-left .page-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: 2px;
}

.page-header-left .page-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.page-header-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ── KPI Grid ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: var(--space-5);
}

/* ── Chart Grid ── */
.chart-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.chart-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.chart-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-inset);
}

.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  gap: var(--space-3);
}

.chart-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.chart-card-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 400;
}

/* ── CRITICAL: Chart Container Fix ── */
/* Every chart canvas must be wrapped in .chart-wrap for proper height constraint */
.chart-wrap {
  position: relative;
  width: 100%;
  /* Heights set per use case */
}

.chart-wrap canvas {
  display: block;
}

.chart-h-200 { height: 200px; }
.chart-h-180 { height: 180px; }
.chart-h-160 { height: 160px; }
.chart-h-220 { height: 220px; }
.chart-h-260 { height: 260px; }

/* ── Notification Panel ── */
.notif-panel {
  position: fixed;
  top: 0; right: -400px;
  width: 360px; height: 100vh;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  transition: right var(--transition-slow);
  box-shadow: var(--shadow-xl);
}

.notif-panel.open { right: 0; }

.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.notif-panel-title { font-size: 14px; font-weight: 600; }

.notif-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-1);
}

.notif-item {
  display: flex;
  gap: var(--space-3);
  padding: 10px;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: background var(--transition-fast);
  border-bottom: 1px solid var(--border);
}

.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg-hover); }
.notif-item.unread { background: rgba(37,99,235,0.04); }

.notif-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--primary);
  margin: auto 0;
  flex-shrink: 0;
}

.notif-icon {
  width: 32px; height: 32px;
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.notif-content { flex: 1; min-width: 0; }
.notif-title { font-size: 13px; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.notif-desc { font-size: 11px; color: var(--text-muted); line-height: 1.4; }
.notif-time { font-size: 10px; color: var(--text-disabled); margin-top: 3px; }



/* ── Filter Bar ── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-lg);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.filter-bar .filter-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Warehouse Flow Container ── */
.warehouse-flow-container {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-lg);
  padding: var(--space-4);
  position: relative;
  overflow: hidden;
}

/* ── Activity Feed ── */
.activity-feed {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: 320px;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  animation: fadeIn 0.25s ease;
}

.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}

.activity-content { flex: 1; min-width: 0; }
.activity-text { font-size: 12px; color: var(--text-secondary); line-height: 1.4; }
.activity-text strong { color: var(--text-primary); font-weight: 600; }
.activity-time { font-size: 10px; color: var(--text-disabled); margin-top: 2px; }

/* ── Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-16) var(--space-8);
  text-align: center;
  color: var(--text-muted);
}

.empty-icon { margin-bottom: var(--space-4); opacity: 0.3; }
.empty-title { font-size: var(--text-md); font-weight: 600; color: var(--text-secondary); margin-bottom: var(--space-2); }
.empty-desc { font-size: var(--text-sm); max-width: 300px; }

/* ── Tab Navigation ── */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-hover);
  border-radius: var(--border-radius);
  padding: 2px;
  width: fit-content;
}

.tab {
  padding: 6px 14px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
  white-space: nowrap;
}

.tab:hover { color: var(--text-primary); }
.tab.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ── Breadcrumb ── */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}

.breadcrumb-sep { color: var(--border-strong); }
.breadcrumb-current { color: var(--text-primary); font-weight: 600; }
