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

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-hover: #242836;
  --bg-input: #1a1d27;
  --border: #2a2e3a;
  --text: #e4e6eb;
  --text-muted: #8b8fa3;
  --accent: #4f8ff7;
  --accent-hover: #3a7ae0;
  --danger: #e74c3c;
  --success: #27ae60;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* === Header === */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

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

.user-badge {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.25rem 0.6rem;
  background: var(--bg);
  border-radius: var(--radius);
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { background: var(--bg-hover); color: var(--text); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-full { width: 100%; justify-content: center; }
.btn-outline { background: transparent; }

/* === Container === */
main { padding: 1.5rem; }
.container { max-width: 1100px; margin: 0 auto; }

/* === Login === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 2.5rem 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.login-card h1 {
  font-size: 1.5rem;
  text-align: center;
  margin-bottom: 0.25rem;
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}
.form-group input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}
.form-group input:focus { border-color: var(--accent); }

.alert { padding: 0.6rem 0.8rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.85rem; }
.alert-error { background: rgba(231,76,60,0.15); border: 1px solid rgba(231,76,60,0.3); color: #e74c3c; }

/* === Projects Grid === */
h2 { font-size: 1.3rem; margin-bottom: 1rem; font-weight: 600; }

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.project-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 1.25rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all 0.15s;
  color: var(--text);
  text-align: center;
}
.project-card:hover { background: var(--bg-hover); border-color: var(--accent); color: var(--text); }

.project-icon { font-size: 2rem; }
.project-name { font-size: 0.9rem; font-weight: 500; word-break: break-all; }

.badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  font-weight: 500;
}
.badge-live { background: rgba(39,174,96,0.2); color: var(--success); }

/* === Breadcrumbs === */
.breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.breadcrumbs .sep { color: var(--text-muted); }
.breadcrumbs .current { color: var(--text); font-weight: 500; }

/* === Preview Bar === */
.preview-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.preview-info { display: flex; align-items: center; gap: 0.75rem; font-size: 0.85rem; color: var(--text-muted); }

.preview-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-family: var(--font);
}

.toggle-track {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--border);
  border-radius: 11px;
  transition: background 0.2s;
}

.preview-toggle.active .toggle-track { background: var(--success); }

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.preview-toggle.active .toggle-thumb { transform: translateX(18px); }
.toggle-label { user-select: none; }

/* === File List === */
.file-list table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.file-list thead th {
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
}

.file-list tbody tr { border-bottom: 1px solid var(--border); }
.file-list tbody tr:last-child { border-bottom: none; }
.file-list tbody tr:hover { background: var(--bg-hover); }

.file-list td {
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}

.icon-col { width: 30px; text-align: center; }
.size-col { width: 80px; color: var(--text-muted); font-size: 0.8rem; text-align: right; }
.action-col { width: 60px; text-align: right; }

.hint {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  background: rgba(79,143,247,0.15);
  color: var(--accent);
  border-radius: 4px;
}

.empty { text-align: center; color: var(--text-muted); padding: 2rem !important; }

/* === File View === */
.file-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.file-header h3 { font-size: 1.1rem; font-weight: 600; }

.file-content { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

.markdown-body {
  padding: 1.5rem;
  line-height: 1.7;
}
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 1rem 0 0.5rem; }
.markdown-body p { margin-bottom: 0.75rem; }
.markdown-body ul, .markdown-body ol { margin-left: 1.5rem; margin-bottom: 0.75rem; }
.markdown-body code {
  background: var(--bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.85em;
}
.markdown-body pre {
  background: var(--bg);
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin-bottom: 0.75rem;
}
.markdown-body pre code { padding: 0; background: none; }
.markdown-body img { max-width: 100%; border-radius: var(--radius); }
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.75rem;
}
.markdown-body th, .markdown-body td {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  text-align: left;
}

.image-preview { padding: 1.5rem; text-align: center; }
.image-preview img { max-width: 100%; max-height: 80vh; border-radius: var(--radius); }

.code-block { overflow-x: auto; }
.code-block pre {
  padding: 1rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre;
  tab-size: 2;
}

.html-actions { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }

.table-wrapper { overflow-x: auto; }
.csv-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.csv-table th {
  padding: 0.5rem 0.6rem;
  background: var(--bg);
  font-weight: 600;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.csv-table td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.csv-table tr:hover td { background: var(--bg-hover); }

.download-prompt { padding: 3rem; text-align: center; }
.download-prompt p { margin-bottom: 1rem; color: var(--text-muted); }

/* === Responsive === */
@media (max-width: 600px) {
  main { padding: 1rem; }
  .project-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .preview-bar { flex-direction: column; align-items: flex-start; }
  header { padding: 0.5rem 1rem; }
}
