*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg2: #161b27;
  --bg3: #1e2535;
  --bg4: #252d3d;
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);
  --text: #e8ecf0;
  --text2: #8b96a8;
  --text3: #5a6478;
  --accent: #6366f1;
  --accent-dim: rgba(99,102,241,0.15);
  --accent-hover: #7c7fff;
  --danger: #ef4444;
  --danger-dim: rgba(239,68,68,0.12);
  --success: #22c55e;
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-width: 240px;
  --detail-width: 480px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

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

.hidden { display: none !important; }

/* ── AUTH ─────────────────────────────────────────── */
.auth-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.auth-box {
  width: 100%; max-width: 360px;
  padding: 2.5rem 2rem;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
}
.auth-logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 20px; font-weight: 600; margin-bottom: 6px;
}
.auth-sub { color: var(--text2); margin-bottom: 2rem; font-size: 13px; }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-error { color: #f87171; font-size: 12px; min-height: 16px; }
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 11px 16px;
  background: var(--bg3); border: 1px solid var(--border2);
  color: var(--text); border-radius: var(--radius);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-google:hover { background: var(--bg4); border-color: var(--border2); }

/* ── BUTTONS ──────────────────────────────────────── */
.btn-primary {
  background: var(--accent); color: white; border: none;
  padding: 10px 18px; border-radius: var(--radius);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost {
  background: transparent; color: var(--text2);
  border: 1px solid var(--border2); padding: 10px 18px;
  border-radius: var(--radius); font-size: 14px; cursor: pointer;
  transition: background 0.15s;
}
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.btn-icon {
  background: transparent; border: none; color: var(--text2);
  width: 32px; height: 32px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg4); color: var(--text); }
.btn-icon.btn-danger:hover { color: var(--danger); background: var(--danger-dim); }

/* ── APP LAYOUT ───────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── SIDEBAR ──────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width); flex-shrink: 0;
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform 0.2s ease;
  height: 100vh; overflow-y: auto;
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-width))); position: absolute; z-index: 100; }

.sidebar-header {
  padding: 16px 14px 12px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 600;
}
.sidebar-search {
  margin: 10px 12px;
  position: relative; display: flex; align-items: center;
}
.sidebar-search svg {
  position: absolute; left: 10px; color: var(--text3); pointer-events: none;
}
.sidebar-search input {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius);
  padding: 7px 10px 7px 30px; font-size: 13px;
}
.sidebar-search input:focus { outline: none; border-color: var(--accent); }
.sidebar-section-title {
  padding: 10px 16px 6px;
  font-size: 11px; font-weight: 600; color: var(--text3);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.categories-list { padding: 0 8px; flex: 1; }
.cat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: var(--radius);
  cursor: pointer; color: var(--text2); font-size: 13px;
  transition: background 0.12s, color 0.12s;
  user-select: none;
}
.cat-item:hover { background: var(--bg4); color: var(--text); }
.cat-item.active { background: var(--accent-dim); color: var(--accent-hover); }
.cat-count {
  margin-left: auto; font-size: 11px; background: var(--bg4);
  color: var(--text3); padding: 1px 6px; border-radius: 10px;
}
.cat-item.active .cat-count { background: var(--accent-dim); color: var(--accent); }

.sidebar-bottom {
  padding: 12px; border-top: 1px solid var(--border); margin-top: auto;
}
.btn-logout {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: transparent;
  border: none; color: var(--text3); cursor: pointer;
  border-radius: var(--radius); font-size: 13px;
  transition: color 0.12s, background 0.12s;
}
.btn-logout:hover { color: var(--danger); background: var(--danger-dim); }

/* ── MAIN ─────────────────────────────────────────── */
.main {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column;
  min-width: 0;
}
.main-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
.main-header h1 { font-size: 16px; font-weight: 600; flex: 1; }
.main-header-right { display: flex; align-items: center; gap: 8px; }
.sort-select {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text2); padding: 6px 10px; border-radius: var(--radius);
  font-size: 13px; cursor: pointer;
}
.sort-select:focus { outline: none; }
.sidebar-toggle { display: none; }

.snippets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px; padding: 20px;
  align-content: start;
}

/* ── SNIPPET CARD ─────────────────────────────────── */
.snippet-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px;
  cursor: pointer; transition: border-color 0.15s, transform 0.1s;
  display: flex; flex-direction: column; gap: 10px;
}
.snippet-card:hover { border-color: var(--border2); transform: translateY(-1px); }
.snippet-card.active { border-color: var(--accent); }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-name { font-size: 14px; font-weight: 500; line-height: 1.3; }
.card-badge {
  font-size: 10px; font-weight: 600; padding: 2px 8px;
  border-radius: 20px; white-space: nowrap; flex-shrink: 0;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.card-desc { font-size: 12px; color: var(--text2); line-height: 1.5; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card-bottom { display: flex; align-items: center; justify-content: space-between; margin-top: auto; }
.card-files { font-size: 11px; color: var(--text3); }
.card-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag {
  font-size: 10px; padding: 2px 7px; background: var(--bg4);
  color: var(--text3); border-radius: 20px;
}

/* ── EMPTY STATE ──────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; padding: 80px 20px;
  color: var(--text3); text-align: center;
}
.empty-state p { font-size: 15px; }

/* ── DETAIL PANEL ─────────────────────────────────── */
.detail-panel {
  width: var(--detail-width); flex-shrink: 0;
  background: var(--bg2); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100vh; overflow-y: auto;
}
.detail-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg2); z-index: 5;
}
.detail-actions { display: flex; align-items: center; gap: 4px; }
.detail-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.detail-title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.detail-title-row h2 { font-size: 18px; font-weight: 600; }
.detail-description { color: var(--text2); font-size: 13px; line-height: 1.6; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 6px; }

/* ── BADGE ────────────────────────────────────────── */
.badge {
  font-size: 11px; font-weight: 600; padding: 3px 10px;
  border-radius: 20px; text-transform: uppercase; letter-spacing: 0.04em;
}

/* ── FILES SECTION ────────────────────────────────── */
.files-section { display: flex; flex-direction: column; gap: 0; }
.files-tabs {
  display: flex; gap: 2px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.file-tab {
  padding: 6px 14px; font-size: 12px; font-family: var(--font-mono);
  cursor: pointer; color: var(--text3); border-radius: 6px 6px 0 0;
  transition: color 0.12s, background 0.12s;
  border: 1px solid transparent; border-bottom: none;
  background: transparent; user-select: none;
}
.file-tab:hover { color: var(--text2); }
.file-tab.active {
  color: var(--text); background: var(--bg3);
  border-color: var(--border);
  margin-bottom: -1px;
}
.file-content-wrap {
  background: var(--bg3); border: 1px solid var(--border);
  border-top: none; border-radius: 0 0 var(--radius) var(--radius);
}
.file-content-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-bottom: 1px solid var(--border);
}
.filename { font-family: var(--font-mono); font-size: 12px; color: var(--text2); }
.btn-copy-file {
  display: flex; align-items: center; gap: 5px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text3); padding: 4px 10px; border-radius: 6px;
  font-size: 11px; cursor: pointer; transition: all 0.12s;
}
.btn-copy-file:hover { border-color: var(--border2); color: var(--text); }
.btn-copy-file.copied { color: var(--success); border-color: var(--success); }

#file-code-block {
  margin: 0; overflow-x: auto; max-height: 400px;
  background: transparent !important;
}
#file-code-block code {
  font-family: var(--font-mono) !important;
  font-size: 12px !important; line-height: 1.6;
  padding: 14px !important;
  background: transparent !important;
  white-space: pre;
}

/* ── USAGE SECTION ────────────────────────────────── */
.usage-section { display: flex; flex-direction: column; gap: 8px; }
.usage-section h3 { font-size: 13px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.06em; }
.usage-content {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  font-size: 13px; color: var(--text2); line-height: 1.7;
  white-space: pre-wrap;
}

/* ── MODAL ────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal {
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--radius-lg); width: 100%; max-width: 680px;
  max-height: 90vh; display: flex; flex-direction: column;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-footer {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 12px; font-weight: 500; color: var(--text2); }
.form-group input, .form-group textarea, .form-group select {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius);
  padding: 9px 12px; font-size: 13px; font-family: var(--font);
  transition: border-color 0.15s; resize: vertical;
}
.form-group input:focus, .form-group textarea:focus { outline: none; border-color: var(--accent); }

.files-label-row { display: flex; align-items: center; justify-content: space-between; }
.btn-add-file {
  display: flex; align-items: center; gap: 5px;
  background: var(--accent-dim); color: var(--accent-hover);
  border: 1px solid rgba(99,102,241,0.2); padding: 5px 12px;
  border-radius: var(--radius); font-size: 12px; cursor: pointer;
  transition: background 0.12s;
}
.btn-add-file:hover { background: rgba(99,102,241,0.25); }

#files-form-list { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.file-form-item {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.file-form-header {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.file-form-header input {
  flex: 1; background: transparent; border: none;
  color: var(--text); font-family: var(--font-mono); font-size: 12px;
  padding: 2px 4px;
}
.file-form-header input:focus { outline: none; }
.file-form-header select {
  background: var(--bg4); border: 1px solid var(--border);
  color: var(--text2); padding: 3px 6px; border-radius: 4px; font-size: 11px;
}
.file-form-header select:focus { outline: none; }
.btn-remove-file {
  background: transparent; border: none; color: var(--text3);
  cursor: pointer; width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; transition: color 0.12s;
}
.btn-remove-file:hover { color: var(--danger); }
.file-form-code {
  width: 100%; background: transparent; border: none;
  color: var(--text); font-family: var(--font-mono); font-size: 12px;
  padding: 10px 12px; resize: vertical; min-height: 120px; line-height: 1.6;
}
.file-form-code:focus { outline: none; }

/* ── TOAST ────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg4); border: 1px solid var(--border2);
  color: var(--text); padding: 10px 20px; border-radius: 30px;
  font-size: 13px; z-index: 9999; white-space: nowrap;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ── CATEGORY COLORS ──────────────────────────────── */
.cat-android { background: rgba(61,220,132,0.12); color: #3ddc84; }
.cat-flutter { background: rgba(84,182,255,0.12); color: #54b6ff; }
.cat-web { background: rgba(255,167,38,0.12); color: #ffa726; }
.cat-ios { background: rgba(255,95,95,0.12); color: #ff5f5f; }
.cat-react { background: rgba(97,218,251,0.12); color: #61dafb; }
.cat-default { background: var(--accent-dim); color: var(--accent-hover); }

/* ── RESPONSIVE ───────────────────────────────────── */
@media (max-width: 1100px) {
  .detail-panel { width: 420px; }
}
@media (max-width: 900px) {
  .sidebar { position: absolute; z-index: 100; height: 100%; }
  .sidebar.collapsed { display: none; }
  .sidebar-toggle { display: flex; }
  .detail-panel { position: absolute; right: 0; top: 0; height: 100%; width: 100%; max-width: 520px; z-index: 50; }
  .snippets-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}
@media (max-width: 500px) {
  .form-row { grid-template-columns: 1fr; }
  .modal { max-height: 100vh; border-radius: 0; }
}

/* ── SCROLLBAR ────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }
