:root {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  background: #f5f7fa;
  color: #1f2937;
}

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.shell-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  padding: 12px 20px;
  min-height: var(--shell-header-height, 56px);
  flex-shrink: 0;
}

.shell-header-left {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.shell-header h1 {
  margin: 0;
  font-size: 26px;
}

.shell-header p {
  margin: 6px 0 0;
  opacity: 0.9;
}

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

.sidebar-toggle {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.55);
}

.sidebar-toggle:active {
  transform: translateY(1px);
}

.sidebar-toggle:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.sidebar-toggle svg {
  width: 18px;
  height: 18px;
}

.admin-entry {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.admin-link {
  color: #fff;
  text-decoration: none;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.12);
}

.admin-link:hover {
  background: rgba(255, 255, 255, 0.2);
}

.admin-name {
  font-size: 13px;
  font-weight: 600;
}

.shell-main {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

.sidebar {
  background: #fff;
  width: var(--portal-sidebar-width, 240px);
  min-width: var(--portal-sidebar-width, 240px);
  border-right: 1px solid #e5e7eb;
  padding: 10px;
  overflow-y: auto;
  overflow-x: hidden;
  white-space: nowrap;
  flex-shrink: 0;
  transition:
    width 0.3s ease,
    min-width 0.3s ease,
    padding 0.3s ease,
    transform 0.3s ease,
    box-shadow 0.3s ease;
}

.sidebar--collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  border-right: none;
  overflow: hidden;
}

.sidebar--collapsed * {
  visibility: hidden;
}

.sidebar--mobile-open,
.sidebar--mobile-closed {
  position: fixed;
  top: var(--shell-header-height, 56px);
  left: 0;
  bottom: 0;
  width: min(280px, calc(100vw - 40px));
  min-width: min(280px, calc(100vw - 40px));
  z-index: 40;
  box-shadow: 8px 0 24px rgba(15, 23, 42, 0.22);
}

.sidebar--mobile-open {
  transform: translateX(0);
}

.sidebar--mobile-closed {
  transform: translateX(-100%);
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(15, 23, 42, 0.4);
}

.overlay-fade-enter-active,
.overlay-fade-leave-active {
  transition: opacity 0.3s ease;
}

.overlay-fade-enter-from,
.overlay-fade-leave-to {
  opacity: 0;
}

.drawer + .drawer {
  margin-top: 10px;
  border-top: 1px solid #e5e7eb;
  padding-top: 10px;
}

.drawer-title {
  margin: 0 0 6px;
  font-size: 12px;
  color: #64748b;
  text-transform: uppercase;
}

.drawer-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
  color: #334155;
  font-size: 14px;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.drawer-link:hover {
  background: #f1f5f9;
}

.drawer-link.active {
  background: #eef2ff;
  color: #4338ca;
  font-weight: 600;
}

.shell-content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  background: #f5f7fa;
  padding: 16px;
}

.shell-content .resource-page,
.shell-content .dashboard,
.shell-content .qc-gate-page,
.shell-content .job-query-page,
.shell-content .excel-query-page,
.shell-content .query-tool-page,
.shell-content .tmtt-page,
.shell-content .tables-page {
  max-width: none;
  min-height: auto;
}

.shell-content .tables-page .container {
  max-width: none;
}

.shell-content .resource-page {
  padding: 0;
}

.breadcrumb {
  margin-bottom: 12px;
  color: #64748b;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #eef2ff;
  color: #4338ca;
  border: 1px solid #c7d2fe;
  border-radius: 999px;
  padding: 2px 8px;
}

.notice-banner {
  margin-bottom: 10px;
  border: 1px solid #fde68a;
  background: #fffbeb;
  color: #92400e;
  border-radius: 8px;
  font-size: 13px;
  padding: 8px 10px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 24px;
}

.panel p {
  margin: 0 0 8px;
  color: #475569;
}

.panel .muted {
  color: #64748b;
  font-size: 12px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.btn-primary {
  border: none;
  border-radius: 8px;
  background: #4f46e5;
  color: #fff;
  padding: 8px 12px;
  cursor: pointer;
}

.btn-link {
  color: #4f46e5;
}

.health-wrap {
  position: relative;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
}

.dot.healthy {
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
}

.dot.degraded {
  background: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.6);
}

.dot.unhealthy {
  background: #ef4444;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.6);
}

.dot.loading {
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.health-trigger {
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.health-trigger:hover {
  background: rgba(255, 255, 255, 0.2);
}

.label {
  font-size: 13px;
  font-weight: 600;
}

.meta {
  font-size: 12px;
  opacity: 0.95;
}

.meta-toggle {
  font-size: 12px;
  opacity: 0.9;
  border-left: 1px solid rgba(255, 255, 255, 0.35);
  padding-left: 8px;
}

.health-popup {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 360px;
  max-width: calc(100vw - 32px);
  color: #1f2937;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.24);
  border: 1px solid #e2e8f0;
  padding: 14px;
  z-index: 50;
}

.health-popup h4 {
  margin: 0 0 10px;
  font-size: 14px;
  color: #4338ca;
}

.health-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  font-size: 13px;
}

.health-item + .health-item {
  border-top: 1px solid #f1f5f9;
}

.health-item-label {
  color: #64748b;
}

.health-item-value {
  font-weight: 600;
  text-align: right;
}

.health-section {
  margin-top: 10px;
  border-top: 1px solid #e2e8f0;
  padding-top: 8px;
}

.health-section h5 {
  margin: 0 0 6px;
  font-size: 12px;
  color: #334155;
}

.health-section ul {
  margin: 0;
  padding-left: 16px;
  color: #475569;
  font-size: 12px;
}

.health-section-error h5 {
  color: #b91c1c;
}

.health-section-error ul {
  color: #b91c1c;
}

.muted {
  color: #64748b;
  font-size: 13px;
}

.error {
  color: #dc2626;
  font-size: 13px;
}

.route-fade-enter-active,
.route-fade-leave-active {
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.route-fade-enter-from,
.route-fade-leave-to {
  opacity: 0;
  transform: translateY(6px);
}

@media (prefers-reduced-motion: reduce) {
  .drawer-link,
  .route-fade-enter-active,
  .route-fade-leave-active,
  .sidebar,
  .sidebar--mobile-open,
  .sidebar--mobile-closed,
  .sidebar-overlay,
  .overlay-fade-enter-active,
  .overlay-fade-leave-active,
  .sidebar-toggle {
    transition: none !important;
  }

  .dot.loading {
    animation: none !important;
  }
}

@media (max-width: 900px) {
  .shell-header {
    padding: 12px 16px;
  }

  .shell-header-right {
    margin-left: auto;
  }

  .health-trigger {
    width: 100%;
    justify-content: space-between;
  }

  .shell-content {
    padding: 12px;
  }
}
