/* Extracted from diagrams.html */

/* =========================================================================
       BASE RESET & SHELL
       ========================================================================= */

    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
    html, body { height: 100%; }

    body {
      font-family: var(--font-body);
      font-size: var(--text-body);
      color: var(--color-text-primary);
      background-color: var(--color-bg-base);
      overflow: hidden;
    }

    [data-theme="modern"] body {
      background-image: radial-gradient(circle, var(--dot-grid-color) 1px, transparent 1px);
      background-size: var(--dot-grid-size) var(--dot-grid-size);
    }

    /* =========================================================================
       APP LAYOUT
       ========================================================================= */

    .app-shell { display: flex; height: 100vh; padding-top: 36px; }

    /* =========================================================================
       SIDEBAR (shared pattern)
       ========================================================================= */

    .sidebar {
      width: 260px; flex-shrink: 0; display: flex; flex-direction: column;
      background: var(--color-bg-elevated); border-right: 1px solid var(--color-border);
      overflow-y: auto; transition: var(--transition-normal);
    }
    .sidebar__brand {
      display: flex; align-items: center; gap: var(--space-3);
      padding: var(--space-5) var(--space-5) var(--space-4);
      border-bottom: 1px solid var(--color-border); flex-shrink: 0;
    }
    .brand-logo {
      width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
      background: var(--color-primary); color: var(--color-text-inverse);
      font-family: var(--font-heading); font-weight: var(--heading-weight-primary);
      font-size: 1.375rem; letter-spacing: var(--tracking-tight); flex-shrink: 0;
    }
    [data-theme="industrial"] .brand-logo { clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%); border-radius: 0; }
    [data-theme="modern"] .brand-logo { border-radius: var(--radius-md); }
    .brand-name { display: flex; flex-direction: column; line-height: 1; }
    .brand-name__primary { font-family: var(--font-heading); font-weight: var(--heading-weight-primary); font-size: 1.125rem; letter-spacing: var(--tracking-wide); color: var(--color-text-primary); text-transform: uppercase; }
    .brand-name__sub { font-family: var(--font-body); font-size: var(--text-caption); color: var(--color-text-muted); letter-spacing: var(--tracking-wider); text-transform: uppercase; margin-top: 2px; }

    .sidebar__nav { flex: 1; padding: var(--space-3) 0; }
    .nav-section-label { padding: var(--space-3) var(--space-5) var(--space-1); font-size: var(--text-caption); font-family: var(--font-body); font-weight: var(--font-weight-semibold); color: var(--color-text-muted); letter-spacing: var(--tracking-widest); text-transform: uppercase; }
    .nav-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-5); color: var(--color-text-secondary); font-family: var(--font-body); font-size: var(--text-body-sm); font-weight: var(--font-weight-regular); text-decoration: none; cursor: pointer; border: none; background: none; width: 100%; text-align: left; transition: var(--transition-fast); border-left: 3px solid transparent; }
    .nav-item:hover { background: var(--color-primary-muted); color: var(--color-text-primary); border-left-color: var(--color-primary); }
    .nav-item.is-active { background: var(--color-primary-muted); color: var(--color-primary); font-weight: var(--font-weight-semibold); border-left-color: var(--color-primary); }
    [data-theme="industrial"] .nav-item.is-active { background: rgba(245, 166, 35, 0.12); }
    .nav-item__icon { width: 18px; height: 18px; opacity: 0.75; flex-shrink: 0; }
    .nav-item.is-active .nav-item__icon, .nav-item:hover .nav-item__icon { opacity: 1; }

    .sidebar__profile { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--color-border); display: flex; align-items: center; gap: var(--space-3); flex-shrink: 0; }
    .profile-avatar { width: 36px; height: 36px; border-radius: var(--radius-full); background: var(--color-primary-muted); color: var(--color-primary); display: flex; align-items: center; justify-content: center; font-family: var(--font-heading); font-weight: var(--font-weight-bold); font-size: var(--text-body-sm); flex-shrink: 0; }
    .profile-info { overflow: hidden; }
    .profile-info__name { font-weight: var(--font-weight-semibold); font-size: var(--text-body-sm); color: var(--color-text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .profile-info__role { font-size: var(--text-caption); color: var(--color-text-muted); }

    /* =========================================================================
       MAIN CONTENT
       ========================================================================= */

    .main-content {
      flex: 1; display: flex; flex-direction: column; overflow: hidden;
      min-width: 0;
      margin-left: 260px;
    }

    .page-header {
      display: flex; align-items: center; gap: var(--space-4);
      padding: var(--space-4) var(--space-5);
      border-bottom: 1px solid var(--color-border);
      background: var(--color-bg-elevated);
      flex-shrink: 0;
    }

    .page-header__title {
      font-family: var(--font-heading); font-weight: var(--heading-weight-primary);
      font-size: 1.25rem; color: var(--color-text-primary);
    }

    .page-header__filter {
      margin-left: auto;
      padding: var(--space-2) var(--space-3);
      border: 1px solid var(--color-border);
      border-radius: var(--radius-md);
      background: var(--color-bg-base);
      color: var(--color-text-primary);
      font-family: var(--font-body);
      font-size: var(--text-body-sm);
      min-width: 220px;
      outline: none;
      transition: var(--transition-fast);
    }
    .page-header__filter:focus {
      border-color: var(--color-primary);
      box-shadow: 0 0 0 2px var(--color-primary-muted);
    }

    .page-body {
      flex: 1; overflow-y: auto; padding: var(--space-5);
    }

    /* =========================================================================
       LOADING & EMPTY
       ========================================================================= */

    .loading {
      display: none; align-items: center; justify-content: center;
      padding: var(--space-8); flex: 1;
    }
    .spinner {
      width: 40px; height: 40px; border: 3px solid var(--color-border);
      border-top-color: var(--color-primary); border-radius: 50%;
      animation: spin 0.7s linear infinite;
    }
    @keyframes spin { to { transform: rotate(360deg); } }

    .empty-state {
      display: none; flex-direction: column; align-items: center;
      justify-content: center; gap: var(--space-3); padding: var(--space-8);
      color: var(--color-text-muted); text-align: center;
    }
    .empty-state__title { font-weight: var(--font-weight-semibold); font-size: 1.1rem; }
    .empty-state__subtitle { font-size: var(--text-body-sm); }

    /* =========================================================================
       DIAGRAM LIST VIEW
       ========================================================================= */

    .diagram-category { margin-bottom: var(--space-6); }

    .category-title {
      font-family: var(--font-heading);
      font-weight: var(--heading-weight-primary);
      font-size: 1rem;
      color: var(--color-text-primary);
      text-transform: uppercase;
      letter-spacing: var(--tracking-wide);
      padding-bottom: var(--space-2);
      border-bottom: 2px solid var(--color-primary);
      margin-bottom: var(--space-4);
    }

    .diagram-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
      gap: var(--space-4);
    }

    .diagram-card {
      background: var(--color-bg-elevated);
      border: 1px solid var(--color-border);
      border-radius: var(--radius-lg);
      overflow: hidden;
      cursor: pointer;
      transition: var(--transition-fast);
    }
    .diagram-card:hover {
      border-color: var(--color-primary);
      box-shadow: var(--shadow-md);
      transform: translateY(-2px);
    }
    [data-theme="industrial"] .diagram-card {
      border-radius: var(--radius-sm);
    }

    .diagram-card__preview {
      width: 100%;
      height: 180px;
      background: #f8f8f8;
      display: flex; align-items: center; justify-content: center;
      overflow: hidden;
      border-bottom: 1px solid var(--color-border);
    }
    [data-theme="modern"] .diagram-card__preview {
      background: var(--color-bg-base);
    }
    .diagram-card__preview img {
      width: 100%; height: 100%;
      object-fit: contain;
      padding: var(--space-3);
    }

    .diagram-card__info {
      padding: var(--space-3) var(--space-4);
    }
    .diagram-card__name {
      font-weight: var(--font-weight-semibold);
      font-size: var(--text-body-sm);
      color: var(--color-text-primary);
      margin-bottom: 2px;
    }
    .diagram-card__group {
      font-size: var(--text-caption);
      color: var(--color-text-muted);
    }

    /* =========================================================================
       DIAGRAM VIEWER
       ========================================================================= */

    .diagram-viewer {
      display: none; flex: 1; flex-direction: row; overflow: hidden;
    }

    .viewer-main {
      flex: 1; display: flex; flex-direction: column; overflow: hidden;
      min-width: 0;
    }

    .viewer-toolbar {
      display: flex; align-items: center; gap: var(--space-3);
      padding: var(--space-3) var(--space-4);
      border-bottom: 1px solid var(--color-border);
      background: var(--color-bg-elevated);
      flex-shrink: 0;
    }

    .viewer-toolbar .btn-icon {
      width: 36px; height: 36px;
      display: flex; align-items: center; justify-content: center;
      background: var(--color-bg-base); border: 1px solid var(--color-border);
      border-radius: var(--radius-md); cursor: pointer;
      color: var(--color-text-secondary);
      transition: var(--transition-fast);
    }
    .viewer-toolbar .btn-icon:hover {
      background: var(--color-primary-muted);
      color: var(--color-primary);
      border-color: var(--color-primary);
    }

    .viewer-toolbar__title {
      font-family: var(--font-heading);
      font-weight: var(--heading-weight-primary);
      font-size: 1rem;
      color: var(--color-text-primary);
      flex: 1;
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }

    .zoom-controls {
      display: flex; gap: var(--space-1); margin-left: auto;
    }

    .svg-container {
      flex: 1; overflow: hidden; position: relative;
      background: var(--color-bg-base);
      cursor: grab;
    }
    .svg-container:active { cursor: grabbing; }

    .svg-wrapper {
      width: 100%; height: 100%;
      transform-origin: center center;
      transition: none;
      display: flex; align-items: center; justify-content: center;
    }
    .svg-wrapper svg {
      max-width: 100%; max-height: 100%;
    }

    .svg-loading, .svg-error {
      color: var(--color-text-muted);
      font-size: var(--text-body);
      padding: var(--space-6);
    }

    /* ---- Parts list sidebar ---- */
    .parts-sidebar {
      width: 280px; flex-shrink: 0;
      background: var(--color-bg-elevated);
      border-left: 1px solid var(--color-border);
      overflow-y: auto;
      display: flex; flex-direction: column;
    }

    .parts-list__title {
      padding: var(--space-4);
      font-family: var(--font-heading);
      font-weight: var(--heading-weight-primary);
      font-size: var(--text-body-sm);
      text-transform: uppercase;
      letter-spacing: var(--tracking-wide);
      color: var(--color-text-muted);
      border-bottom: 1px solid var(--color-border);
    }

    .part-item {
      display: flex; align-items: center; gap: var(--space-3);
      padding: var(--space-3) var(--space-4);
      cursor: pointer; border-bottom: 1px solid var(--color-border);
      transition: var(--transition-fast);
      border-left: 3px solid transparent;
    }
    .part-item:hover, .part-item.is-highlighted {
      background: var(--color-primary-muted);
      border-left-color: var(--color-primary);
    }
    .part-item.is-active {
      background: rgba(245, 166, 35, 0.15);
      border-left-color: var(--color-primary);
    }

    .part-item__callout {
      width: 28px; height: 28px;
      display: flex; align-items: center; justify-content: center;
      background: var(--color-primary);
      color: var(--color-text-inverse);
      font-weight: var(--font-weight-bold);
      font-size: var(--text-body-sm);
      border-radius: var(--radius-full);
      flex-shrink: 0;
    }

    .part-item__info { min-width: 0; }
    .part-item__name {
      font-weight: var(--font-weight-semibold);
      font-size: var(--text-body-sm);
      color: var(--color-text-primary);
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .part-item__number {
      font-size: var(--text-caption);
      color: var(--color-text-muted);
      font-family: var(--font-mono, monospace);
    }

    .parts-list__empty {
      padding: var(--space-6);
      text-align: center;
      color: var(--color-text-muted);
      font-size: var(--text-body-sm);
    }

    /* ---- Hotspot detail panel ---- */
    .hotspot-panel {
      position: fixed;
      bottom: 0; left: 260px; right: 280px;
      background: var(--color-bg-elevated);
      border-top: 2px solid var(--color-primary);
      box-shadow: var(--shadow-lg);
      padding: var(--space-4) var(--space-5);
      transform: translateY(100%);
      transition: transform var(--duration-normal) var(--ease-in-out);
      z-index: 50;
    }
    .hotspot-panel.is-open {
      transform: translateY(0);
    }

    .hotspot-panel__close {
      position: absolute; top: var(--space-3); right: var(--space-4);
      background: none; border: none; cursor: pointer;
      font-size: 1.3rem; color: var(--color-text-muted);
      padding: var(--space-1);
    }
    .hotspot-panel__close:hover { color: var(--color-text-primary); }

    .hotspot-detail {
      display: flex; align-items: center; gap: var(--space-5); flex-wrap: wrap;
    }

    .hotspot-callout {
      width: 40px; height: 40px;
      display: flex; align-items: center; justify-content: center;
      background: var(--color-primary); color: var(--color-text-inverse);
      font-weight: var(--font-weight-bold); font-size: 1.2rem;
      border-radius: var(--radius-full); flex-shrink: 0;
    }

    .hotspot-name {
      font-family: var(--font-heading);
      font-weight: var(--heading-weight-primary);
      font-size: 1.1rem;
      color: var(--color-text-primary);
      margin: 0;
    }
    .hotspot-partnumber {
      font-size: var(--text-body-sm);
      color: var(--color-text-muted);
      font-family: var(--font-mono, monospace);
    }
    .hotspot-desc {
      font-size: var(--text-body-sm);
      color: var(--color-text-secondary);
      max-width: 400px;
      margin: 0;
    }

    .hotspot-actions {
      display: flex; gap: var(--space-2); margin-left: auto;
    }

    /* ---- Buttons ---- */
    .btn {
      display: inline-flex; align-items: center; gap: var(--space-2);
      padding: var(--space-2) var(--space-4);
      border: 1px solid var(--color-border);
      border-radius: var(--radius-md);
      font-family: var(--font-body);
      font-size: var(--text-body-sm);
      font-weight: var(--font-weight-semibold);
      cursor: pointer;
      transition: var(--transition-fast);
      background: var(--color-bg-elevated);
      color: var(--color-text-primary);
      text-decoration: none;
    }
    .btn-primary {
      background: var(--color-primary);
      color: var(--color-text-inverse);
      border-color: var(--color-primary);
    }
    .btn-primary:hover { opacity: 0.9; }
    .btn-accent {
      background: var(--color-success, #22c55e);
      color: white;
      border-color: var(--color-success, #22c55e);
    }
    .btn-accent:hover { opacity: 0.9; }
    .btn-sm {
      padding: var(--space-1) var(--space-3);
      font-size: var(--text-caption);
    }

    /* =========================================================================
       RESPONSIVE
       ========================================================================= */

    @media (max-width: 900px) {
      .sidebar { width: 56px; overflow: hidden; }
      .sidebar__brand { padding: var(--space-3); justify-content: center; }
      .brand-name { display: none; }
      .nav-section-label { display: none; }
      .nav-item { padding: var(--space-2) var(--space-3); justify-content: center; }
      .nav-item span:not(.nav-item__icon) { display: none; }

      .parts-sidebar { width: 200px; }
      .hotspot-panel { left: 56px; right: 200px; }
    }

    @media (max-width: 640px) {
      .parts-sidebar { display: none; }
      .hotspot-panel { left: 56px; right: 0; }
      .diagram-grid { grid-template-columns: 1fr; }
    }
