  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  :root {
    --bg:       #0f1117;
    --panel:    #181c27;
    --border:   #2a2f3e;
    --accent:   #c8102e;
    --accent2:  #e63950;
    --text:     #e2e6ef;
    --muted:    #6b7280;
    --hover:    #232840;
    --active:   #1e2640;
    --active-b: #c8102e;
    --ring:     #c8102e44;
    --cat-bg:   #1a1f30;
  }

  html, body { height: 100%; overflow: hidden; font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); }

  /* ── Layout ── */
  .app { display: grid; grid-template-columns: 260px 1fr; grid-template-rows: 56px 1fr; height: 100vh; }

  /* ── Header ── */
  header {
    grid-column: 1 / -1;
    display: flex; align-items: center; gap: 14px;
    padding: 0 20px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 8px #0007;
  }
  .logo-ring { width: 32px; height: 32px; border: 2.5px solid var(--accent); border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; }
  .logo-ring svg { width: 18px; height: 18px; fill: var(--accent); }
  header h1 { font-size: 15px; font-weight: 600; letter-spacing: .03em; color: var(--text); }
  header h1 span { color: var(--accent); }
  .header-tag { font-size: 11px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }

  /* ── Search ── */
  .search-wrap {
    margin-left: auto;
    position: relative; display: flex; align-items: center;
  }
  .search-input {
    width: 220px; padding: 6px 12px 6px 32px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text); font-size: 13px;
    outline: none; transition: border-color .15s, width .2s;
  }
  .search-input::placeholder { color: var(--muted); }
  .search-input:focus { border-color: var(--accent); width: 280px; }
  .search-icon {
    position: absolute; left: 9px; top: 50%; transform: translateY(-50%);
    color: var(--muted); font-size: 13px; pointer-events: none;
  }
  .search-clear {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    color: var(--muted); cursor: pointer; font-size: 14px; line-height: 1;
    display: none;
  }
  .search-clear:hover { color: var(--text); }

  /* Search results */
  .search-results {
    flex: 1; overflow-y: auto; padding: 0;
  }
  .search-results::-webkit-scrollbar { width: 4px; }
  .search-results::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
  .search-group-label {
    padding: 10px 16px 4px;
    font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
    color: var(--muted);
  }
  .search-result-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 16px; cursor: pointer;
    border-left: 2px solid transparent;
    transition: background .1s, border-color .1s;
  }
  .search-result-item:hover { background: var(--hover); border-left-color: var(--accent); }
  .sri-icon { font-size: 14px; flex-shrink: 0; }
  .sri-text { flex: 1; min-width: 0; }
  .sri-name { font-size: 12px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sri-name mark { background: none; color: var(--accent2); font-weight: 600; }
  .sri-meta { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .search-empty {
    padding: 32px 16px; text-align: center;
    font-size: 13px; color: var(--muted);
  }

  /* ── Sidebar ── */
  .sidebar {
    background: var(--panel);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    display: flex; flex-direction: column;
  }
  .sidebar::-webkit-scrollbar { width: 4px; }
  .sidebar::-webkit-scrollbar-track { background: transparent; }
  .sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

  /* Car tabs */
  .car-tabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
  .car-tab {
    flex: 1; padding: 12px 8px; text-align: center;
    font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
    color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent;
    transition: color .15s, border-color .15s, background .15s;
  }
  .car-tab:hover { color: var(--text); background: var(--hover); }
  .car-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

  /* Category list */
  .cat-label {
    padding: 14px 16px 6px;
    font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
    color: var(--muted); flex-shrink: 0;
  }
  .cat-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 16px; cursor: pointer;
    font-size: 13px; color: var(--text);
    border-left: 2px solid transparent;
    transition: background .1s, border-color .1s, color .1s;
  }
  .cat-item:hover { background: var(--hover); }
  .cat-item.active { background: var(--active); border-left-color: var(--active-b); color: #fff; }
  .cat-icon { font-size: 15px; flex-shrink: 0; width: 20px; text-align: center; }
  .cat-count {
    margin-left: auto; font-size: 10px; background: var(--border);
    color: var(--muted); border-radius: 10px; padding: 1px 7px;
  }

  /* Sidebar file items */
  .file-item {
    display: flex; align-items: flex-start; gap: 8px;
    padding: 5px 14px 5px 40px;
    cursor: pointer; font-size: 12px; color: var(--muted);
    border-left: 2px solid transparent;
    line-height: 1.4; user-select: none;
    transition: background .1s, color .1s, border-color .1s;
  }
  .file-item:hover { background: var(--hover); color: var(--text); border-left-color: var(--border); }
  .file-item.file-active { color: var(--accent2); border-left-color: var(--accent); background: var(--active); }
  .file-item-bullet { flex-shrink: 0; color: var(--border); font-size: 10px; margin-top: 2px; }

  /* Document group separator inside expanded category */
  .doc-separator {
    padding: 6px 14px 2px 16px;
    font-size: 9px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
    color: #3a4157; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }

  /* ── Main ── */
  .main { display: flex; flex-direction: column; overflow: hidden; }

  /* File list panel */
  .file-panel {
    display: none; flex-direction: column;
    background: var(--bg); height: 100%;
  }
  .file-panel.active { display: flex; }

  .file-panel-header {
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  .file-panel-header h2 { font-size: 16px; font-weight: 600; }
  .file-panel-header p { font-size: 12px; color: var(--muted); margin-top: 2px; }

  .file-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
  }
  .file-grid::-webkit-scrollbar { width: 5px; }
  .file-grid::-webkit-scrollbar-track { background: transparent; }
  .file-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

  .file-card {
    display: flex; align-items: center; gap: 0;
    border-radius: 6px;
    background: var(--panel); border: 1px solid var(--border);
    cursor: pointer; overflow: hidden;
    transition: border-color .15s, background .15s, transform .15s;
    transform: translateX(0);
  }
  .file-card:hover { border-color: var(--fc-color); background: var(--hover); transform: translateX(3px); }
  .file-card:active { transform: translateX(1px); opacity: .85; }

  /* Colored left stripe */
  .fc-stripe {
    width: 3px; align-self: stretch; flex-shrink: 0;
    background: var(--fc-color);
    transition: width .15s;
  }
  .file-card:hover .fc-stripe { width: 4px; }

  /* Doc thumbnail */
  .fc-thumb {
    width: 52px; height: 52px; flex-shrink: 0;
    margin: 10px 0 10px 14px;
    position: relative;
    border-radius: 4px;
    background: color-mix(in srgb, var(--fc-color) 12%, var(--bg));
    border: 1px solid color-mix(in srgb, var(--fc-color) 30%, transparent);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  }
  /* Schematic lines inside thumb */
  .fc-thumb::before {
    content: '';
    position: absolute; inset: 8px 7px;
    background:
      linear-gradient(var(--fc-color) 1px, transparent 1px) 0 0 / 100% 7px,
      linear-gradient(var(--fc-color) 1px, transparent 1px) 0 0 / 100% 7px;
    background-repeat: repeat-y;
    opacity: .18;
  }
  .fc-format {
    font-size: 9px; font-weight: 800; letter-spacing: .1em;
    color: var(--fc-color); text-transform: uppercase;
    position: relative; z-index: 1;
    background: color-mix(in srgb, var(--fc-color) 15%, var(--bg));
    border: 1px solid color-mix(in srgb, var(--fc-color) 40%, transparent);
    padding: 1px 4px; border-radius: 3px;
  }

  /* Text block */
  .fc-body {
    flex: 1; min-width: 0;
    padding: 0 14px;
    display: flex; flex-direction: column; gap: 3px;
  }
  .fc-name {
    font-size: 13px; font-weight: 500; color: var(--text);
    line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .file-card:hover .fc-name { color: #fff; }

  /* Arrow */
  .fc-arrow {
    flex-shrink: 0; width: 36px; height: 36px; margin-right: 10px;
    display: grid; place-items: center;
    color: var(--muted); font-size: 14px;
    opacity: 0; transform: translateX(-4px);
    transition: opacity .15s, transform .15s, color .15s;
  }
  .file-card:hover .fc-arrow { opacity: 1; transform: translateX(0); color: var(--fc-color); }

  /* Viewer */
  .viewer-panel {
    display: none; flex-direction: column; height: 100%;
    background: #111;
  }
  .viewer-panel.active { display: flex; }

  .viewer-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 16px;
    background: var(--panel); border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  .back-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 5px 12px; border-radius: 6px;
    background: var(--hover); border: 1px solid var(--border);
    color: var(--text); font-size: 12px; cursor: pointer;
    transition: background .15s, border-color .15s;
  }
  .back-btn:hover { background: var(--active); border-color: var(--accent); }
  .viewer-title { font-size: 13px; font-weight: 500; color: var(--text); margin-left: 4px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .open-btn {
    padding: 5px 12px; border-radius: 6px;
    background: var(--accent); border: none;
    color: #fff; font-size: 12px; cursor: pointer;
    transition: background .15s;
    text-decoration: none; display: inline-block;
  }
  .open-btn:hover { background: var(--accent2); }

  .viewer-frame { flex: 1; border: none; background: #111; }

  .img-viewer { flex: 1; overflow: auto; display: flex; align-items: flex-start; justify-content: center; padding: 20px; }
  .img-viewer img { max-width: 100%; border-radius: 4px; box-shadow: 0 4px 24px #0008; }

  /* Welcome */
  .welcome {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 10px; color: var(--muted); text-align: center;
    padding: 40px;
  }
  .welcome-icon { font-size: 48px; opacity: .4; }
  .welcome h3 { font-size: 16px; color: var(--text); opacity: .6; }
  .welcome p { font-size: 13px; max-width: 300px; line-height: 1.6; }

  /* ── Hamburger ── */
  .menu-btn {
    display: none; align-items: center; justify-content: center;
    width: 36px; height: 36px; flex-shrink: 0;
    background: none; border: none; cursor: pointer;
    color: var(--text); border-radius: 6px;
    transition: background .15s;
  }
  .menu-btn:hover { background: var(--hover); }
  .menu-btn svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }

  /* ── Sidebar backdrop ── */
  .overlay {
    display: none; position: fixed; inset: 0; z-index: 99;
    background: #00000080;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }
  .overlay.visible { display: block; }

  /* ── Responsive: tablet ── */
  @media (max-width: 1023px) {
    .app { grid-template-columns: 220px 1fr; }
    .header-tag { display: none; }
    .search-input { width: 160px; }
    .search-input:focus { width: 210px; }
  }

  /* ── Responsive: mobile ── */
  @media (max-width: 639px) {
    .app { grid-template-columns: 1fr; }

    .menu-btn { display: flex; }

    /* Sidebar becomes a fixed drawer */
    .sidebar {
      position: fixed;
      top: 52px; bottom: 0; left: -280px;
      width: 280px; z-index: 100;
      transition: left .25s cubic-bezier(.4,0,.2,1);
      box-shadow: 4px 0 24px #000a;
    }
    .sidebar.open { left: 0; }

    /* Header: tighter, search goes to icon mode */
    header { padding: 0 12px; gap: 10px; height: 52px; }
    header h1 { font-size: 14px; }

    /* Mobile search: icon button that toggles full search bar */
    .search-wrap { margin-left: auto; }
    .search-input { width: 0; padding: 6px 0; border-color: transparent; background: transparent; }
    .search-wrap.active .search-input {
      width: 100%; padding: 6px 30px 6px 32px;
      border-color: var(--accent); background: var(--bg);
    }
    .search-icon { cursor: pointer; pointer-events: auto; padding: 4px; }

    /* When search is active, search bar takes over the whole header */
    header.search-active { gap: 0; }
    header.search-active .menu-btn,
    header.search-active .logo-ring,
    header.search-active h1 { display: none; }
    header.search-active .search-wrap { width: 100%; }
    header.search-active .search-input {
      width: 100%; padding: 6px 30px 6px 32px;
      border-color: var(--accent); background: var(--bg);
    }

    /* File panel padding */
    .file-grid { padding: 12px 14px; gap: 5px; }
    .file-panel-header { padding: 12px 14px 10px; }
    .fc-thumb { width: 44px; height: 44px; margin: 8px 0 8px 12px; }

    /* Viewer bar tighter */
    .viewer-bar { padding: 8px 10px; gap: 8px; }
    .viewer-title { font-size: 12px; }

    /* Welcome */
    .welcome { padding: 24px 20px; }
  }

  /* ── Content search results ── */
  .sri-page { font-size: 10px; color: var(--muted); margin-top: 2px; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sri-page mark { background: none; color: var(--accent2); font-weight: 600; }
  .sri-badge { float: right; margin-left: 6px; font-size: 9px; padding: 1px 5px; border-radius: 3px; background: var(--border); color: var(--muted); }
  .search-section-label { padding: 8px 16px 2px; font-size: 9px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #444d60; }
