:root {
  --bg: #f7f8fb;
  --surface: rgba(255,255,255,.88);
  --surface-solid: #fff;
  --text: #172033;
  --muted: #70809a;
  --border: #e7ebf2;
  --border-strong: #d8dee9;
  --accent: #4f6bff;
  --accent-strong: #3f56da;
  --danger: #d84f57;
  --shadow: 0 18px 55px rgba(17, 31, 62, .08);
  --radius-lg: 22px;
  --radius-md: 14px;
  --sidebar: 292px;
  --share: 316px;
  --editor-size: 15px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top left, #fff 0, #f8f9fd 42%, #f3f5fa 100%);
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

.app-shell { min-height: 100dvh; }
.login-view { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(430px, 100%);
  padding: 34px;
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 28px;
  background: rgba(255,255,255,.78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.brand-mark, .brand-symbol {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 14px; background: #101827; color: white; font-weight: 800;
}
.eyebrow { margin: 0 0 6px; font-size: 11px; letter-spacing: .17em; color: var(--muted); font-weight: 800; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: 29px; letter-spacing: -.03em; }
.login-subtitle { color: var(--muted); line-height: 1.6; margin-bottom: 26px; }
.login-note { margin: 18px 0 0; color: #98a3b5; font-size: 12px; line-height: 1.55; }
.stack { display: grid; gap: 15px; }
.field { display: grid; gap: 8px; }
.field > span { font-size: 12px; font-weight: 700; color: #5e6b80; }
.field input, .search-box input, .share-result input {
  width: 100%; min-height: 44px; padding: 0 13px;
  border: 1px solid var(--border-strong); border-radius: 12px;
  background: #fff; color: var(--text); outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .search-box input:focus, .share-result input:focus, textarea:focus {
  border-color: rgba(79,107,255,.62); box-shadow: 0 0 0 4px rgba(79,107,255,.10);
}
.input-with-action { position: relative; }
.input-with-action input { padding-right: 48px; }
.input-with-action .icon-btn { position: absolute; right: 4px; top: 4px; height: 36px; }

.primary-btn, .secondary-btn, .ghost-btn, .icon-btn, .danger-outline {
  border: 0; border-radius: 11px; min-height: 42px; padding: 0 15px;
  transition: transform .12s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.primary-btn:hover, .secondary-btn:hover, .ghost-btn:hover, .icon-btn:hover, .danger-outline:hover { transform: translateY(-1px); }
.primary-btn { background: var(--accent); color: white; font-weight: 750; box-shadow: 0 8px 18px rgba(79,107,255,.22); }
.primary-btn:hover { background: var(--accent-strong); }
.primary-btn.compact { min-height: 36px; padding: 0 14px; }
.secondary-btn { background: #f3f5f9; color: #34415a; font-weight: 650; border: 1px solid var(--border); }
.ghost-btn, .icon-btn { background: transparent; color: #607089; }
.ghost-btn:hover, .icon-btn:hover { background: #f3f5f9; }
.danger-outline { color: var(--danger); background: #fff; border: 1px solid #efc9cc; }
.form-error { margin: 0; font-size: 13px; color: var(--danger); }

.disk-view { min-height: 100dvh; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  height: 72px; display: flex; justify-content: space-between; align-items: center;
  padding: 0 22px; border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.78); backdrop-filter: blur(14px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand strong { display: block; font-size: 15px; }
.brand span { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }
.top-actions { display: flex; gap: 4px; align-items: center; }
.mobile-only { display: none; }
.workspace { min-height: 0; display: grid; grid-template-columns: var(--sidebar) minmax(0,1fr) var(--share); }
.sidebar, .share-panel, .editor-panel { min-width: 0; min-height: 0; }
.sidebar { border-right: 1px solid var(--border); background: rgba(248,250,253,.86); display: flex; flex-direction: column; }
.sidebar-head { padding: 18px 16px 12px; display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.sidebar-head h2 { font-size: 18px; margin-bottom: 0; letter-spacing: -.02em; }
.mini-actions { display: flex; gap: 2px; }
.search-box { margin: 0 13px 10px; position: relative; display: flex; align-items: center; }
.search-box > span { position: absolute; left: 12px; color: #9aa5b7; }
.search-box input { min-height: 40px; padding-left: 32px; padding-right: 38px; }
.search-box .icon-btn { position: absolute; right: 3px; min-height: 34px; width: 34px; padding: 0; }
.breadcrumb { padding: 4px 16px 9px; color: #7f8da2; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-list { flex: 1; overflow: auto; padding: 0 8px 16px; }
.file-row {
  display: flex; align-items: center; gap: 9px; min-height: 42px; padding: 7px 8px;
  border-radius: 11px; color: #4d5b70; margin-bottom: 2px;
}
.file-row:hover { background: #eef2fb; }
.file-row.selected { background: #e8edff; color: #3f56da; }
.file-row .type { width: 22px; text-align: center; font-size: 14px; flex: 0 0 22px; }
.file-row .name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.file-row .more { opacity: .5; }
.file-row.folder .name { font-weight: 650; }

.editor-panel { background: #fff; position: relative; display: flex; min-height: calc(100dvh - 72px); }
.empty-state { margin: auto; width: min(560px, calc(100% - 48px)); text-align: center; padding: 28px; }
.empty-illustration { width: 72px; height: 72px; margin: 0 auto 18px; display: grid; place-items: center; border-radius: 20px; background: #f0f3f9; color: #6f7b8e; font-size: 32px; }
.empty-state h2 { margin-bottom: 8px; font-size: 23px; }
.empty-state p { color: var(--muted); line-height: 1.7; }
.empty-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.editor-state { display: flex; flex-direction: column; width: 100%; min-height: 0; }
.editor-toolbar { min-height: 62px; padding: 10px 14px; display: flex; justify-content: space-between; gap: 12px; align-items: center; border-bottom: 1px solid var(--border); }
.path-title { min-width: 0; display: flex; align-items: center; gap: 10px; }
.doc-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: #f0f3f8; font-size: 10px; font-weight: 800; color: #63718a; }
.path-title strong { display: block; max-width: 340px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.path-title span:last-child { display: block; color: #96a1b1; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 340px; margin-top: 2px; }
.editor-tools { display: flex; align-items: center; gap: 3px; }
.editor-tools > span { width: 26px; text-align: center; color: #78859a; font-size: 12px; }
.save-status { min-height: 30px; display: flex; align-items: center; padding: 0 16px; border-bottom: 1px solid var(--border); color: #9aa4b4; font-size: 11px; }
.save-status.unsaved { color: #b57a16; background: #fff8e9; }
#editor { flex: 1; width: 100%; resize: none; border: 0; outline: none; padding: 18px 20px 20px; font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; font-size: var(--editor-size); line-height: 1.7; color: #222c3d; background: #fff; }
.editor-footer { display: flex; justify-content: space-between; padding: 7px 14px; border-top: 1px solid var(--border); color: #99a2b0; font-size: 10px; }

.share-panel { border-left: 1px solid var(--border); background: rgba(249,250,252,.8); padding: 12px; }
.share-panel details { border: 1px solid var(--border); border-radius: 16px; background: rgba(255,255,255,.88); overflow: hidden; }
.share-panel summary { list-style: none; padding: 14px; cursor: pointer; font-weight: 750; font-size: 13px; }
.share-panel summary::-webkit-details-marker { display: none; }
.share-content { padding: 0 14px 15px; display: grid; gap: 12px; }
.muted { color: var(--muted); font-size: 11px; line-height: 1.6; margin: 0; }
.row-actions { display: flex; gap: 8px; }
.row-actions > * { flex: 1; }
.share-result { display: grid; gap: 8px; padding-top: 4px; }
.share-ok { color: #198a55; font-size: 11px; font-weight: 700; }
.share-result input { font-size: 11px; background: #f8fafc; }

.toast-root { position: fixed; right: 18px; bottom: 18px; z-index: 50; display: grid; gap: 8px; }
.toast { padding: 11px 14px; background: #101827; color: white; border-radius: 11px; box-shadow: 0 12px 28px rgba(0,0,0,.18); font-size: 12px; max-width: min(360px, calc(100vw - 36px)); }
.modal-backdrop { position: fixed; inset: 0; background: rgba(17, 24, 39, .42); display: grid; place-items: center; z-index: 40; padding: 18px; backdrop-filter: blur(4px); }
.modal { width: min(460px, 100%); padding: 22px; border-radius: 20px; background: #fff; box-shadow: 0 24px 80px rgba(0,0,0,.24); }
.modal h3 { margin: 0 0 16px; font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 17px; }

.install-hint { position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 35; padding: 13px 14px; border: 1px solid #dbe2ef; border-radius: 15px; background: rgba(255,255,255,.97); box-shadow: var(--shadow); font-size: 12px; line-height: 1.55; }

@media (max-width: 1100px) {
  :root { --sidebar: 250px; --share: 280px; }
}
@media (max-width: 860px) {
  .mobile-only { display: inline-grid; place-items: center; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 72px auto 0 0; width: min(88vw, 330px); transform: translateX(-104%); z-index: 20; box-shadow: 12px 0 36px rgba(0,0,0,.10); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .share-panel { border-left: 0; border-top: 1px solid var(--border); }
  .editor-panel { min-height: calc(100dvh - 72px); }
  .topbar::after { content: '☰'; margin-right: auto; margin-left: 12px; color: #65738a; }
}
@media (max-width: 600px) {
  .topbar { height: 62px; padding: 0 12px; }
  .workspace { min-height: calc(100dvh - 62px); }
  .editor-panel { min-height: calc(100dvh - 62px); }
  .brand-symbol { width: 38px; height: 38px; border-radius: 12px; }
  .brand strong { font-size: 14px; }
  .top-actions .ghost-btn#refreshBtn, .top-actions .ghost-btn#logoutBtn { font-size: 0; width: 38px; padding: 0; }
  .top-actions .ghost-btn#refreshBtn::before { content: '↻'; font-size: 17px; }
  .top-actions .ghost-btn#logoutBtn::before { content: '⇱'; font-size: 17px; }
  .editor-toolbar { align-items: flex-start; }
  .editor-tools { flex-wrap: wrap; justify-content: flex-end; }
  .path-title strong { max-width: 160px; }
  .path-title span:last-child { max-width: 160px; }
  #editor { padding: 14px 13px 18px; font-size: var(--editor-size); }
  .editor-footer { gap: 12px; flex-direction: column; }
  .share-panel { padding: 9px; }
}
@media (display-mode: standalone) {
  .topbar { padding-top: max(0px, env(safe-area-inset-top)); height: calc(62px + env(safe-area-inset-top)); }
  .workspace { min-height: calc(100dvh - 62px - env(safe-area-inset-top)); }
  .editor-panel { min-height: calc(100dvh - 62px - env(safe-area-inset-top)); }
}
