/* ==========================================================================
 * Workspace layer: login, ribbon, file explorer, save/load modal.
 * Loaded after app.css, so the layout overrides below win.
 * ========================================================================*/

body.auth-locked { overflow: hidden; }
body.auth-locked .topbar,
body.auth-locked .shell {
  filter: blur(2.5px);
  pointer-events: none;
  user-select: none;
}

/* ---------------- shell + app ---------------- */
.shell {
  display: flex;
  align-items: flex-start;
  max-width: 1720px;
  margin: 0 auto;
  min-height: calc(100vh - 78px);
}
.shell .app {
  flex: 1;
  min-width: 0;
  max-width: none;
  margin: 18px 0 40px;
  padding: 0 18px 0 14px;
}

/* ---------------- ribbon ---------------- */
.ribbon {
  position: sticky;
  top: 78px;
  z-index: 32;
  flex: 0 0 46px;
  width: 46px;
  height: calc(100vh - 96px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 10px 6px;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .04), transparent 40%),
    linear-gradient(180deg, #0d2438, #102e49);
  border: 1px solid rgba(255, 255, 255, .08);
  box-shadow: 0 12px 30px -22px rgba(0, 0, 0, .7);
}
.ribbon-user {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin-bottom: 3px;
  background: #f6b26b;
  color: #0d2438;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .02em;
}
.ribbon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #a9c0d4;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.ribbon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ribbon-btn:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.ribbon-btn.active { background: rgba(246, 178, 107, .15); border-color: rgba(246, 178, 107, .35); color: #f6b26b; }
.ribbon-btn.danger:hover { background: rgba(248, 113, 113, .16); color: #fca5a5; }
.ribbon-spacer { flex: 1; }

/* ---------------- explorer ---------------- */
.explorer {
  position: sticky;
  top: 78px;
  z-index: 31;
  flex: 0 0 280px;
  width: 280px;
  height: calc(100vh - 96px);
  margin: 18px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  transition: margin-left .22s ease, opacity .18s ease, transform .22s ease;
}
.explorer.closed {
  margin-left: -280px;
  opacity: 0;
  pointer-events: none;
}
.explorer-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 9px;
  border-bottom: 1px solid var(--line);
}
.eyebrow {
  display: block;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
}
.explorer-id strong { display: block; margin-top: 2px; font-size: 14px; }
.icon-btn {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.icon-btn:hover { background: #f1f5f8; color: var(--ink); }
.explorer-actions { display: flex; gap: 6px; padding: 9px 10px 7px; }
.explorer-actions .btn { flex: 1; padding: 0 8px; font-size: 10.5px; }
.explorer-actions .btn:last-child { flex: 0 0 30px; }
.explorer-path {
  flex: 0 0 auto;
  padding: 0 12px 7px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-tree {
  flex: 1;
  overflow: auto;
  padding: 2px 6px 10px;
  scrollbar-width: thin;
}
.file-tree::-webkit-scrollbar { width: 7px; }
.file-tree::-webkit-scrollbar-thumb { background: #c7d3dd; border-radius: 99px; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  padding: 3px 6px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink-2);
  font-size: 11.5px;
  line-height: 1.2;
}
.tree-row:hover { background: #eef4f8; }
.tree-row.selected { background: #e6f4f0; color: #0f5f4f; }
.tree-row.active { background: #fff4e6; }
.tree-row .ticon { flex: 0 0 14px; width: 14px; height: 14px; color: #7c8c9b; }
.tree-row .ticon svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.tree-row.folder .ticon { color: #b45309; }
.tree-row .tname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row.file { min-height: 34px; }
.tree-row.file .ttext { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.tree-row.file .tname { flex: none; font-size: 11.5px; }
.tree-row.file .tmeta { max-width: none; width: 100%; font-size: 8px; color: #8796a5; }
.tree-row .tmeta { flex: 0 1 auto; max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 8.5px; color: var(--muted); }
.tree-row .tcount { font-family: var(--mono); font-size: 9px; color: var(--muted); }
.tree-row .twisty {
  flex: 0 0 14px;
  width: 14px;
  height: 14px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  padding: 0;
  transition: transform .15s;
}
.tree-row .twisty svg { width: 10px; height: 10px; fill: none; stroke: currentColor; stroke-width: 2; }
.tree-row .twisty.open { transform: rotate(90deg); }
.tree-row .tdel {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  font-size: 12px;
  opacity: 0;
}
.tree-row:hover .tdel { opacity: 1; }
.tree-row .tdel:hover { background: #fdecec; color: var(--bad); }
.tree-children { margin-left: 12px; padding-left: 4px; border-left: 1px dashed #e1e8ee; }
.tree-empty { padding: 18px 10px; text-align: center; font-size: 11px; color: var(--muted); line-height: 1.5; }
.explorer-foot {
  flex: 0 0 auto;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  font-size: 9.5px;
  color: var(--muted);
  font-family: var(--mono);
}
.explorer-backdrop { display: none; }

/* ---------------- user chip / topbar ---------------- */
.user-chip {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .10);
  border: 1px solid rgba(255, 255, 255, .18);
  color: #e8f0f7;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .02em;
}

/* ---------------- login ---------------- */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  grid-template-columns: 1.12fr .88fr;
  background: #0b1a29;
  color: #e8f0f7;
}
.login-screen[hidden] { display: none; }
.login-art {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 52px 58px;
  background:
    radial-gradient(700px 420px at 78% 12%, rgba(15, 118, 110, .22), transparent 65%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .028) 0 1px, transparent 1px 40px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .028) 0 1px, transparent 1px 40px),
    linear-gradient(120deg, #091725, #123450);
}
.login-art::after {
  content: "";
  position: absolute;
  right: -140px;
  bottom: -180px;
  width: 560px;
  height: 560px;
  border: 1px solid rgba(246, 178, 107, .18);
  border-radius: 50%;
  box-shadow: 0 0 0 60px rgba(246, 178, 107, .04), 0 0 0 120px rgba(246, 178, 107, .03);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 42px; }
.login-brand .brand-mark { width: 46px; height: 46px; color: #f6b26b; flex: 0 0 auto; }
.login-brand .brand-mark svg { width: 100%; height: 100%; }
.login-brand strong { display: block; font-size: 16px; color: #fff; }
.login-brand span { font-size: 10.5px; color: #9fb6ca; letter-spacing: .04em; }
.login-art h2 {
  margin: 0 0 16px;
  font-size: clamp(34px, 4.4vw, 58px);
  line-height: 1.02;
  letter-spacing: -.035em;
  color: #fff;
  font-weight: 750;
}
.login-art p { max-width: 470px; color: #b6c9da; font-size: 14px; line-height: 1.65; margin: 0; }
.login-list { list-style: none; margin: 24px 0 0; padding: 0; display: flex; flex-direction: column; gap: 9px; font-size: 12.5px; color: #cfe0ee; }
.login-list li::before { content: "—"; color: #f6b26b; margin-right: 9px; }
.login-foot { position: absolute; left: 58px; right: 58px; bottom: 24px; font-size: 9.5px; color: #7f97ab; letter-spacing: .03em; }

.login-card {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 52px 48px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: #fff;
  color: var(--ink);
  align-self: stretch;
}
.login-card h2 { margin: 6px 0 6px; font-size: 27px; letter-spacing: -.02em; }
.login-card > p { margin: 0 0 22px; }
.login-card label { margin-bottom: 13px; font-size: 11.5px; }
.login-card input { height: 42px; font-family: var(--sans); font-size: 13px; margin-top: 5px; }
.login-submit { height: 42px; margin-top: 5px; }
.login-error {
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid #f3c0c0;
  border-radius: 6px;
  background: #fdecec;
  color: #991b1b;
  font-size: 11.5px;
}
/* ---------------- save/rename modal ---------------- */
.ws-modal {
  position: fixed;
  inset: 0;
  z-index: 210;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 17, 28, .55);
  backdrop-filter: blur(3px);
}
.ws-modal[hidden] { display: none; }
.ws-modal-card {
  width: min(430px, 100%);
  padding: 18px 18px 16px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 34px 70px -24px rgba(0, 0, 0, .55);
}
.ws-modal-card h3 { margin: 4px 0 6px; font-size: 16px; }
.ws-modal-hint { margin: 0 0 12px; font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.ws-modal-card label { margin-bottom: 10px; }
.ws-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.ws-modal-error { margin: 0 0 8px; color: var(--bad); font-size: 11px; }

/* ---------------- responsive ---------------- */
@media (max-width: 1280px) {
  .explorer { flex-basis: 252px; width: 252px; }
  .explorer.closed { margin-left: -252px; }
}
@media (max-width: 1100px) {
  .shell { display: block; }
  .shell .app { padding: 0 12px; }
  .ribbon { position: fixed; left: 0; top: 78px; bottom: 0; height: auto; border-radius: 0 10px 10px 0; z-index: 46; }
  .explorer {
    position: fixed;
    left: 46px;
    top: 78px;
    bottom: 0;
    width: 290px;
    height: auto;
    margin: 0;
    border-radius: 0 10px 10px 0;
    z-index: 42;
  }
  .explorer.closed { margin-left: 0; transform: translateX(-110%); opacity: 0; }
  .explorer-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 41;
    background: rgba(8, 17, 28, .42);
    backdrop-filter: blur(1px);
  }
}
@media (max-width: 900px) {
  .login-screen { grid-template-columns: 1fr; background: #0b1a29; }
  .login-art { display: none; }
  .login-card { max-width: 460px; border-radius: 14px; padding: 34px 28px; margin: 24px; align-self: center; }
}
@media (max-width: 640px) {
  .top-actions .user-chip { display: none; }
  .ribbon { top: 96px; bottom: 0; }
  .explorer { top: 96px; }
  .shell .app { margin-top: 12px; }
}

/* ---------------- print ---------------- */
@media print {
  .ribbon, .explorer, .explorer-backdrop, .login-screen, .ws-modal, .user-chip, #logoutBtn { display: none !important; }
  .shell { display: block; }
  body.auth-locked .topbar, body.auth-locked .shell { filter: none; }
}
