:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e6e8eb;
  --text: #1f2328;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- Auth ---------- */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #f7f8fa 0%, #eef2ff 100%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 28px; }
.brand h1 { margin: 12px 0 4px; font-size: 24px; }
.brand p { margin: 0; }
.brand-logo {
  width: 52px; height: 52px;
  margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: #fff;
  background: var(--accent);
  border-radius: 14px;
}
.login-area { display: flex; justify-content: center; }
.dev-login { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.dev-login textarea {
  width: 100%;
  font: inherit; font-size: 13px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 500; font-size: 14px;
  border: none; border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.ghost:hover { background: #f0f1f3; }
.btn.block { width: 100%; }
.icon-btn {
  border: none; background: transparent; cursor: pointer;
  font-size: 16px; color: var(--muted);
  padding: 4px 8px; border-radius: 6px;
}
.icon-btn:hover { background: #f0f1f3; color: var(--text); }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto;
  padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand.small { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand.small .brand-logo { width: 34px; height: 34px; font-size: 18px; border-radius: 9px; margin: 0; }
.user-area { display: flex; align-items: center; gap: 12px; }
.user-info { display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; background: #e5e7eb; }
.user-text { display: flex; flex-direction: column; line-height: 1.2; }
.user-text strong { font-size: 14px; }

/* ---------- Container & stats ---------- */
.container { max-width: 1080px; margin: 0 auto; padding: 24px 20px 60px; }
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: 13px; color: var(--muted); }
.stat-card .stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-chip {
  font: inherit; font-size: 13px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
}
.filter-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.filter-chip .count { opacity: 0.7; margin-left: 4px; }
.toolbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.select {
  font: inherit; font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

/* ---------- File list ---------- */
.file-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.file-row {
  display: grid;
  grid-template-columns: 40px 1fr auto auto auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.file-row:last-child { border-bottom: none; }
.file-row:hover { background: #fafbfc; }
.file-row .check { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.file-type-icon {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  border-radius: 9px;
  background: #eef2ff; color: var(--accent);
}
.file-type-icon.video { background: #fef3c7; color: #b45309; }
.file-type-icon.audio { background: #dcfce7; color: #15803d; }
.file-type-icon.doc { background: #fee2e2; color: #b91c1c; }
.file-name { font-weight: 500; word-break: break-all; }
.file-meta { display: flex; gap: 14px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.file-actions { display: flex; gap: 6px; }
.file-actions .icon-btn { font-size: 15px; }
.row-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

.empty {
  text-align: center; color: var(--muted);
  padding: 40px; background: var(--surface);
  border: 1px dashed var(--border); border-radius: var(--radius);
}
.error { color: var(--danger); font-size: 14px; margin-top: 12px; text-align: center; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: 14px;
  max-width: 860px; width: 100%;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.modal.small { max-width: 420px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-weight: 600; font-size: 15px; word-break: break-all; }
.modal-body { padding: 18px; overflow: auto; min-height: 60px; }
.modal-body img, .modal-body video { width: 100%; max-height: 60vh; border-radius: 8px; display: block; }
.modal-body .preview-info { font-size: 13px; color: var(--muted); }
.preview-meta {
  padding: 0 18px 14px;
  border-bottom: 1px solid var(--border);
}
.meta-row {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 4px 0; font-size: 13px;
}
.meta-label { color: var(--muted); white-space: nowrap; }
.meta-value { text-align: right; word-break: break-all; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 18px; border-top: 1px solid var(--border);
}
.doc-preview { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }

/* ---------- Segment buttons (group & view) ---------- */
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.seg-btn {
  font: inherit; font-size: 13px;
  border: none; background: transparent;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--muted);
  border-left: 1px solid var(--border);
}
.seg-btn:first-child { border-left: none; }
.seg-btn.active { background: var(--accent); color: #fff; }
.seg-btn:hover:not(.active) { background: #f0f1f3; }

/* ---------- Grid views ---------- */
.file-list.view-grid-sm, .file-list.view-grid-lg {
  padding: 14px;
  display: grid;
  gap: 12px;
}
.file-list.view-grid-sm { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.file-list.view-grid-lg { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.grid-item {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  display: flex; flex-direction: column;
  transition: box-shadow 0.15s;
}
.grid-item:hover { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); }
.grid-item .check {
  position: absolute; top: 8px; left: 8px;
  width: 18px; height: 18px;
  accent-color: var(--accent);
  cursor: pointer; z-index: 2;
}
.grid-thumb {
  width: 100%;
  aspect-ratio: 1;
  cursor: pointer;
  background: #eef2ff;
  display: flex; align-items: center; justify-content: center;
}
.grid-media {
  width: 100%; height: 100%;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}
.grid-thumb-img { background-image: none; background-color: #e5e7eb; }
.grid-media.audio { font-size: 40px; color: var(--muted); }
.grid-name {
  font-size: 13px; font-weight: 500;
  padding: 8px 10px 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.grid-meta { font-size: 12px; color: var(--muted); padding: 0 10px 8px; }

/* ---------- Folder grouping ---------- */
.folder-section {
  border-bottom: 1px solid var(--border);
}
.folder-section:last-child { border-bottom: none; }
.folder-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  cursor: default;
}
.folder-chevron { color: var(--muted); font-size: 14px; }
.folder-name { font-weight: 600; }
.folder-count { margin-left: auto; font-size: 13px; color: var(--muted); }
.folder-body { padding: 0; }
.folder-body.folder-list .file-row:last-child { border-bottom: none; }
.folder-body.folder-grid {
  padding: 14px;
  display: grid;
  gap: 12px;
}
.folder-body.folder-grid.grid-sm { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.folder-body.folder-grid.grid-lg { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

/* Responsive */
@media (max-width: 640px) {
  .file-row {
    grid-template-columns: 32px 1fr auto;
    grid-template-areas:
      "check name actions"
      "check meta actions";
  }
  .file-row .check { grid-area: check; }
  .file-row .file-name-wrap { grid-area: name; }
  .file-row .file-actions { grid-area: actions; align-self: center; }
  .file-row .row-label { display: none; }
  .file-row .file-meta { grid-area: meta; }
  .toolbar { flex-direction: column; align-items: stretch; }
}
