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

:root {
  --sidebar-bg: #1a1a2e;
  --sidebar-text: #a0aec0;
  --sidebar-active: #4f8ef7;
  --sidebar-hover: #2d2d4a;
  --sidebar-width: 240px;
  --topbar-h: 64px;
  --body-bg: #f7f8fc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-muted: #718096;
  --primary: #4f8ef7;
  --primary-dark: #3b7de8;
  --success: #38a169;
  --warning: #d69e2e;
  --danger: #e53e3e;
  --purple: #805ad5;
  --orange: #dd6b20;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.04);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 14px; color: var(--text); background: var(--body-bg); line-height: 1.5; }

/* === App Layout === */
.app-layout { display: flex; min-height: 100vh; }
.main-content { flex: 1; display: flex; flex-direction: column; margin-left: var(--sidebar-width); min-height: 100vh; }
.page-body { flex: 1; padding: 24px; max-width: 1400px; width: 100%; }

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex; flex-direction: column;
  padding: 0;
  z-index: 100;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  color: #fff; font-weight: 700; font-size: 15px;
}
.sidebar-menu { list-style: none; padding: 12px 0; flex: 1; }
.sidebar-menu li a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; color: var(--sidebar-text);
  text-decoration: none; font-size: 14px; font-weight: 500;
  border-radius: 0; transition: background 0.15s, color 0.15s;
}
.sidebar-menu li a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-menu li a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-menu li.active a { background: rgba(79,142,247,0.15); color: var(--sidebar-active); border-right: 3px solid var(--sidebar-active); }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.06); }
.logout-btn {
  display: flex; align-items: center; gap: 10px;
  background: none; border: none; color: var(--sidebar-text);
  cursor: pointer; font-size: 14px; font-weight: 500; width: 100%; padding: 8px 0;
  transition: color 0.15s;
}
.logout-btn svg { width: 18px; height: 18px; }
.logout-btn:hover { color: #fff; }

/* === Topbar === */
.topbar {
  height: var(--topbar-h); background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; position: sticky; top: 0; z-index: 50;
}
.page-title { font-size: 18px; font-weight: 700; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.user-badge { display: flex; align-items: center; gap: 8px; color: var(--text-muted); }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }

/* === Cards === */
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 24px; overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-header h3 { font-size: 15px; font-weight: 600; color: var(--text); }
.card-body { padding: 20px; }
.card-body.no-pad { padding: 0; }
.card-link { color: var(--primary); text-decoration: none; font-size: 13px; }
.card-link:hover { text-decoration: underline; }

/* === Stats Grid === */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; display: flex; align-items: center; gap: 16px; }
.stat-icon { width: 48px; height: 48px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon svg { width: 24px; height: 24px; }
.stat-icon-blue { background: rgba(79,142,247,0.1); color: var(--primary); }
.stat-icon-green { background: rgba(56,161,105,0.1); color: var(--success); }
.stat-icon-purple { background: rgba(128,90,213,0.1); color: var(--purple); }
.stat-icon-orange { background: rgba(221,107,32,0.1); color: var(--orange); }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 500; }

/* === Charts === */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-card { margin-bottom: 0; }
@media (max-width: 768px) { .charts-row { grid-template-columns: 1fr; } }

/* === Tables === */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { background: #f9fafb; padding: 12px 16px; text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); }
.data-table td { padding: 12px 16px; border-bottom: 1px solid #f0f0f5; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f9fafb; }
.clickable-row { cursor: pointer; }

/* === Login === */
.login-page { background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-container { background: #fff; border-radius: 16px; padding: 40px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 { font-size: 22px; font-weight: 700; color: var(--text); margin: 16px 0 6px; }
.login-logo p { color: var(--text-muted); font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }

/* === Forms === */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text); }
.form-input, .select-input, input[type="text"], input[type="password"], input[type="email"], input[type="file"], select {
  border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px;
  font-size: 14px; color: var(--text); background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s; width: 100%;
}
.form-input:focus, input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,142,247,0.15); }
.form-row { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 160px; }
.search-form { display: flex; gap: 8px; align-items: center; }
.search-input { min-width: 240px; }
.filter-form { display: flex; gap: 8px; }
.select-input { width: auto; min-width: 120px; }
.upload-form .form-row { align-items: flex-end; }

/* === Buttons === */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 6px; font-size: 14px; font-weight: 500; cursor: pointer; text-decoration: none; transition: all 0.15s; border: 1px solid transparent; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: #f7f8fc; color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; padding: 12px; }

/* === Badges === */
.badge { display: inline-flex; align-items: center; justify-content: center; background: #e2e8f0; color: var(--text-muted); border-radius: 12px; padding: 2px 8px; font-size: 12px; font-weight: 600; margin-left: 8px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.tag-photo { background: rgba(79,142,247,0.1); color: var(--primary); }
.tag-route { background: rgba(56,161,105,0.1); color: var(--success); }
.tag-ride { background: rgba(221,107,32,0.1); color: var(--orange); }

/* === Alerts === */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; font-size: 14px; }
.alert-error { background: rgba(229,62,62,0.08); border: 1px solid rgba(229,62,62,0.2); color: #c53030; }
.alert-warning { background: rgba(214,158,46,0.08); border: 1px solid rgba(214,158,46,0.2); color: #975a16; }
.alert-success { background: rgba(56,161,105,0.08); border: 1px solid rgba(56,161,105,0.2); color: #276749; }

/* === User Elements === */
.user-chip { display: inline-flex; align-items: center; gap: 6px; background: #f0f4ff; color: var(--primary); border-radius: 12px; padding: 2px 10px; font-size: 12px; font-weight: 600; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.avatar-lg { width: 72px; height: 72px; font-size: 28px; margin: 0 auto; }

/* === User Detail / Profile === */
.profile-grid { display: grid; grid-template-columns: 280px 1fr; gap: 24px; align-items: start; }
@media (max-width: 900px) { .profile-grid { grid-template-columns: 1fr; } }
.profile-card { }
.profile-meta { border-top: 1px solid var(--border); }
.meta-item { display: flex; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.meta-item:last-child { border-bottom: none; }
.meta-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.meta-value { font-size: 13px; color: var(--text); font-weight: 500; text-align: right; max-width: 160px; overflow-wrap: break-word; }

/* === Posts list === */
.posts-list { }
.post-item { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.post-item:last-child { border-bottom: none; }
.post-content { font-size: 14px; color: var(--text); margin-bottom: 8px; }
.post-meta { display: flex; gap: 12px; font-size: 12px; color: var(--text-muted); }

/* === Firmware === */

/* === Misc === */
.text-muted { color: var(--text-muted); }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: 'SFMono-Regular', Consolas, monospace; font-size: 12px; }
.empty-state { text-align: center; padding: 48px; color: var(--text-muted); }
.pagination { padding: 16px 20px; border-top: 1px solid var(--border); }
.error-page { text-align: center; padding: 40px; }
.error-page h1 { font-size: 24px; margin-bottom: 12px; }
.error-page p { color: var(--text-muted); margin-bottom: 24px; }
.filter-bar { display: flex; align-items: center; gap: 8px; }
