/* ============================================================
   BASE + SHELL LAYOUT
   ============================================================ */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--c-accent-glow); color: var(--c-text); }
*:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-line-strong); border-radius: var(--r-pill); border: 2px solid var(--c-bg); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

h1,h2,h3,h4 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
code, .mono { font-family: var(--font-mono); }

#boot-screen {
  position: fixed; inset: 0; z-index: 2000; background: var(--c-bg);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.25s ease;
}
.boot-card { text-align: center; color: var(--c-text-dim); font-size: var(--fs-xs); }

.login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 20%, var(--c-accent-glow), transparent 45%), var(--c-bg);
  padding: var(--sp-4); z-index: 100;
}
.login-card {
  width: 420px; max-width: 100%; background: var(--c-surface); border: 1px solid var(--c-line);
  border-radius: var(--r-xl); box-shadow: var(--shadow-lg); padding: var(--sp-8) var(--sp-6);
  animation: modal-in var(--dur-slow) var(--ease);
}
.login-title { text-align: center; font-size: var(--fs-xl); margin-bottom: 2px; }
.login-subtitle { text-align: center; color: var(--c-text-dim); font-size: var(--fs-sm); margin-bottom: var(--sp-6); }
.login-divider { display: flex; align-items: center; gap: var(--sp-3); margin: var(--sp-5) 0; color: var(--c-text-faint); font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: .05em; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--c-line); }
.login-error { background: var(--c-coral-dim); color: var(--c-coral); border-radius: var(--r-md); padding: 8px 12px; font-size: var(--fs-xs); margin-bottom: var(--sp-3); }
.quick-login-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-2); }
.quick-login-tile {
  background: var(--c-surface-2); border: 1px solid var(--c-line); border-radius: var(--r-md);
  padding: var(--sp-3); text-align: center; cursor: pointer; color: var(--c-text); font-size: var(--fs-2xs);
  transition: all var(--dur-fast) var(--ease);
}
.quick-login-tile:hover { border-color: var(--c-accent); background: var(--c-accent-glow); }

#app-root {
  display: grid;
  grid-template-columns: var(--rail-w) auto 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "rail topbar topbar"
    "rail sidebar main";
  height: 100vh;
  width: 100vw;
  transition: grid-template-columns var(--dur-med) var(--ease);
}
#app-root.sidebar-collapsed { grid-template-columns: var(--rail-w) 0 1fr; }

/* ---- Icon Rail ---- */
.rail {
  grid-area: rail;
  background: var(--c-surface);
  border-right: 1px solid var(--c-line);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--sp-3) 0;
  gap: var(--sp-2);
  z-index: 30;
}
.rail-logo {
  width: 36px; height: 36px; border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--c-accent), var(--c-accent-dim));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; color: #06201C;
  margin-bottom: var(--sp-4); font-size: var(--fs-md);
  box-shadow: var(--shadow-glow);
}
.rail-item {
  width: 44px; height: 44px; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--c-text-dim); cursor: pointer; position: relative;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  border: none; background: transparent;
}
.rail-item svg { width: var(--rail-icon-size, 22px); height: var(--rail-icon-size, 22px); transition: transform .16s ease, color .16s ease; }
.rail-item:hover svg { transform: scale(1.22); }
.rail-item:not([data-cic]):hover svg { color: var(--c-accent); }
.rail-item.active svg { transform: scale(1.08); }
.rail-label { display: none; }
body.rail-labels .rail-label { display: block; font-size: 8.5px; line-height: 1.1; margin-top: 2px; color: var(--c-text-dim); max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.rail-labels .rail-item { flex-direction: column; height: auto; padding: 6px 2px; }
body.rail-labels .rail { width: 68px; }
.rail-item:hover { background: var(--c-surface-2); color: var(--c-text); }
.rail-item.active { background: var(--c-accent-glow); color: var(--c-accent); }
.rail-item.active::before {
  content: ""; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; background: var(--c-accent); border-radius: var(--r-pill);
}
.rail-item .tooltip {
  position: absolute; left: 56px; top: 50%; transform: translateY(-50%) translateX(-4px);
  background: var(--c-surface-3); color: var(--c-text); padding: 6px 10px; border-radius: var(--r-sm);
  font-size: var(--fs-xs); white-space: nowrap; opacity: 0; pointer-events: none;
  box-shadow: var(--shadow-md); transition: all var(--dur-fast) var(--ease); z-index: 100;
  border: 1px solid var(--c-line);
}
.rail-item:hover .tooltip { opacity: 1; transform: translateY(-50%) translateX(0); }
.rail-spacer { flex: 1; }

/* ---- Top Bar ---- */
.topbar {
  grid-area: topbar;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-line);
  display: flex; align-items: center;
  padding: 0 var(--sp-5);
  gap: var(--sp-4);
  z-index: 20;
}
.topbar .crumb {
  font-family: var(--font-display); font-size: var(--fs-md); font-weight: 600;
  display: flex; align-items: center; gap: var(--sp-2); color: var(--c-text);
}
.crumb .sep { color: var(--c-text-faint); font-weight: 400; }
.crumb .dim { color: var(--c-text-faint); font-weight: 500; }
.topbar-search {
  flex: 1; max-width: 560px; margin: 0 auto;
  position: relative;
}
.topbar-search input {
  width: 100%; background: var(--c-surface-2); border: 1px solid var(--c-line);
  border-radius: var(--r-pill); padding: 9px 14px 9px 38px; color: var(--c-text);
  font-size: var(--fs-sm); transition: all var(--dur-fast) var(--ease);
}
.topbar-search input:focus { border-color: var(--c-accent); background: var(--c-surface); box-shadow: 0 0 0 3px var(--c-accent-glow); outline: none; }
.topbar-search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--c-text-faint); }
.topbar-search .kbd-hint {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font-size: var(--fs-2xs); color: var(--c-text-faint); border: 1px solid var(--c-line);
  padding: 1px 6px; border-radius: var(--r-sm); font-family: var(--font-mono);
}
.topbar-actions { display: flex; align-items: center; gap: var(--sp-3); }
.icon-btn {
  width: 34px; height: 34px; border-radius: var(--r-md); border: none;
  background: transparent; color: var(--c-text-dim); display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all var(--dur-fast) var(--ease); position: relative;
}
.icon-btn:hover { background: var(--c-surface-2); color: var(--c-text); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .dot { position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--c-amber); border: 2px solid var(--c-surface); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg,var(--c-accent),var(--c-blue));
  display: flex; align-items: center; justify-content: center; font-size: var(--fs-xs); font-weight: 700;
  color: #06201C; cursor: pointer;
}

/* ---- Sidebar ---- */
.sidebar {
  grid-area: sidebar;
  background: var(--c-surface);
  border-right: 1px solid var(--c-line);
  overflow: hidden; overflow-y: auto;
  width: var(--sidebar-w);
  transition: width var(--dur-med) var(--ease), padding var(--dur-med) var(--ease);
}
#app-root.sidebar-collapsed .sidebar { width: 0; padding: 0; border: none; }
.sidebar-section { padding: var(--sp-4) var(--sp-4) var(--sp-2); }
.sidebar-label {
  font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--c-text-faint); font-weight: 600; padding: var(--sp-2) var(--sp-2);
}
.tree-node { display: flex; align-items: center; gap: var(--sp-2); padding: 7px var(--sp-2); border-radius: var(--r-md); cursor: pointer; color: var(--c-text-dim); font-size: var(--fs-sm); white-space: nowrap; }
.tree-node:hover { background: var(--c-surface-2); color: var(--c-text); }
.tree-node.active { background: var(--c-accent-glow); color: var(--c-accent); font-weight: 600; }
.tree-node .chev { width: 14px; height: 14px; transition: transform var(--dur-fast) var(--ease); color: var(--c-text-faint); flex-shrink:0; }
.tree-node.open > .chev { transform: rotate(90deg); }
.tree-node .icon { width: 16px; height: 16px; flex-shrink: 0; color: var(--c-text-faint); }
.tree-node .count { margin-left: auto; font-size: var(--fs-2xs); color: var(--c-text-faint); font-family: var(--font-mono); }
.tree-children { padding-left: var(--sp-5); overflow: hidden; max-height: 0; transition: max-height var(--dur-med) var(--ease); }
.tree-children.open { max-height: 1000px; }

/* ---- Main workspace ---- */
.main {
  grid-area: main;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--c-bg);
}
.view-scroll { flex: 1; overflow-y: auto; padding: var(--sp-6); }
.view-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-5); flex-wrap: wrap; gap: var(--sp-3); }
.view-title { font-size: var(--fs-xl); font-weight: 600; }
.view-subtitle { color: var(--c-text-dim); font-size: var(--fs-sm); margin-top: 2px; }
.toolbar { display: flex; align-items: center; gap: var(--sp-2); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 8px 14px; border-radius: var(--r-md); border: 1px solid var(--c-line);
  background: var(--c-surface-2); color: var(--c-text); font-size: var(--fs-sm); font-weight: 500;
  cursor: pointer; transition: all var(--dur-fast) var(--ease); white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { background: var(--c-surface-3); border-color: var(--c-line-strong); }
.btn.primary { background: var(--c-accent); border-color: var(--c-accent); color: #06201C; font-weight: 600; }
.btn.primary:hover { background: #17CFBB; box-shadow: var(--shadow-glow); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--c-surface-2); }
.btn.sm { padding: 5px 10px; font-size: var(--fs-xs); }
.btn.danger { color: var(--c-coral); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.seg {
  display: flex; background: var(--c-surface-2); border: 1px solid var(--c-line); border-radius: var(--r-md); padding: 2px; gap: 2px;
}
.seg button {
  border: none; background: transparent; color: var(--c-text-dim); padding: 6px 10px; border-radius: var(--r-sm);
  cursor: pointer; display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); transition: all var(--dur-fast) var(--ease);
}
.seg svg { width: 14px; height: 14px; }
.seg button.active { background: var(--c-surface-3); color: var(--c-text); box-shadow: var(--shadow-sm); }

/* ---- Badges / lifecycle chip ---- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: var(--r-pill);
  font-size: var(--fs-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--state-bg, var(--c-surface-3)); color: var(--state-c, var(--c-text-dim));
}
.chip::before { content:""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.chip.plain { background: var(--c-surface-3); color: var(--c-text-dim); text-transform: none; font-weight: 500; letter-spacing: 0; }
.chip.plain::before { display: none; }

/* lifecycle ribbon - signature element */
.ribbon { width: 4px; align-self: stretch; border-radius: var(--r-pill); background: var(--state-c, var(--c-line-strong)); flex-shrink: 0; }

/* ---- Card ---- */
.card {
  background: var(--c-surface); border: 1px solid var(--c-line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); transition: box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.card.hoverable:hover { box-shadow: var(--shadow-md); border-color: var(--c-line-strong); transform: translateY(-1px); }
.card-pad { padding: var(--sp-5); }

/* ---- Panels (dockable right panel) ---- */
.panel {
  width: var(--panel-w); flex-shrink: 0; background: var(--c-surface); border-left: 1px solid var(--c-line);
  display: flex; flex-direction: column; height: 100%;
}
.panel-header { padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--c-line); display:flex; align-items:center; justify-content:space-between; }
.panel-tabs { display: flex; border-bottom: 1px solid var(--c-line); padding: 0 var(--sp-3); }
.panel-tab { padding: var(--sp-3) var(--sp-3); font-size: var(--fs-xs); color: var(--c-text-dim); cursor: pointer; border-bottom: 2px solid transparent; font-weight: 600; }
.panel-tab.active { color: var(--c-accent); border-color: var(--c-accent); }
.panel-body { flex: 1; overflow-y: auto; padding: var(--sp-5); }
.kv-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--c-line); font-size: var(--fs-sm); gap: var(--sp-3); }
.kv-row .k { color: var(--c-text-faint); }
.kv-row .v { color: var(--c-text); text-align: right; font-weight: 500; }

/* ---- Table ---- */
.dtable { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.dtable thead th {
  position: sticky; top: 0; background: var(--c-bg); text-align: left; padding: var(--sp-2) var(--sp-3);
  color: var(--c-text-faint); font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--c-line); font-weight: 600; cursor: pointer; user-select: none; z-index: 5;
}
.dtable thead th:hover { color: var(--c-text); }
.dtable tbody tr { border-bottom: 1px solid var(--c-line); cursor: pointer; transition: background var(--dur-fast) var(--ease); }
.dtable tbody tr:hover { background: var(--c-surface-2); }
.dtable tbody tr.selected { background: var(--c-accent-glow); }
.dtable td { padding: var(--sp-3); vertical-align: middle; }
.dtable .doc-name-cell { display: flex; align-items: center; gap: var(--sp-3); }
.file-icon { width: 30px; height: 30px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 700; color: white; flex-shrink: 0; }

/* ---- Empty / skeleton ---- */
.skel { background: linear-gradient(90deg, var(--c-surface-2) 25%, var(--c-surface-3) 37%, var(--c-surface-2) 63%); background-size: 400% 100%; animation: skel-shimmer 1.4s ease infinite; border-radius: var(--r-md); }
@keyframes skel-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--sp-16) var(--sp-6); color: var(--c-text-dim); text-align: center; gap: var(--sp-3); }
.empty-state svg { width: 48px; height: 48px; color: var(--c-text-faint); }
.empty-state h3 { font-size: var(--fs-md); color: var(--c-text); }
.empty-state p { font-size: var(--fs-sm); max-width: 320px; }

/* ---- Context menu ---- */
.ctx-menu {
  position: fixed; background: var(--c-surface-3); border: 1px solid var(--c-line-strong); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg); padding: var(--sp-2); min-width: 210px; z-index: 1000;
  animation: ctx-in var(--dur-fast) var(--ease);
}
@keyframes ctx-in { from { opacity: 0; transform: scale(0.97) translateY(-4px); } to { opacity: 1; transform: none; } }
.ctx-item { display: flex; align-items: center; gap: var(--sp-3); padding: 7px var(--sp-3); border-radius: var(--r-sm); font-size: var(--fs-sm); cursor: pointer; color: var(--c-text); }
.ctx-item:hover { background: var(--c-surface); color: var(--c-accent); }
.ctx-item svg { width: 15px; height: 15px; color: var(--c-text-faint); }
.ctx-item.danger:hover { color: var(--c-coral); }
.ctx-sep { height: 1px; background: var(--c-line); margin: var(--sp-2) 4px; }
.ctx-shortcut { margin-left: auto; font-size: var(--fs-2xs); color: var(--c-text-faint); font-family: var(--font-mono); }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6,10,12,0.6); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 500; animation: fade-in var(--dur-fast) var(--ease);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--c-surface); border: 1px solid var(--c-line-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  width: 560px; max-width: 92vw; max-height: 86vh; display: flex; flex-direction: column;
  animation: modal-in var(--dur-med) var(--ease);
}
.modal.wide { width: 920px; }
@keyframes modal-in { from { opacity: 0; transform: scale(0.96) translateY(8px); } to { opacity: 1; transform: none; } }
.modal-header { padding: var(--sp-5); border-bottom: 1px solid var(--c-line); display: flex; align-items: center; justify-content: space-between; }
.modal-body { padding: var(--sp-5); overflow-y: auto; }
.modal-footer { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--c-line); display: flex; justify-content: flex-end; gap: var(--sp-2); }

/* ---- Toast ---- */
.toast-stack { position: fixed; bottom: var(--sp-5); right: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); z-index: 900; }
.toast {
  background: var(--c-surface-3); border: 1px solid var(--c-line-strong); border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  padding: var(--sp-3) var(--sp-4); display: flex; align-items: center; gap: var(--sp-3); font-size: var(--fs-sm); min-width: 260px;
  animation: toast-in var(--dur-med) var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.toast .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ---- Grids / views ---- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--sp-4); }
.doc-card { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }
.doc-card .thumb { height: 110px; border-radius: var(--r-md); background: var(--c-surface-2); display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.doc-card .thumb svg { width: 34px; height: 34px; color: var(--c-text-faint); }
.doc-card .name { font-size: var(--fs-sm); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-card .meta { font-size: var(--fs-2xs); color: var(--c-text-faint); font-family: var(--font-mono); }
.doc-card .foot { display: flex; align-items: center; justify-content: space-between; }

/* utility */
.flex { display: flex; } .items-center { align-items: center; } .gap-2 { gap: var(--sp-2); } .gap-3 { gap: var(--sp-3); }
.text-dim { color: var(--c-text-dim); } .text-faint { color: var(--c-text-faint); }
.mt-2 { margin-top: var(--sp-2); } .mt-4 { margin-top: var(--sp-4); }
.w-full { width: 100%; }
.bar-track { background: var(--c-surface-2); border-radius: var(--r-pill); overflow: hidden; height: 6px; }
.bar-fill { height: 100%; border-radius: var(--r-pill); background: var(--c-accent); transition: width var(--dur-slow) var(--ease); }

@media (max-width: 900px) {
  :root { --sidebar-w: 220px; }
  .topbar-search { display: none; }
}
