/* ---------- Theme ---------- */
:root{
  --bg: #0b0d11;
  --bg-2: #0f131a;
  --pane: #131826;
  --pane-2: #0f1523;
  --chrome: #171d2c;
  --chrome-2:#0f1422;
  --line: #222a3a;
  --text: #e7ecff;
  --muted:#96a3b9;
  --accent:#ff86db; /* Copland pink */
  --accent-2:#6dd6ff; /* neon teal */
  --ok:#7ce38b; --warn:#ffd36a; --err:#ff7a7a;
  --radius: 12px;
  --shadow: 0 30px 60px rgba(0,0,0,.55), inset 0 0 0 1px rgba(255,255,255,.04);
  --vh: 1vh; /* set via JS for mobile chrome */
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; color:var(--text);
  background: radial-gradient(1000px 520px at 50% -200px, #141a28 0%, #0b0d11 55%, #080a0d 100%);
  font:14px/1.45 "Segoe UI", Tahoma, Arial, sans-serif;
  -webkit-font-smoothing:antialiased; -moz-osx-font-smoothing:grayscale;
}

/* Subtle CRT scanlines */
body::after{
  content:""; pointer-events:none; position:fixed; inset:0;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,.045), rgba(255,255,255,.045) 1px, transparent 1px, transparent 3px);
  mix-blend-mode:overlay; opacity:.07;
}

/* Skip link */
.skip-link{position:absolute;left:-999px;top:auto;width:1px;height:1px;overflow:hidden}
.skip-link:focus{left:12px;top:12px;width:auto;height:auto;z-index:1000;background:#111;color:#fff;padding:.5rem .75rem;border-radius:8px}

/* Window shell */
.window{
  height: min(94vh, 860px);
  height: calc(var(--vh) * 94);
  width: min(1100px, 96vw);
  margin: max(12px, env(safe-area-inset-top)) auto max(18px, env(safe-area-inset-bottom));
  background: var(--pane);
  border: 1px solid #000; border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow);
  display:flex; flex-direction:column;
}

.titlebar{
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  padding:10px 12px; color:#fff;
  background: linear-gradient(180deg, #1c2750 0%, #152045 60%, #121a36 100%);
  border-bottom:1px solid #0a0f22;
  text-shadow:0 1px 0 rgba(0,0,0,.45);
}
.titlebar .name{font-weight:600; letter-spacing:.2px}
.win-btns{display:flex; gap:8px}
.wbtn{width:22px;height:22px;border-radius:6px;display:grid;place-items:center;cursor:pointer;background:#e6ecff0f;border:1px solid #2a3555;color:#cfe6ff}
.wbtn:hover{background:#e6ecff1a}

.menubar{display:flex; gap:14px; padding:6px 10px; background:var(--chrome); color:#d8e1ff; border-bottom:1px solid #0a0f22; font-size:13px}
.menubar button{appearance:none; border:0; background:transparent; color:#c4d1ff; padding:4px 6px; border-radius:6px; cursor:pointer}
.menubar button:hover{background:#ffffff10}
.menubar button:focus-visible{outline:2px solid var(--accent); outline-offset:2px}

.toolbar{display:flex; flex-wrap:wrap; align-items:center; gap:8px; padding:10px; background:linear-gradient(180deg, var(--chrome), var(--chrome-2)); border-bottom:1px solid #0a0f22}
.btn{display:inline-flex; align-items:center; gap:8px; padding:8px 12px; border-radius:10px; border:1px solid #2a3555; background:#e6ecff10; color:#dbe6ff; cursor:pointer; user-select:none}
.btn:hover{background:#e6ecff18}
.btn:active{transform:translateY(1px)}
.addr{flex:1 1 240px; display:flex; align-items:center; gap:8px; min-width:180px; padding:8px 10px; background:#0a0f1f; border:1px solid #2a3555; border-radius:10px; color:#dbe6ff}
.addr span{white-space:nowrap; overflow:hidden; text-overflow:ellipsis}
.filter{flex:1 1 180px; min-width:160px; display:flex; align-items:center; gap:8px; padding:8px 10px; background:#0a0f1f; border:1px solid #2a3555; border-radius:10px}
.filter input{flex:1; background:transparent; border:0; color:#e7ecff; outline:none}
.view-toggle{display:flex; gap:8px}
.mobile-only{display:none}

/* Layout body */
.body{
  flex:1; min-height:0; display:grid;
  grid-template-columns: 280px 1fr;
  grid-template-areas: "tree list";
}

/* Folder tree */
.tree{
  grid-area:tree; background:linear-gradient(180deg, #0e1424, #0c1120);
  border-right:1px solid #0a0f22; padding:10px; overflow:auto
}
.tree h3{margin:6px 6px 10px; font-size:12px; text-transform:uppercase; letter-spacing:.12em; color:var(--muted)}

/* Node buttons (reset native look) */
.tree .node{
  appearance:none; -webkit-appearance:none; background:transparent;
  border:1px solid transparent; color:var(--text); font:inherit;
  display:flex; align-items:center; gap:10px; padding:8px 10px; border-radius:8px; cursor:pointer;
}
.tree .node:hover{background:#ffffff0d}
.tree .node.active{background:#ff86db22; box-shadow:inset 0 0 0 1px #ff86db33}
.tree .node:focus{outline:none; background:transparent}
.tree .node:focus-visible{outline:2px solid var(--accent-2); outline-offset:2px}
.tree .node::-moz-focus-inner{border:0; padding:0}
.twisty{width:12px; text-align:center; color:#7e8aa5}

/* Files panel */
.list{
  grid-area:list; background:linear-gradient(180deg, #101627, #0b1020);
  overflow:auto; padding:12px
}
/* center the files area */
.list #view-icons, .list .table-wrap{ max-width:1100px; margin:0 auto }

/* Icon view */
.icons{display:grid; grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); gap:12px}
.icon{border:1px solid var(--line); border-radius:12px; padding:12px; background:var(--pane-2); display:flex; align-items:center; gap:12px}
.icon:hover{box-shadow:0 0 0 1px #8de4ff44; transform:translateY(-1px); transition:.15s}
.icon-left{width:40px; height:40px; display:grid; place-items:center; border-radius:10px; background:#1a2440}
.icon a{color:#dff3ff; font-weight:600; text-decoration:none}
.icon a:hover{text-decoration:underline}
.meta{font-size:12px; color:var(--muted)}

/* Details view */
.details{width:100%; border-collapse:collapse}
.details th, .details td{ text-align:left; padding:10px 12px; border-bottom:1px solid #1a2338; white-space:nowrap}
.details th{ position:sticky; top:0; background:#0f162a; color:#cfe0ff; font-weight:600; z-index:1}
.row:hover{ background:#131c33 }
.col-name a{ color:#dff3ff; text-decoration:none; font-weight:600 }
.col-name a:hover{text-decoration:underline}
.table-wrap{overflow:auto; max-width:100%}

/* Misc */
.i{width:16px;height:16px; display:inline-block}
.hint{ color:var(--muted); font-size:12px; padding:6px 10px 0 }

/* Drawer overlay lives OUTSIDE the grid */
.shade{ position: fixed; inset: 0; background: rgba(0,0,0,.5); display: none; z-index: 25; }
.nav-open .shade{ display: block; }

/* ---------- Responsive ---------- */

/* Medium screens: drawer behavior for tree */
@media (max-width: 880px){
  .mobile-only{ display:inline-flex; }
  .body{ grid-template-columns:1fr; grid-template-areas:"list"; }
  .tree{
    position: fixed; inset: 0 28% 0 0;
    max-width: 420px; transform: translateX(-100%);
    transition: transform .25s ease; z-index: 30; box-shadow: 12px 0 40px rgba(0,0,0,.45);
    border-right:1px solid #0a0f22; border-bottom:0;
  }
  .nav-open .tree{ transform: translateX(0) }

  /* extra breathing room so last card isn't clipped */
  .list{ padding-bottom: max(72px, env(safe-area-inset-bottom)); }
}

/* Small screens: inline tree + unified gutters + full-bleed window */
@media (max-width: 640px){
  /* full-bleed container */
  .window{
    margin: 0 auto max(12px, env(safe-area-inset-bottom));
    height: calc(var(--vh) * 100);
    width: 100vw;
    border: 0; border-radius: 0;
  }

  /* single-column layout, folders above files */
  .body{ grid-template-columns:1fr; grid-template-areas:"tree" "list"; }

  /* unified horizontal gutters */
  :root{ --gutter: clamp(12px, 4.5vw, 18px); }
  .titlebar, .menubar, .toolbar, .tree, .list{
    padding-left: max(var(--gutter), env(safe-area-inset-left));
    padding-right: max(var(--gutter), env(safe-area-inset-right));
  }

  /* tree inline + scrollable if tall */
  .tree{
    position: static; inset: auto; transform: none; max-width: none;
    max-height: 40vh; overflow: auto; box-shadow: none; border-right: 0;
    border-bottom: 1px solid #0a0f22;
  }

  /* files span full width inside gutters */
  .list #view-icons, .list .table-wrap{ max-width: 100%; margin: 0 }
  .icons{ grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

  .shade{ display: none !important; }
  .mobile-only{ display: none; } /* hide Folders button; tree is visible */

  /* allow page to scroll (no nested overflow traps) */
  .window{ height:auto; min-height: calc(var(--vh) * 100); }
  .list{ overflow: visible; }
}

/* Accessibility / motion */
:focus-visible{outline:2px solid var(--accent-2); outline-offset:2px}
@media (prefers-reduced-motion: reduce){ *{transition:none !important} }

/* --- Compact mode: trim fluff --- */
body.compact .menubar,
body.compact .titlebar .win-btns,
body.compact .hint { display:none; }
body.compact .titlebar{ padding:6px 10px; font-size:13px; }
body.compact .toolbar{ padding:6px 8px; gap:6px; }
body.compact .btn{ padding:6px 8px; border-radius:8px; }
body.compact .addr, body.compact .filter{ padding:6px 8px; }
body.compact .window{ border-radius:10px; box-shadow: 0 20px 40px rgba(0,0,0,.4), inset 0 0 0 1px rgba(255,255,255,.03); }
body.compact .icons{ gap:10px; }
body.compact .icon{ padding:10px; border-radius:10px; box-shadow:none; }
body.compact .icon:hover{ transform:none; }
body.compact .icon-left{ width:32px; height:32px; }
/* icon-only view buttons */
body.compact #viewIcons, body.compact #viewDetails{ font-size:0; width:40px; justify-content:center; }
body.compact #viewIcons .i, body.compact #viewDetails .i{ width:18px; height:18px; }
/* tiny screens: hide filter until toggled */
@media (max-width: 640px){
  body.compact .filter{ display:none; }
  body.compact.show-filter .filter{ display:flex; }
}
