/* Unified Design System */
:root {
  /* Colors - Light Mode (default) */
  --primary: #ffffff;
  --primary-light: #b3d9ff;
  --accent: #FF9500;
  --bg: #ffffff;
  --card: #f5f5f5;
  --card-elevated: #ffffff;
  --panel: #f5f5f5;
  --panel2: #f0f0f0;
  --muted: #666666;
  --text: #333333;
  --accent-hover: rgba(255, 149, 0, 0.15);
  --border: #ddd;
  --border-soft: rgba(0, 0, 0, 0.1);
  --line: #ddd;
  --chip: #f0f0f0;
  
  /* Status colors */
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  
  /* Sizing */
  --radius: 14px;
  --radius-sm: 12px;
  --sidebar-width: 280px;
  --sidebar-width-collapsed: 80px;
  
  /* Typography */
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

/* Dark Mode */
html.dark-mode {
  --primary: #ffffff;
  --primary-light: #b3d9ff;
  --accent: #FF9500;
  --bg: #1a1a1a;
  --card: #2a2a2a;
  --card-elevated: #2a2a2a;
  --panel: #2a2a2a;
  --panel2: #333333;
  --muted: #a0a0a0;
  --text: #e0e0e0;
  --accent-hover: rgba(255, 149, 0, 0.15);
  --border: #444444;
  --border-soft: rgba(255, 255, 255, 0.1);
  --line: #444444;
  --chip: #333333;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

html.dark-mode body {
  background: #1a1a1a;
  color: var(--text);
}

/* --- Layout with Sidebar --- */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.3s ease;
}

.app-layout.sidebar-collapsed {
  grid-template-columns: var(--sidebar-width-collapsed) 1fr;
}

.app-sidebar {
  background: var(--card);
  border-right: 1px solid var(--border-soft);
  padding: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
}

html.dark-mode .app-sidebar {
  background: #1a1a1a;
  border-right-color: #444444;
}

.app-sidebar::-webkit-scrollbar {
  width: 6px;
}

.app-sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.app-sidebar::-webkit-scrollbar-thumb {
  background: rgba(79, 140, 255, 0.3);
  border-radius: 3px;
}

.app-main {
  padding: 18px;
  overflow-y: auto;
  overflow-x: hidden;
}

/* --- Sidebar Brand --- */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 14px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
}

.sidebar-brand-icon {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  background: transparent;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: width 0.3s ease, height 0.3s ease;
}

.app-layout.sidebar-collapsed .sidebar-brand-icon {
  width: 44px;
  height: 44px;
}

.sidebar-brand-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.sidebar-brand-icon:empty::before {
  content: 'Q';
  font-weight: 800;
  color: var(--text);
  font-size: 24px;
}

.app-layout.sidebar-collapsed .sidebar-brand-icon:empty::before {
  font-size: 20px;
}

.sidebar-brand-text {
  min-width: 0;
  opacity: 1;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  visibility: visible;
}

.app-layout.sidebar-collapsed .sidebar-brand-text {
  opacity: 0;
  width: 0;
  margin: 0;
  visibility: hidden;
}

.sidebar-brand h1 {
  font-size: 14px;
  margin: 0;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-brand .sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.sidebar-nav a:hover {
  border-color: var(--accent);
  background: var(--accent-hover);
}

.sidebar-nav a.active {
  border-color: var(--accent);
  background: var(--accent-hover);
}

html.dark-mode .sidebar-nav a {
  background: transparent;
  border-color: #444444;
}

html.dark-mode .sidebar-nav a:hover,
html.dark-mode .sidebar-nav a.active {
  background: rgba(255, 149, 0, 0.15);
  border-color: #FF9500;
}

.sidebar-nav a svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-nav a span {
  font-size: 13px;
  opacity: 1;
  transition: opacity 0.3s ease;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-item-with-subnav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-subnav {
  display: none;
  flex-direction: column;
  gap: 6px;
  padding-left: 28px;
}

.sidebar-item-with-subnav.active .sidebar-subnav {
  display: flex;
}

.sidebar-subnav a {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
  transition: color 0.15s ease;
}

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

.app-layout.sidebar-collapsed .sidebar-nav a span {
  opacity: 0;
  width: 0;
  margin: 0;
}

.app-layout.sidebar-collapsed .sidebar-subnav {
  display: none !important;
}

.app-layout.sidebar-collapsed .sidebar-brand-text {
  opacity: 0;
  width: 0;
  visibility: hidden;
}

.app-layout.sidebar-collapsed .btn-dark-toggle {
  font-size: 0;
  padding: 8px;
  overflow: hidden;
}

.app-layout.sidebar-collapsed .btn-dark-toggle::before {
  content: '🌙';
  font-size: 14px;
}

html.dark-mode .app-layout.sidebar-collapsed .btn-dark-toggle::before {
  content: '☀️';
}

/* --- Sidebar Footer --- */
.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  margin-top: auto;
}

.sidebar-footer button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(255, 90, 90, 0.35);
  border-radius: var(--radius-sm);
  background: rgba(255, 90, 90, 0.08);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 13px;
}

.sidebar-footer button svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-footer button:hover {
  background: rgba(255, 90, 90, 0.15);
  border-color: rgba(255, 90, 90, 0.5);
}

html.dark-mode .sidebar-footer button {
  border-color: rgba(255, 90, 90, 0.35);
  background: rgba(255, 90, 90, 0.08);
}

html.dark-mode .sidebar-footer button:hover {
  background: rgba(255, 90, 90, 0.15);
}

.sidebar-footer button span {
  opacity: 1;
  transition: opacity 0.3s ease;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-layout.sidebar-collapsed .sidebar-footer button span {
  opacity: 0;
  width: 0;
  margin: 0;
}

/* Toggle button */
.sidebar-toggle {
  position: absolute;
  top: 18px;
  right: -16px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid rgba(79, 140, 255, 0.35);
  color: var(--accent);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sidebar-toggle:hover {
  background: var(--accent-hover);
}

/* --- Topbar (for branded pages) --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: -18px -18px 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--card);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.topbarLeft {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.topbarTitle {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.5px;
  color: var(--text);
}

.topbarRight {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* --- Common Components --- */
.card {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  padding: 18px;
}

html.dark-mode .card {
  background: #2a2a2a;
  border-color: #444444;
}

.card-header {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin: -18px -18px 10px -18px;
  padding: 14px 18px 10px 18px;
}

.card-header h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.2px;
}

.card-header p {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.card-body {
  padding: 0;
}

/* Buttons */
button, .btn {
  appearance: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  border: 1px solid rgba(79, 140, 255, 0.55);
  background: rgba(79, 140, 255, 0.18);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: all 0.15s ease;
}

button:hover, .btn:hover {
  background: var(--accent-hover);
  border-color: rgba(79, 140, 255, 0.75);
}

button:active, .btn:active {
  transform: translateY(1px);
}

.btn.secondary {
  border-color: rgba(34, 48, 73, 0.95);
  background: rgba(34, 48, 73, 0.25);
  color: var(--muted);
}

.btn.secondary:hover {
  background: rgba(34, 48, 73, 0.35);
  color: var(--text);
}

/* Forms */
label {
  display: block;
  margin: 10px 0 6px;
  color: var(--muted);
  font-size: 12px;
}

input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(11, 15, 20, 0.55);
  color: var(--text);
  outline: none;
  font-size: 14px;
  font-family: inherit;
  transition: all 0.15s ease;
}

input::placeholder, textarea::placeholder {
  color: rgba(154, 164, 178, 0.65);
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(79, 140, 255, 0.9);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.18);
}

/* Typography */
h1 {
  margin: 0 0 6px 0;
  font-size: 18px;
}

h2 {
  margin: 0 0 10px 0;
  font-size: 15px;
}

h3 {
  margin: 0 0 8px 0;
  font-size: 13px;
}

p {
  margin: 0 0 14px 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.35;
}

/* Utilities */
.top {
  width: min(1100px, 100%);
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.wrap {
  width: min(1100px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}

.crumb {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  border: 1px solid rgba(34, 48, 73, 0.9);
  background: rgba(34, 48, 73, 0.22);
  padding: 6px 10px;
  border-radius: 999px;
}

.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: var(--sidebar-width-collapsed) 1fr;
  }
  
  .sidebar-brand-text,
  .sidebar-nav a span,
  .sidebar-footer button span {
    opacity: 0 !important;
    width: 0;
    margin: 0;
  }
}

/* Dark Mode Toggle Button */
.btn-dark-toggle {
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 12px;
  transition: all 0.2s ease;
}

.btn-dark-toggle:hover {
  background: rgba(0, 0, 0, 0.05);
}

html.dark-mode .btn-dark-toggle {
  border-color: #444444;
  background: #2a2a2a;
  color: var(--text);
}

html.dark-mode .btn-dark-toggle:hover {
  background: #333333;
}
