:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --border: #e2e6ef;
  --text: #1f2430;
  --text-dim: #6b7280;
  --accent: #2f6df0;
  --accent-soft: #e8f0fe;
  --danger: #e0413a;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .18);
  --radius: 12px;
  --desktop-bg: linear-gradient(135deg, #1b3a6b 0%, #2f6df0 55%, #4f86ff 100%);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Login ---------- */
.login {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: var(--desktop-bg);
}
.login-card {
  width: 320px; background: var(--surface);
  padding: 32px 28px; border-radius: 16px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 12px;
}
.login-logo { font-size: 28px; font-weight: 700; letter-spacing: -.5px; text-align: center; }
.login-logo span { color: var(--accent); }
.login-sub { margin: 0 0 8px; text-align: center; color: var(--text-dim); font-size: 14px; }
.login-card input {
  padding: 11px 13px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 15px; outline: none;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button {
  margin-top: 4px; padding: 11px; border: 0; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 600;
}
.login-card button:hover { background: #2559cf; }
.login-error { color: var(--danger); font-size: 13px; min-height: 16px; text-align: center; }

/* ---------- App shell ---------- */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 0 18px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow); z-index: 10;
}
.brand { font-size: 20px; font-weight: 700; letter-spacing: -.5px; }
.brand span { color: var(--accent); }
.views { display: flex; gap: 6px; }
.view-tab {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 8px;
  font-size: 14px; color: var(--text-dim); font-weight: 500;
}
.view-tab:hover { background: var(--surface-2); }
.view-tab.active { background: var(--accent-soft); color: var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.who { font-size: 13px; color: var(--text-dim); }
.btn-primary {
  border: 0; background: var(--accent); color: #fff;
  padding: 8px 14px; border-radius: 8px; font-size: 14px; font-weight: 600;
}
.btn-primary:hover { background: #2559cf; }
.btn-ghost {
  border: 1px solid var(--border); background: var(--surface);
  padding: 7px 12px; border-radius: 8px; font-size: 14px; color: var(--text);
}
.btn-ghost:hover { background: var(--surface-2); }

.view { flex: 1; overflow: hidden; }

/* ---------- Desktop ---------- */
.desktop { position: relative; background: var(--desktop-bg); }
.desktop-surface { position: absolute; inset: 0; overflow: hidden; }
.desktop-hint {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  color: rgba(255,255,255,.8); font-size: 12px; pointer-events: none;
  background: rgba(0,0,0,.18); padding: 4px 12px; border-radius: 20px;
}
.dicon {
  position: absolute; width: 92px; padding: 8px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border-radius: 10px; cursor: default; user-select: none; text-align: center;
}
.dicon:hover { background: rgba(255,255,255,.14); }
.dicon.selected { background: rgba(255,255,255,.26); outline: 1px solid rgba(255,255,255,.5); }
.dicon .glyph { font-size: 44px; line-height: 1; filter: drop-shadow(0 2px 3px rgba(0,0,0,.3)); }
.dicon .label {
  font-size: 12px; color: #fff; word-break: break-word; max-height: 32px; overflow: hidden;
  text-shadow: 0 1px 3px rgba(0,0,0,.6);
}
.dicon.dragging { opacity: .8; z-index: 999; }

/* ---------- Explorer ---------- */
.explorer { display: flex; }
.tree {
  width: 240px; background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 12px 8px; flex-shrink: 0;
}
.tree-node { user-select: none; }
.tree-row {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px;
  border-radius: 7px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.tree-row:hover { background: var(--surface-2); }
.tree-row.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree-row .twisty { width: 14px; font-size: 10px; color: var(--text-dim); text-align: center; }
.tree-children { margin-left: 14px; }

.explorer-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.explorer-toolbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 18px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.breadcrumb { display: flex; align-items: center; gap: 4px; flex: 1; font-size: 14px; flex-wrap: wrap; }
.breadcrumb .crumb { color: var(--accent); cursor: pointer; padding: 2px 4px; border-radius: 5px; }
.breadcrumb .crumb:hover { background: var(--accent-soft); }
.breadcrumb .sep { color: var(--text-dim); }
.breadcrumb .crumb.current { color: var(--text); cursor: default; font-weight: 600; }
.toolbar-actions { display: flex; gap: 8px; }

.dropzone { position: relative; flex: 1; overflow-y: auto; }
.file-area { padding: 18px; }
.file-area.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.file-area.list { display: flex; flex-direction: column; gap: 2px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; align-items: center; gap: 10px;
  cursor: default; position: relative; transition: box-shadow .15s, border-color .15s;
}
.card:hover { box-shadow: var(--shadow); border-color: #c9d2e3; }
.card .glyph { font-size: 40px; }
.card .thumb { width: 100%; height: 72px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.card .name { font-size: 13px; text-align: center; word-break: break-word; max-height: 34px; overflow: hidden; }
.card .meta { font-size: 11px; color: var(--text-dim); }
.card .menu-dot {
  position: absolute; top: 6px; right: 6px; border: 0; background: transparent;
  border-radius: 6px; padding: 2px 6px; color: var(--text-dim); font-size: 16px; line-height: 1;
}
.card .menu-dot:hover { background: var(--surface-2); }
.card.shared::after { content: "🔗"; position: absolute; top: 8px; left: 8px; font-size: 13px; }

/* list rows */
.file-area.list .card {
  flex-direction: row; align-items: center; gap: 12px; padding: 8px 14px; border-radius: 8px;
}
.file-area.list .card .glyph { font-size: 22px; }
.file-area.list .card .thumb { width: 34px; height: 34px; }
.file-area.list .card .name { text-align: left; flex: 1; max-height: none; }
.file-area.list .card .meta { white-space: nowrap; }

.empty { color: var(--text-dim); text-align: center; padding: 60px 20px; font-size: 14px; }

.drop-overlay {
  position: absolute; inset: 0; display: none; place-items: center;
  background: rgba(47,109,240,.1); border: 2px dashed var(--accent);
  border-radius: 12px; margin: 10px; pointer-events: none;
}
.drop-overlay span { background: var(--accent); color: #fff; padding: 8px 18px; border-radius: 20px; font-weight: 600; }
.dropzone.dragover .drop-overlay { display: grid; }

/* ---------- Context menu ---------- */
.context-menu {
  position: fixed; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-lg); padding: 6px; min-width: 180px; z-index: 1000;
}
.context-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent;
  padding: 9px 12px; border-radius: 7px; font-size: 14px; color: var(--text); text-align: left;
}
.context-menu button:hover { background: var(--surface-2); }
.context-menu button.danger { color: var(--danger); }
.context-menu .sep { height: 1px; background: var(--border); margin: 4px 2px; }

/* ---------- Toast & modal ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f2430; color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 14px; box-shadow: var(--shadow-lg); z-index: 2000; max-width: 80vw;
}
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: center; z-index: 1500;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  padding: 22px; width: 360px; max-width: 90vw; display: flex; flex-direction: column; gap: 14px;
}
.modal h3 { margin: 0; font-size: 17px; }
.modal input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; font-size: 14px; outline: none;
}
.modal input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; }
.modal .link-box {
  display: flex; gap: 8px; align-items: center; background: var(--surface-2);
  padding: 8px 10px; border-radius: 8px; font-size: 13px; word-break: break-all;
}
.progress { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
