:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel2: #1e242d;
  --border: #2a313c;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --green: #22c55e;
  --warn: #f59e0b;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button {
  background: var(--accent); color: white; border: none;
  padding: 8px 14px; border-radius: var(--radius); cursor: pointer;
  font-size: 13px; font-weight: 500;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.ghost:hover { background: var(--panel2); }
button.danger { background: var(--danger); }
button.danger:hover { background: #dc2626; }
input, select, textarea {
  background: var(--panel2); color: var(--text); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: var(--radius); font-size: 13px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
.row { display: flex; gap: 12px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 8px; }

/* Layout */
.app-layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 16px; }
.sidebar h1 { font-size: 18px; margin: 0 0 24px 0; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  padding: 8px 12px; border-radius: var(--radius); color: var(--text);
  font-weight: 500;
}
.sidebar nav a:hover { background: var(--panel2); text-decoration: none; }
.sidebar nav a.active { background: var(--accent); color: white; }
.sidebar .user-info {
  position: absolute; bottom: 16px; left: 16px; right: calc(100% - 220px + 16px);
  width: 188px;
  border-top: 1px solid var(--border); padding-top: 12px;
}
.sidebar .user-info .email { font-size: 12px; color: var(--muted); }
.sidebar .user-info .role { font-size: 11px; background: var(--accent); padding: 2px 6px; border-radius: 4px; display: inline-block; margin-top: 4px; }
.main { padding: 24px 32px; overflow-x: auto; }
.main h2 { margin: 0 0 16px 0; font-size: 22px; }
.toolbar { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.toolbar input { width: 260px; }

/* Login */
.login-screen {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: var(--bg);
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 32px; width: 360px;
}
.login-card h1 { margin: 0 0 8px 0; font-size: 22px; }
.login-card .sub { color: var(--muted); margin-bottom: 24px; font-size: 13px; }
.login-card .col { gap: 12px; }
.error-msg { background: rgba(239, 68, 68, 0.15); color: #fca5a5; padding: 10px; border-radius: var(--radius); font-size: 13px; }
.success-msg { background: rgba(34, 197, 94, 0.15); color: #86efac; padding: 10px; border-radius: var(--radius); font-size: 13px; }

/* Table */
table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
th { background: var(--panel2); font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--panel2); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.pill.admin { background: rgba(245, 158, 11, 0.2); color: var(--warn); }
.pill.user  { background: rgba(139, 148, 158, 0.2); color: var(--muted); }
.pill.public { background: rgba(34, 197, 94, 0.2); color: var(--green); }
.pill.private { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
.pill.disabled { background: rgba(239, 68, 68, 0.2); color: var(--danger); }

/* Asset grid */
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }
.asset-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  cursor: pointer; transition: transform 0.1s, border-color 0.1s;
}
.asset-card:hover { border-color: var(--accent); }
.asset-card .thumb {
  background: var(--panel2); aspect-ratio: 1/1; display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.asset-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.asset-card .thumb .file-icon { font-size: 32px; color: var(--muted); }
.asset-card .meta { padding: 8px 10px; }
.asset-card .meta .name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asset-card .meta .sub { font-size: 11px; color: var(--muted); }

/* Library: folder tree sidebar */
.library-shell { display: grid; grid-template-columns: 240px 1fr; gap: 20px; align-items: start; }
@media (max-width: 880px) { .library-shell { grid-template-columns: 1fr; } }

.library-sidebar {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto;
}
.library-sidebar-head {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
  padding: 14px 16px 6px; font-weight: 600;
}
.folder-tree { padding: 4px 0 8px; }
.folder-row {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px 6px 0;
  cursor: pointer; font-size: 13px; user-select: none; line-height: 1.2;
}
.folder-row:hover { background: var(--panel2); }
.folder-row.active { background: var(--accent); color: white; }
.folder-row.active .folder-count { background: rgba(255,255,255,0.25); color: white; }
.caret { display: inline-block; width: 14px; text-align: center; color: var(--muted); font-size: 10px; flex: 0 0 14px; }
.caret-blank { visibility: hidden; }
.folder-icon { font-size: 13px; flex: 0 0 14px; }
.folder-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-count {
  background: var(--panel2); color: var(--muted); padding: 1px 7px;
  border-radius: 10px; font-size: 11px; font-weight: 600; min-width: 22px; text-align: center;
}

/* Folder-tree skeleton bars while data loads */
.folder-name.skel {
  display: inline-block; height: 12px; width: 140px; border-radius: 4px;
  background: linear-gradient(90deg, var(--panel2) 0%, #2e3744 50%, var(--panel2) 100%);
  background-size: 200% 100%; animation: skel-shimmer 1.4s linear infinite;
}
@keyframes skel-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.library-main { min-width: 0; }
.library-head { display: flex; align-items: baseline; gap: 18px; margin-bottom: 14px; flex-wrap: wrap; }
.library-head h2 { margin: 0; }
.breadcrumb { color: var(--muted); font-size: 13px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--accent); text-decoration: none; }
.breadcrumb .bc-sep { margin: 0 6px; color: var(--border); }
.breadcrumb .bc-cur { color: var(--text); font-weight: 600; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 24px;
  max-width: 720px; width: 90%; max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 16px 0; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.stat-card .value { font-size: 24px; font-weight: 700; margin-top: 4px; }

.kbd { font-family: ui-monospace, "JetBrains Mono", Menlo, monospace; background: var(--panel2); padding: 2px 6px; border-radius: 4px; font-size: 12px; border: 1px solid var(--border); }
.code-block {
  background: #0a0d12; border: 1px solid var(--border); padding: 12px;
  border-radius: var(--radius); font-family: ui-monospace, Menlo, monospace; font-size: 12px;
  white-space: pre-wrap; word-break: break-all; color: #d1d5db;
}
.code-block.scroll { overflow-x: auto; white-space: pre; }
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 32px;
  text-align: center; color: var(--muted); cursor: pointer; transition: border-color 0.1s, background 0.1s;
}
.upload-zone.drag { border-color: var(--accent); background: rgba(59, 130, 246, 0.05); }
.upload-zone:hover { border-color: var(--accent); }
.empty { text-align: center; padding: 48px; color: var(--muted); }
.spacer-1 { height: 8px; } .spacer-2 { height: 16px; } .spacer-3 { height: 24px; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.detail-grid .preview { background: var(--panel2); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; min-height: 240px; }
.detail-grid .preview img { max-width: 100%; max-height: 480px; }
.detail-grid dl { margin: 0; }
.detail-grid dt { color: var(--muted); font-size: 12px; text-transform: uppercase; margin-top: 12px; }
.detail-grid dd { margin: 4px 0 0 0; font-family: ui-monospace, Menlo, monospace; font-size: 13px; word-break: break-all; }
