/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --text-muted: #888;
  --accent: #4f8ef7;
  --accent-hover: #6fa3ff;
  --danger: #e05252;
  --folder: #f5c842;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ── Auth pages ── */
.auth-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
}

.auth-box h1 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.auth-sub { color: var(--text-muted); margin-bottom: 1.5rem; }

.auth-box form { display: flex; flex-direction: column; gap: 1rem; }

.auth-box label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.auth-box input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  padding: 0.55rem 0.75rem;
  outline: none;
  transition: border-color 0.15s;
}

.auth-box input:focus { border-color: var(--accent); }

.auth-box button[type=submit] {
  margin-top: 0.25rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.6rem;
  transition: background 0.15s;
}

.auth-box button[type=submit]:hover { background: var(--accent-hover); }

.auth-switch {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 1.25rem;
  text-align: center;
}

.error {
  background: rgba(224,82,82,.15);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
}

/* ── App layout ── */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.25rem;
  height: 48px;
  flex-shrink: 0;
}

.app-logo { font-weight: 600; letter-spacing: -0.02em; }

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-name { color: var(--text-muted); font-size: 0.85rem; }

.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

#tree {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

/* Tree entries (sidebar) */
.tree-folder {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 1rem;
  cursor: pointer;
  color: var(--text);
  font-size: 0.88rem;
  border-radius: 0;
  transition: background 0.1s;
}

.tree-folder:hover { background: var(--border); }
.tree-folder.active { background: rgba(79,142,247,.15); color: var(--accent); }

/* ── Main pane ── */
.main-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.main-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex: 1;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.crumb {
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  border-radius: 4px;
  transition: background 0.1s;
}

.crumb:hover { background: var(--border); color: var(--text); }
.crumb.active { color: var(--text); cursor: default; }
.crumb.active:hover { background: none; }

.crumb-sep { color: var(--border); }

#file-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1.25rem;
}

/* ── Entry rows ── */
.entry {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius);
  transition: background 0.1s;
  cursor: default;
}

.entry:hover { background: var(--surface); }

.entry-icon { flex-shrink: 0; display: flex; align-items: center; }
.entry.folder .entry-icon { color: var(--folder); }
.entry.file .entry-icon { color: var(--text-muted); }

.entry-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.folder-link { cursor: pointer; }
.folder-link:hover { color: var(--accent); }

.entry-meta { color: var(--text-muted); font-size: 0.8rem; flex-shrink: 0; }

.entry-actions {
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  transition: opacity 0.1s;
}

.entry:hover .entry-actions { opacity: 1; }

/* ── Buttons ── */
.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
  transition: border-color 0.15s, background 0.15s;
}

.btn-ghost:hover { background: var(--border); }

.btn-icon {
  background: none;
  border: none;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  transition: color 0.15s, background 0.15s;
}

.btn-icon:hover { color: var(--danger); background: rgba(224,82,82,.1); }

.btn-sm {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.35rem 0.9rem;
  transition: background 0.15s;
}

.btn-sm:hover { background: var(--accent-hover); }

.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.5rem 1.2rem;
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--accent-hover); }

/* ── Upload progress ── */
.upload-progress {
  position: absolute;
  bottom: 1.25rem;
  left: 1.25rem;
  right: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}

.upload-progress-info {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.4rem;
  gap: 0.5rem;
}

.upload-progress-name {
  font-size: 0.82rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-progress-pct {
  font-size: 0.78rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.upload-progress-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.upload-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.1s linear;
}

/* ── Drop overlay ── */
.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(79,142,247,.12);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 10;
}

.drop-message {
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: 500;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 320px;
}

.modal h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }

.modal input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  padding: 0.5rem 0.75rem;
  transition: border-color 0.15s;
}

.modal input:focus { border-color: var(--accent); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* ── Misc ── */
.loading { color: var(--text-muted); padding: 0.75rem 1rem; font-size: 0.85rem; }

.empty-state {
  color: var(--text-muted);
  padding: 3rem 1rem;
  text-align: center;
}

.empty-state .hint { font-size: 0.85rem; margin-top: 0.4rem; }

/* ── File link in list ── */
.file-link {
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-link:hover { color: var(--accent); text-decoration: none; }

/* ── File detail page ── */
.file-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
}

.file-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.25rem;
  height: 48px;
  flex-shrink: 0;
}

.back-link {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  font-size: 0.88rem;
  text-decoration: none;
  transition: color 0.15s;
}
.back-link:hover { color: var(--text); text-decoration: none; }

.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.4rem 1rem;
  text-decoration: none;
  transition: background 0.15s;
}
.btn-download:hover { background: var(--accent-hover); color: #fff; text-decoration: none; }

.file-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.file-meta-panel {
  width: 260px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 2rem 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.file-icon-large { color: var(--accent); }

.file-name {
  font-size: 1rem;
  font-weight: 600;
  word-break: break-all;
  line-height: 1.4;
}

.file-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 1rem;
  font-size: 0.83rem;
}
.file-meta dt { color: var(--text-muted); white-space: nowrap; }
.file-meta dd { color: var(--text); word-break: break-all; }

.file-preview-panel {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem;
}

.preview-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0,0,0,.4);
}

.preview-pdf {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: var(--radius);
}

.preview-text-wrap {
  width: 100%;
  max-width: 860px;
}

.preview-text {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  overflow-x: auto;
  padding: 1.25rem 1.5rem;
  white-space: pre;
}

.preview-unsupported {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  color: var(--text-muted);
  padding-top: 4rem;
}

.preview-unsupported-icon { color: var(--text-muted); opacity: .5; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Share button ── */
.btn-icon.share-btn:hover { color: var(--accent); background: rgba(79,142,247,.1); }

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(0.5rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 200;
  white-space: nowrap;
  max-width: 80vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
#toast.toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* ── Shares page ── */
.shares-page {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.shares-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.shares-title { font-size: 1.2rem; font-weight: 600; }
.shares-count { color: var(--text-muted); font-size: 0.85rem; }

.shares-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.share-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  transition: background 0.1s;
}
.share-row:hover { background: var(--surface); }

.share-kind-icon { flex-shrink: 0; color: var(--text-muted); display: flex; }
.share-kind-icon .entry.folder & { color: var(--folder); }

.share-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-meta { color: var(--text-muted); font-size: 0.8rem; flex-shrink: 0; }

.share-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.shares-pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.page-info { color: var(--text-muted); font-size: 0.85rem; flex: 1; text-align: center; }

/* ── Share folder page ── */
.share-folder-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
}

.share-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.25rem;
  height: 48px;
  flex-shrink: 0;
}

.share-branding { color: var(--text-muted); font-size: 0.85rem; margin-right: auto; }
.share-folder-name { font-size: 0.95rem; font-weight: 600; }

.share-file-list { padding: 0.75rem 1.25rem; }

/* ── OAuth ── */
.oauth-scope { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem 1.25rem; margin: 1rem 0; }
.oauth-scope p { font-size: 0.85rem; color: var(--text-muted); margin: 0 0 0.5rem; }
.oauth-scope ul { margin: 0; padding-left: 1.25rem; font-size: 0.9rem; }
.oauth-scope li { margin-bottom: 0.25rem; }
.oauth-actions { display: flex; gap: 0.75rem; margin-top: 1.25rem; }
.oauth-actions button { flex: 1; }
.btn-secondary { background: var(--surface) !important; color: var(--text) !important; border: 1px solid var(--border) !important; }
.btn-secondary:hover { background: var(--border) !important; }
