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

:root {
  --bg: #f6f7f9;
  --sidebar-bg: #111318;
  --sidebar-text: #8b8fa8;
  --sidebar-active: #fff;
  --sidebar-hover: #1e2128;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --card-bg: #fff;
  --border: #e8eaee;
  --text: #111318;
  --text-muted: #6b7280;
  --radius: 10px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===== LOGIN ===== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1d23 0%, #2d3748 100%);
}

.login-container {
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 40px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-card h1 {
  text-align: center;
  font-size: 24px;
  color: var(--sidebar-bg);
  margin-bottom: 4px;
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

.login-form .form-group { margin-bottom: 18px; }
.login-form label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.login-form input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  transition: border-color 0.2s;
}
.login-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.15); }

/* ===== PUBLIC FRONT ===== */
.public-page {
  background: #f8f9fb;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.public-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.public-header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.public-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sidebar-bg);
}

.public-logo h1 {
  font-size: 20px;
  font-weight: 700;
}

.public-admin-link {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all 0.15s;
}

.public-admin-link:hover { color: var(--primary); border-color: var(--primary); }

.public-main {
  flex: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 20px 60px;
  width: 100%;
}

.public-empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.public-empty svg { margin-bottom: 16px; color: #d1d5db; }
.public-empty h2 { font-size: 20px; margin-bottom: 6px; color: var(--text); }

/* sections */
.audio-section { margin-bottom: 40px; }

.section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
  display: inline-block;
}

.audio-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 600px) {
  .audio-grid { grid-template-columns: 1fr 1fr; }
}

.audio-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  transition: box-shadow 0.15s;
}

.audio-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }

.audio-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #ede9fe;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.audio-card-body { flex: 1; min-width: 0; }

.audio-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.audio-card-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.audio-card-player { width: 100%; height: 32px; }

.public-footer {
  text-align: center;
  padding: 20px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ===== ADMIN LAYOUT ===== */
.admin-page {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 22px 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand h2 {
  font-size: 15px;
  color: #fff;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  margin: 1px 8px;
  border-radius: 7px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s;
}

.nav-item:hover { background: var(--sidebar-hover); color: #e5e7eb; }
.nav-item.active { background: rgba(79,70,229,0.18); color: #fff; }

.nav-icon { width: 20px; height: 20px; flex-shrink: 0; }

.sidebar-divider {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.08);
  margin: 8px 16px;
}

.nav-logout { margin-top: auto; color: #f87171; }
.nav-logout:hover { color: #fca5a5; }

/* ===== MAIN ===== */
.main-content {
  flex: 1;
  margin-left: 240px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: #fff;
  padding: 13px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.topbar-left { font-size: 14px; font-weight: 600; color: var(--text-muted); letter-spacing: 0.01em; }
.topbar-user {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg);
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.content { padding: 32px; flex: 1; }

.content h2 { font-size: 22px; margin-bottom: 6px; }

/* ===== CARDS & STATS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  gap: 16px;
  align-items: center;
}

.stat-icon { width: 36px; height: 36px; flex-shrink: 0; color: var(--primary); }
.stat-icon svg { width: 100%; height: 100%; }
.stat-label { font-size: 14px; color: var(--text-muted); margin-bottom: 4px; }
.stat-link a { font-size: 13px; color: var(--primary); text-decoration: none; font-weight: 500; }
.stat-link a:hover { text-decoration: underline; }

.form-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 480px;
  margin-top: 16px;
}

/* ===== TABLE ===== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

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

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table th {
  background: #f9fafb;
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f9fafb; }

.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-admin { background: #ede9fe; color: #6d28d9; }
.badge-editor { background: #dbeafe; color: #2563eb; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
}

.btn:hover { opacity: 0.9; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-outline { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: #f3f4f6; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-block { width: 100%; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.form-group input,
.form-group select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: #fff;
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}

/* ===== ALERTS ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
}
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

/* ===== CATEGORIES ===== */
.cat-edit-form { display: flex; gap: 6px; align-items: center; }
.cat-edit-input { padding: 5px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; width: 180px; }
.cat-edit-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.12); }

.form-hint { display: block; font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-hint a { color: var(--primary); text-decoration: none; }
.form-hint a:hover { text-decoration: underline; }

/* ===== MODAL ===== */
.modal { display: none; }
.modal.active { display: block; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
}

.modal-content {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 12px;
  padding: 28px;
  width: 90%;
  max-width: 440px;
  z-index: 201;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h3 { font-size: 18px; }

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

/* ===== AUDIOS ===== */
.audio-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.audio-row audio { height: 32px; max-width: 200px; }
.audio-filename { font-size: 12px; color: var(--text-muted); word-break: break-all; }

.badge-category {
  background: #e0e7ff;
  color: #3730a3;
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.file-upload-area {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.file-upload-area:hover { border-color: var(--primary); background: #f5f3ff; }

.file-upload-area input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-upload-text { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--text-muted); font-size: 13px; }
.file-upload-text svg { color: var(--primary); }
.file-hint { font-size: 11px; color: #9ca3af; }

.file-upload-area.has-file { border-color: var(--primary); border-style: solid; background: #f5f3ff; padding: 12px; }

.file-preview { width: 100%; }

.file-info-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

.file-info-icon { color: var(--primary); flex-shrink: 0; }

.file-info-details { flex: 1; min-width: 0; }

.file-info-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-info-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.file-info-remove {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}
.file-info-remove:hover { color: var(--danger); }

.file-audio-preview audio { border-radius: var(--radius); }

/* spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.btn-loading { opacity: 0.7; cursor: not-allowed; pointer-events: none; }

/* ===== DASHBOARD ===== */
.dash-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
}

.dash-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: 4px;
}

.dash-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 400;
}

.dash-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 32px;
}

@media (max-width: 900px) {
  .dash-stats { grid-template-columns: repeat(2, 1fr); }
}

.dash-stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: box-shadow 0.15s;
}

.dash-stat-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.07); }

.dash-stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dash-stat-icon svg { width: 20px; height: 20px; }

.dash-stat-icon--audio   { background: #ede9fe; color: #6d28d9; }
.dash-stat-icon--cat     { background: #dbeafe; color: #2563eb; }
.dash-stat-icon--user    { background: #d1fae5; color: #059669; }
.dash-stat-icon--storage { background: #fef3c7; color: #d97706; }

.dash-stat-body { flex: 1; min-width: 0; }

.dash-stat-number {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text);
  line-height: 1.1;
}

.dash-stat-unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}

.dash-stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 2px;
}

.dash-stat-arrow {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 16px;
  transition: color 0.15s, transform 0.15s;
  flex-shrink: 0;
}

.dash-stat-arrow:hover { color: var(--primary); transform: translateX(2px); }

.dash-section { margin-bottom: 28px; }

.dash-section-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.dash-section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

.dash-section-link {
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.dash-section-link:hover { text-decoration: underline; }

.dash-recent {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.dash-recent-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.dash-recent-item:last-child { border-bottom: none; }
.dash-recent-item:hover { background: #fafafa; }

.dash-recent-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #ede9fe;
  color: #6d28d9;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dash-recent-info { flex: 1; min-width: 0; }

.dash-recent-title {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dash-recent-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 1px;
}

.dash-recent-date {
  font-size: 11.5px;
  color: var(--text-muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* ===== UTILS ===== */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
