/* OpenFang Layout — Grid + Sidebar + Responsive */

.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition-normal);
  z-index: 100;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

.sidebar.collapsed .sidebar-label,
.sidebar.collapsed .sidebar-header-text,
.sidebar.collapsed .nav-label { display: none; }

.sidebar.collapsed .nav-item { justify-content: center; padding: 12px 0; }

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo img {
  width: 28px;
  height: 28px;
  opacity: 0.8;
  transition: opacity 0.2s, transform 0.2s;
}

.sidebar-logo img:hover {
  opacity: 1;
  transform: scale(1.05);
}

.sidebar-header h1 {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 3px;
  font-family: var(--font-mono);
}

.sidebar-header .version {
  font-size: 9px;
  color: var(--text-muted);
  margin-top: 1px;
  letter-spacing: 0.5px;
}

.sidebar-status {
  font-size: 11px;
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-status.offline { color: var(--error); }

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}

.conn-badge {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-left: auto;
}
.conn-badge.ws { background: var(--success); color: #000; }
.conn-badge.http { background: var(--warning); color: #000; }

/* Navigation */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { width: 0; }

.nav-section {
  margin-bottom: 4px;
}

.nav-section-title {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 12px 12px 4px;
  font-weight: 600;
}

.sidebar.collapsed .nav-section-title { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  transition: all var(--transition-fast);
  text-decoration: none;
  border: 1px solid transparent;
  white-space: nowrap;
  font-weight: 500;
}

.nav-item:hover {
  background: var(--surface2);
  color: var(--text);
  transform: translateX(2px);
}

.nav-item.active {
  background: var(--accent);
  color: var(--bg-primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm), 0 2px 8px rgba(255, 92, 0, 0.2);
}

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

.nav-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Sidebar toggle button */
.sidebar-toggle {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

.sidebar-toggle:hover { color: var(--text); }

/* Main content area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
}

/* Page wrapper divs (rendered by x-if) must fill the column
   and be flex containers so .page-body can scroll. */
.main-content > div {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.page-header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--header-height);
}

.page-header h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.page-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
}

/* Mobile overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
}

/* Wide desktop — larger card grids */
@media (min-width: 1400px) {
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
}

/* Responsive — tablet breakpoint */
@media (max-width: 1024px) {
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
  .security-grid { grid-template-columns: 1fr; }
  .cost-charts-row { grid-template-columns: 1fr; }
  .overview-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
  .page-body { padding: 16px; }
}

/* Responsive — mobile breakpoint */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -300px;
    top: 0;
    bottom: 0;
    transition: left var(--transition-normal);
  }
  .sidebar.mobile-open {
    left: 0;
  }
  .sidebar.mobile-open + .sidebar-overlay {
    display: block;
  }
  .sidebar.collapsed {
    width: var(--sidebar-width);
    left: -300px;
  }
  .mobile-menu-btn { display: flex !important; }
}

@media (min-width: 769px) {
  .mobile-menu-btn { display: none !important; }
}

/* Mobile small screen */
@media (max-width: 480px) {
  .page-header { flex-direction: column; gap: 8px; align-items: flex-start; padding: 12px 16px; }
  .page-body { padding: 12px; }
  .stats-row { flex-wrap: wrap; }
  .stat-card { min-width: 80px; flex: 1 1 40%; }
  .stat-card-lg { min-width: 80px; flex: 1 1 40%; padding: 12px; }
  .stat-card-lg .stat-value { font-size: 22px; }
  .card-grid { grid-template-columns: 1fr; }
  .overview-grid { grid-template-columns: 1fr; }
  .input-area { padding: 8px 12px; }
  .main-content { padding: 0; }
  .table-wrap { font-size: 10px; }
  .modal { margin: 8px; max-height: calc(100vh - 16px); }
}

/* Touch-friendly tap targets */
@media (pointer: coarse) {
  .btn { min-height: 44px; min-width: 44px; }
  .nav-item { min-height: 44px; }
  .form-input, .form-select, .form-textarea { min-height: 44px; }
  .toggle { min-width: 44px; min-height: 28px; }
}

/* Focus mode — hide sidebar for distraction-free chat */
.app-layout.focus-mode .sidebar { display: none; }
.app-layout.focus-mode .sidebar-overlay { display: none; }
.app-layout.focus-mode .main-content { max-width: 100%; margin-left: 0; }
.app-layout.focus-mode .mobile-menu-btn { display: none !important; }
