: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;
  position: relative;
}
.asset-card:hover { border-color: var(--accent); }
.asset-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.asset-check {
  position: absolute; top: 6px; left: 6px; z-index: 2;
  width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55); border-radius: 4px; cursor: pointer;
}
.asset-check input[type="checkbox"] { width: 16px; height: 16px; margin: 0; cursor: pointer; }

/* Bulk action bar between toolbar and grid */
.bulk-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 12px; margin-bottom: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
}
.bulk-selectall { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.bulk-selectall input { width: 16px; height: 16px; }
.bulk-count { color: var(--muted); font-size: 13px; }
.bulk-bar button { margin-left: 0; }
.bulk-bar button.danger {
  margin-left: auto;
  background: #dc2626; color: white; border-color: #b91c1c;
}
.bulk-bar button.danger:disabled { background: #4b1818; color: #999; cursor: not-allowed; }
.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 .thumb { position: relative; }
.asset-card .thumb-pdf img { object-fit: contain; background: white; }
.asset-card .thumb-tag {
  position: absolute; top: 6px; right: 6px;
  background: rgba(220, 38, 38, 0.92); color: white;
  padding: 1px 6px; border-radius: 4px; font-size: 10px; font-weight: 700; letter-spacing: 0.04em;
}
.asset-card .file-badge {
  display: flex; align-items: center; justify-content: center;
  width: 64px; height: 64px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--border); color: var(--muted);
  font-weight: 700; font-size: 14px; letter-spacing: 0.04em;
}
.pdf-frame { width: 100%; height: 100%; min-height: 480px; border: 0; border-radius: var(--radius); background: white; }
.file-badge-lg {
  width: 120px; height: 120px; border-radius: 12px;
  font-size: 22px;
  background: var(--panel); border: 1px solid var(--border); color: var(--muted);
  display: flex; align-items: center; justify-content: center; font-weight: 700; letter-spacing: 0.05em;
}
.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;
  display: flex; align-items: center; justify-content: space-between;
}
.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;
}

/* Inline folder actions (rename / delete) — revealed on row hover */
.folder-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; flex: 0 0 auto; }
.folder-row:hover .folder-actions { opacity: 1; }
.fa-btn {
  background: transparent; border: 0; color: var(--muted); cursor: pointer;
  font-size: 12px; line-height: 1; padding: 2px 4px; border-radius: 4px;
}
.fa-btn:hover { background: var(--panel2); color: var(--text); }
.fa-btn.fa-del:hover { background: #7f1d1d; color: #fff; }
.folder-row.active .fa-btn { color: rgba(255,255,255,0.85); }
.folder-row.active .fa-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }

/* 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; }

/* Billing — hero card */
.billing-hero {
  display: flex; justify-content: space-between; align-items: center; gap: 24px;
  background: linear-gradient(135deg, #1e2f6e 0%, #3b4ec9 100%);
  color: white; padding: 28px 32px; border-radius: 14px; margin-bottom: 24px;
  box-shadow: 0 12px 32px -8px rgba(67,56,202,0.4);
}
.billing-hero.billing-hero-empty {
  background: linear-gradient(135deg, var(--panel) 0%, var(--panel2) 100%);
  color: var(--text); border: 1px solid var(--border); box-shadow: none;
}
.billing-hero-eyebrow {
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  font-weight: 700; opacity: 0.85; margin-bottom: 8px;
}
.billing-hero h3 { margin: 0 0 4px; font-size: 28px; letter-spacing: -0.01em; }
.billing-hero p  { margin: 6px 0 0; opacity: 0.9; font-size: 14px; }
.billing-state {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.billing-state.ok   { background: rgba(34,197,94,0.2);  color: #86efac; }
.billing-state.warn { background: rgba(245,158,11,0.2); color: #fcd34d; }
.billing-hero-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.btn-brand-lg {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 20px; border-radius: 10px; font-weight: 700; font-size: 14px;
  background: white; color: var(--ink, #0b1220); border: 0; cursor: pointer;
}
.btn-brand-lg:hover { background: rgba(255,255,255,0.92); }
.billing-hero.billing-hero-empty .btn-brand-lg {
  background: var(--accent); color: white;
}
.btn-ghost-lg {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; font-weight: 600; font-size: 13px;
  background: rgba(255,255,255,0.12); color: white; border: 1px solid rgba(255,255,255,0.2);
  cursor: pointer;
}
.btn-ghost-lg:hover { background: rgba(255,255,255,0.2); }
.billing-hero.billing-hero-empty .btn-ghost-lg {
  background: transparent; color: var(--text); border: 1px solid var(--border);
}

/* Billing — generic card wrapper */
.billing-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; margin-top: 24px;
}
.billing-card-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.billing-card-head h4 { margin: 0; font-size: 14px; font-weight: 600; }
.muted-sm { color: var(--muted); font-size: 12px; }

/* Billing — monthly chart */
.chart-bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 8px; padding: 24px 22px; align-items: end; height: 220px; }
.chart-bar { display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; }
.chart-bar-track { width: 100%; height: 170px; display: flex; align-items: flex-end; }
.chart-bar-fill {
  width: 100%; min-height: 2px;
  background: linear-gradient(180deg, var(--accent) 0%, #6366f1 100%);
  border-radius: 4px 4px 0 0; transition: filter 0.15s;
}
.chart-bar-fill:hover { filter: brightness(1.15); cursor: help; }
.chart-bar-fill.empty { background: var(--panel2); opacity: 0.5; }
.chart-bar-label { font-size: 11px; color: var(--muted); }

/* Billing — invoice table */
.invoice-table { width: 100%; border-collapse: collapse; }
.invoice-table th, .invoice-table td { padding: 12px 22px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
.invoice-table th { background: var(--panel2); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; }
.invoice-table tr:last-child td { border-bottom: 0; }
.invoice-table td.mono { font-family: ui-monospace, "JetBrains Mono", Menlo, monospace; font-size: 12px; }
.invoice-table td.num  { text-align: right; font-variant-numeric: tabular-nums; }
.invoice-table .actions-cell { text-align: right; }
.invoice-status {
  display: inline-flex; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.invoice-status-paid       { background: rgba(34,197,94,0.18);  color: #86efac; }
.invoice-status-open       { background: rgba(245,158,11,0.18); color: #fcd34d; }
.invoice-status-void       { background: rgba(139,148,158,0.2); color: var(--muted); }
.invoice-status-draft      { background: rgba(139,148,158,0.2); color: var(--muted); }
.invoice-status-uncollectible { background: rgba(239,68,68,0.18); color: #fca5a5; }
.link-btn {
  display: inline-block; padding: 4px 10px; border-radius: 6px;
  font-size: 12px; font-weight: 600; color: var(--accent); text-decoration: none;
  border: 1px solid var(--border); background: var(--panel2); margin-left: 4px;
}
.link-btn:hover { background: var(--accent); color: white; text-decoration: none; }

/* Billing — details key-value */
.billing-details { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 24px; padding: 22px; }
.kv .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; margin-bottom: 4px; }
.kv .v { font-size: 14px; color: var(--text); }
.kv .v.mono { font-family: ui-monospace, "JetBrains Mono", Menlo, monospace; font-size: 13px; }

.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; }
