:root{
  --bg:#F6F7F9;
  --surface:#FFFFFF;
  --surface-sunken:#F1F3F6;
  --border:#E2E5EA;
  --border-strong:#D3D7DE;
  --text-primary:#15181E;
  --text-secondary:#6B7280;
  --text-tertiary:#9CA3AF;
  --accent:#2454E0;
  --accent-hover:#1D45C4;
  --accent-soft:#EAF0FE;
  --accent-soft-strong:#D6E2FD;
  --danger:#D64545;
  --danger-soft:#FDECEA;
  --shadow-sm: 0 1px 2px rgba(16,24,40,0.05);
  --shadow-md: 0 4px 12px rgba(16,24,40,0.08);
  --shadow-lg: 0 12px 32px rgba(16,24,40,0.16);
  --radius-sm:6px;
  --radius-md:10px;
  --radius-lg:16px;
  --font-ui: -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", ui-monospace, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#101318; --surface:#171B22; --surface-sunken:#1D222B;
    --border:#282E38; --border-strong:#363D49;
    --text-primary:#EDEFF3; --text-secondary:#9AA2B1; --text-tertiary:#6B7280;
    --accent:#5B85F5; --accent-hover:#7396F7;
    --accent-soft:#1C2740; --accent-soft-strong:#243255;
    --danger:#F27272; --danger-soft:#3A1E1E;
  }
}
:root[data-theme="dark"]{
  --bg:#101318; --surface:#171B22; --surface-sunken:#1D222B;
  --border:#282E38; --border-strong:#363D49;
  --text-primary:#EDEFF3; --text-secondary:#9AA2B1; --text-tertiary:#6B7280;
  --accent:#5B85F5; --accent-hover:#7396F7;
  --accent-soft:#1C2740; --accent-soft-strong:#243255;
  --danger:#F27272; --danger-soft:#3A1E1E;
}

*{box-sizing:border-box;}
html,body{height:100%;}
body{
  margin:0;
  background:var(--bg);
  color:var(--text-primary);
  font-family:var(--font-ui);
}
button{font-family:inherit;}
.hidden{display:none !important;}

/* ---------- Login ---------- */
.login-screen{
  min-height:100vh;
  display:flex;align-items:center;justify-content:center;
  background:var(--bg);
}
.login-card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  box-shadow:var(--shadow-lg);
  padding:40px 36px;
  text-align:center;
  width:min(360px, 90vw);
}
.brand-lg{
  display:flex;align-items:center;justify-content:center;gap:10px;
  font-size:22px;font-weight:700;color:var(--text-primary);
  margin-bottom:8px;
}
.brand-lg .mark{
  width:30px;height:30px;border-radius:8px;
  background:var(--accent);color:#fff;
  display:inline-flex;align-items:center;justify-content:center;
  font-size:15px;font-weight:700;
}
.login-card p{color:var(--text-primary);font-weight:600;font-size:14px;margin:0 0 20px;}

.connecting-dots{
  display:flex;align-items:center;justify-content:center;gap:7px;height:14px;
}
.connecting-dots span{
  width:8px;height:8px;border-radius:50%;background:var(--accent);
  animation:dot-bounce 1s ease-in-out infinite;
}
.connecting-dots span:nth-child(2){animation-delay:.15s;}
.connecting-dots span:nth-child(3){animation-delay:.3s;}
@keyframes dot-bounce{
  0%, 60%, 100%{transform:translateY(0);opacity:.5;}
  30%{transform:translateY(-8px);opacity:1;}
}
.brand-lg .mark{animation:mark-pulse 2s ease-in-out infinite;}
@keyframes mark-pulse{
  0%, 100%{box-shadow:0 0 0 0 var(--accent-soft-strong);}
  50%{box-shadow:0 0 0 8px transparent;}
}
@media (prefers-reduced-motion: reduce){
  .connecting-dots span, .brand-lg .mark{animation:none;}
}

/* ---------- App shell ---------- */
.app-root{display:flex;flex-direction:column;height:100vh;}
.topbar{
  display:flex;align-items:center;justify-content:space-between;
  padding:12px 20px;
  border-bottom:1px solid var(--border);
  background:var(--surface);
  flex-shrink:0;
}
.brand{
  display:flex;align-items:center;gap:8px;
  font-weight:700;font-size:15px;color:var(--text-primary);
}
.brand .mark{
  width:22px;height:22px;border-radius:6px;
  background:var(--accent);color:#fff;
  display:inline-flex;align-items:center;justify-content:center;
  font-size:12px;font-weight:700;
}
.app-shell{
  flex:1;
  display:grid;
  grid-template-columns:220px 1fr 6px var(--notes-width, 340px);
  min-height:0;
}
@media (max-width:1100px){
  .app-shell{grid-template-columns:190px 1fr 6px var(--notes-width, 300px);}
}
@media (max-width:860px){
  .app-shell{grid-template-columns:1fr;}
  .sidebar, .resizer{display:none;}
}

.resizer{
  cursor:col-resize;
  background:var(--border);
  position:relative;
}
.resizer::after{
  content:"";
  position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);
  width:3px;height:32px;border-radius:2px;background:var(--border-strong);
}
.resizer:hover, .resizer.dragging{background:var(--accent-soft);}
.resizer:hover::after, .resizer.dragging::after{background:var(--accent);}

/* Sidebar */
.sidebar{
  border-right:1px solid var(--border);
  background:var(--surface-sunken);
  padding:16px 12px;
  overflow:auto;
}
.nav-item{
  display:flex;align-items:center;gap:8px;
  padding:7px 8px;border-radius:var(--radius-sm);
  font-size:13.5px;font-weight:600;color:var(--text-primary);
  cursor:pointer;
}
.nav-item:hover{background:var(--surface);}
.nav-item.active{background:var(--accent-soft);color:var(--accent);}
.nav-item.folder{padding-left:22px;}

/* File pane */
.file-pane{display:flex;flex-direction:column;min-width:0;min-height:0;}
.pane-toolbar{
  display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:8px;
  padding:14px 20px;border-bottom:1px solid var(--border);
  background:var(--surface);
}
.breadcrumb{
  font-size:13px;font-weight:600;color:var(--text-primary);
  display:flex;align-items:center;gap:6px;flex-wrap:wrap;
}
.breadcrumb .sep{color:var(--text-primary);font-weight:600;}
.crumb-home, .crumb-link{
  cursor:pointer;padding:3px 6px;border-radius:6px;color:var(--text-primary);
}
.crumb-home:hover, .crumb-link:hover{color:var(--accent);background:var(--accent-soft);}
.crumb-current{padding:3px 6px;color:var(--text-primary);}

.toolbar-actions{display:flex;gap:8px;}
.btn{
  font-size:12.5px;font-weight:600;padding:7px 12px;border-radius:var(--radius-sm);
  border:1px solid var(--border-strong);background:var(--surface);color:var(--text-primary);
  display:inline-flex;align-items:center;gap:6px;cursor:pointer;
  transition:transform .1s ease, background .15s ease;
}
.btn:hover{border-color:var(--text-tertiary);}
.btn:active{transform:scale(.96);}
.btn.primary{background:var(--accent);border-color:var(--accent);color:#fff;}
.btn.primary:hover{background:var(--accent-hover);}
.btn.danger{background:var(--danger-soft);border-color:var(--danger-soft);color:var(--danger);}
.btn.lg{padding:11px 18px;font-size:14px;width:100%;justify-content:center;}

.file-grid{
  padding:18px 20px;flex:1;overflow:auto;
  display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:12px;
  align-content:start;
}
.empty-hint{grid-column:1/-1;color:var(--text-primary);font-weight:600;font-size:13px;text-align:center;padding:40px 0;}
.file-card{
  border:1px solid var(--border);border-radius:var(--radius-md);
  padding:14px 12px;background:var(--surface);
  display:flex;flex-direction:column;gap:10px;cursor:pointer;
  transition:border-color .15s ease, box-shadow .15s ease;
}
.file-card:hover{border-color:var(--border-strong);box-shadow:var(--shadow-sm);}
.file-icon{
  width:36px;height:36px;border-radius:8px;
  display:flex;align-items:center;justify-content:center;font-size:16px;
}
.file-icon.folder{background:var(--accent-soft);color:var(--accent);}
.file-icon.image{background:#FDECEA;color:#D64545;}
.file-icon.text{background:#EAF6EE;color:#2E9E5B;}
.file-icon.other{background:var(--surface-sunken);color:var(--text-primary);}
.file-thumb{width:36px;height:36px;border-radius:8px;object-fit:cover;}
.file-name{font-size:12.5px;font-weight:600;color:var(--text-primary);line-height:1.3;
  overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.file-meta{font-size:11px;color:var(--text-primary);font-weight:600;font-family:var(--font-mono);font-variant-numeric:tabular-nums;}
.upload-progress{height:3px;background:var(--border);border-radius:2px;overflow:hidden;margin-top:2px;}
.upload-progress-fill{height:100%;background:var(--accent);width:0%;transition:width .2s ease;}

/* Notes pane */
.notes-pane{
  border-left:1px solid var(--border);background:var(--surface);
  display:flex;flex-direction:column;min-height:0;
}
.notes-header{
  padding:14px 18px;border-bottom:1px solid var(--border);
  display:flex;align-items:center;justify-content:space-between;
}
.notes-header h3{margin:0;font-size:14px;font-weight:700;color:var(--text-primary);}
.notes-list{padding:14px 16px;display:flex;flex-direction:column;gap:12px;overflow:auto;flex:1;}
.note-card{
  border:1px solid var(--border);border-radius:var(--radius-md);
  background:var(--surface-sunken);padding:12px 12px 10px;position:relative;
}
.note-card pre, .note-card textarea{
  margin:0;font-family:var(--font-ui);font-size:12.5px;line-height:1.6;
  white-space:pre-wrap;word-break:break-word;color:var(--text-primary);
  padding-right:52px;background:transparent;border:none;width:100%;resize:vertical;
}
.note-card textarea{padding-right:12px;outline:none;min-height:60px;}
.note-actions{position:absolute;top:10px;right:10px;display:flex;gap:6px;}
.icon-btn{
  width:24px;height:24px;border-radius:6px;border:1px solid var(--border-strong);
  background:var(--surface);display:flex;align-items:center;justify-content:center;
  font-size:12px;color:var(--text-primary);cursor:pointer;
}
.icon-btn:hover{background:var(--accent-soft);color:var(--accent);border-color:var(--accent-soft-strong);}
.icon-btn.copied{background:var(--accent);border-color:var(--accent);color:#fff;}
.note-time{margin-top:8px;font-size:10.5px;color:var(--text-primary);font-weight:600;font-family:var(--font-mono);}
.add-note-btn{
  margin:4px 16px 16px;padding:11px;border-radius:var(--radius-md);
  border:1.5px solid var(--accent);background:var(--accent-soft);color:var(--accent);
  font-size:12.5px;font-weight:700;text-align:center;cursor:pointer;
  transition:transform .1s ease, background .15s ease, box-shadow .15s ease;
}
.add-note-btn:hover{background:var(--accent-soft-strong);box-shadow:var(--shadow-sm);}
.add-note-btn:active{transform:scale(.97);background:var(--accent);color:#fff;}

/* Mobile tabbar */
.tabbar{display:none;}
@media (max-width:860px){
  .app-shell{grid-template-columns:1fr;}
  .file-pane, .notes-pane{display:none;}
  .app-shell.show-files .file-pane{display:flex;}
  .app-shell.show-notes .notes-pane{display:flex;}
  .notes-pane{border-left:none;}
  .tabbar{
    display:flex;border-top:1px solid var(--border);background:var(--surface);
    padding:8px 8px calc(8px + env(safe-area-inset-bottom));flex-shrink:0;
  }
  .tab-btn{
    flex:1;display:flex;flex-direction:column;align-items:center;gap:3px;
    padding:6px 0;font-size:10.5px;font-weight:700;color:var(--text-primary);
    border-radius:10px;background:none;border:none;cursor:pointer;
  }
  .tab-btn .tic{font-size:18px;}
  .tab-btn.active{color:var(--accent);}
}

/* Modal */
.modal{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;z-index:50;}
.modal-backdrop{position:absolute;inset:0;background:rgba(15,18,23,0.5);}
.modal-card{
  position:relative;background:var(--surface);border-radius:var(--radius-lg);
  box-shadow:var(--shadow-lg);width:min(560px,92vw);max-height:85vh;
  display:flex;flex-direction:column;overflow:hidden;
}
.modal-head{
  display:flex;align-items:center;justify-content:space-between;
  padding:14px 18px;border-bottom:1px solid var(--border);
}
.modal-title{font-weight:700;font-size:14px;color:var(--text-primary);}
.modal-body{padding:18px;overflow:auto;flex:1;}
.modal-body img{max-width:100%;border-radius:var(--radius-sm);display:block;margin:0 auto;}
.modal-body pre{white-space:pre-wrap;word-break:break-word;font-size:13px;line-height:1.6;color:var(--text-primary);}
.modal-actions{display:flex;justify-content:flex-end;gap:8px;padding:14px 18px;border-top:1px solid var(--border);}

.toast{
  position:fixed;bottom:24px;left:50%;transform:translate(-50%,20px);
  background:var(--text-primary);color:var(--surface);
  font-size:13px;font-weight:600;padding:10px 16px;border-radius:var(--radius-md);
  box-shadow:var(--shadow-md);opacity:0;pointer-events:none;transition:opacity .2s ease, transform .2s ease;
  z-index:100;
}
.toast.show{opacity:1;transform:translate(-50%,0);}
