:root {
  --primary: #1565C0;
  --primary-dark: #0D47A1;
  --primary-light: #1976D2;
  --accent: #2196F3;
  --success: #4CAF50;
  --warning: #FF9800;
  --danger: #F44336;
  --text: #212121;
  --text-light: #757575;
  --bg: #F5F7FA;
  --card: #FFFFFF;
  --border: #E0E0E0;
  --win-bg: #E8F5E9;
  --win-color: #2E7D32;
  --lose-color: #C62828;
  --sidebar-w: 240px;
}

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

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

/* === LAYOUT === */
.app-container { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--primary-dark);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-logo {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo .logo-icon {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 900;
}

.sidebar-logo .logo-text { font-size: 14px; font-weight: 700; line-height: 1.2; }
.sidebar-logo .logo-text small { font-weight: 400; opacity: 0.7; font-size: 11px; }

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

.nav-section { padding: 8px 16px 4px; font-size: 10px; text-transform: uppercase; opacity: 0.5; letter-spacing: 1px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 14px;
  border-left: 3px solid transparent;
}

.nav-item:hover { background: rgba(255,255,255,0.08); }
.nav-item.active { background: rgba(255,255,255,0.12); border-left-color: #64B5F6; color: #64B5F6; }
.nav-item .nav-icon { font-size: 18px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 12px; opacity: 0.7;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.topbar-title { font-size: 18px; font-weight: 700; color: var(--primary); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.page-content { flex: 1; padding: 24px; }

/* === CARDS === */
.card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title { font-size: 16px; font-weight: 700; color: var(--primary); }
.card-body { padding: 20px; }

/* === STATS GRID === */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }

.stat-card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  display: flex; align-items: center; gap: 16px;
}

.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 24px; }
.stat-icon.blue { background: #E3F2FD; }
.stat-icon.green { background: #E8F5E9; }
.stat-icon.orange { background: #FFF3E0; }
.stat-icon.red { background: #FFEBEE; }
.stat-info .stat-value { font-size: 24px; font-weight: 700; }
.stat-info .stat-label { font-size: 12px; color: var(--text-light); }
.stat-info .stat-value.positive { color: var(--success); }
.stat-info .stat-value.negative { color: var(--danger); }

/* === BUTTONS === */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border: none; border-radius: 8px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #388E3C; }
.btn-warning { background: var(--warning); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline { background: transparent; border: 1.5px solid var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: white; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === FORMS === */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.2s;
  background: white;
}
.form-control:focus { outline: none; border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
select.form-control { cursor: pointer; }

/* === TABLES === */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { background: var(--primary); color: white; padding: 10px 12px; text-align: left; font-weight: 600; white-space: nowrap; }
tbody tr:nth-child(even) { background: #FAFAFA; }
tbody tr:hover { background: #F0F4FF; }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px 8px; border-radius: 100px;
  font-size: 11px; font-weight: 700;
}
.badge-success { background: var(--win-bg); color: var(--win-color); }
.badge-warning { background: #FFF8E1; color: #E65100; }
.badge-danger { background: #FFEBEE; color: var(--danger); }
.badge-info { background: #E3F2FD; color: var(--primary); }

/* === WIN HIGHLIGHT === */
.win-number { background: #A5D6A7; color: #1B5E20; padding: 2px 6px; border-radius: 4px; font-weight: 700; margin: 1px; display: inline-block; }
.entry-win td { background: #F1F8E9 !important; }

.profit { color: var(--win-color); font-weight: 700; }
.loss { color: var(--lose-color); font-weight: 700; }

/* === TABS === */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 20px; cursor: pointer;
  font-size: 14px; font-weight: 600;
  color: var(--text-light);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* === MODALS === */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; visibility: hidden;
  transition: all 0.2s;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: white; border-radius: 16px;
  width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
  transform: scale(0.95);
  transition: transform 0.2s;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-overlay.open .modal { transform: scale(1); }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 18px; font-weight: 700; color: var(--primary); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.btn-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-light); }

/* === OCR UPLOAD AREA === */
.upload-area {
  border: 2.5px dashed var(--border);
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg);
}
.upload-area:hover, .upload-area.drag-over { border-color: var(--primary); background: #E3F2FD; }
.upload-area .upload-icon { font-size: 48px; margin-bottom: 12px; }
.upload-area p { color: var(--text-light); font-size: 14px; }
.upload-area .upload-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

/* === FOOTER TABLE === */
.table-footer { background: var(--primary); color: white; padding: 16px 20px; border-radius: 0 0 12px 12px; }
.footer-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.footer-item .footer-label { font-size: 11px; opacity: 0.8; margin-bottom: 4px; }
.footer-item .footer-value { font-size: 18px; font-weight: 700; }
.footer-item .footer-value.win { color: #A5D6A7; }
.footer-item .footer-value.lose { color: #EF9A9A; }

/* === AUTH PAGES === */
.auth-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--accent) 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.auth-card { background: white; border-radius: 20px; padding: 40px; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,0.2); }
.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo h1 { font-size: 28px; font-weight: 900; color: var(--primary); }
.auth-logo p { color: var(--text-light); font-size: 14px; }

/* === ALERTS === */
.alert { padding: 12px 16px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; }
.alert-error { background: #FFEBEE; color: var(--lose-color); border-left: 4px solid var(--danger); }
.alert-success { background: var(--win-bg); color: var(--win-color); border-left: 4px solid var(--success); }
.alert-info { background: #E3F2FD; color: var(--primary); border-left: 4px solid var(--accent); }
.alert-warning { background: #FFF8E1; color: #E65100; border-left: 4px solid var(--warning); }

/* === LOADING === */
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid rgba(255,255,255,0.3); border-top-color: white; border-radius: 50%; animation: spin 0.7s linear infinite; }
.spinner.dark { border-color: rgba(0,0,0,0.1); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,0.8); display: flex; align-items: center; justify-content: center; z-index: 999; }

/* === LICENSE BANNER === */
.license-banner { background: linear-gradient(90deg, var(--warning) 0%, #FF5722 100%); color: white; padding: 10px 24px; display: flex; align-items: center; justify-content: space-between; font-size: 13px; }

/* === MOBILE === */
.hamburger { display: none; background: none; border: none; cursor: pointer; padding: 8px; }
.hamburger span { display: block; width: 22px; height: 2px; background: var(--primary); margin: 4px 0; transition: all 0.2s; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .hamburger { display: block; }
  .form-row { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .page-content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99; display: none; }
  .sidebar-overlay.open { display: block; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr; }
  .tabs { overflow-x: auto; }
  .tab { white-space: nowrap; }
}

/* === SEARCH & FILTER === */
.filter-bar { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filter-bar .form-group { margin-bottom: 0; }
.search-input { position: relative; }
.search-input input { padding-left: 36px; }
.search-input::before { content: '🔍'; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-size: 14px; }

/* === PAGINATION === */
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 16px; }
.page-btn { padding: 6px 12px; border: 1.5px solid var(--border); border-radius: 6px; background: white; cursor: pointer; font-size: 13px; }
.page-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.page-btn:hover:not(.active) { background: var(--bg); }

/* === PWA Install === */
#pwa-install { position: fixed; bottom: 20px; right: 20px; background: var(--primary); color: white; padding: 12px 20px; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.2); cursor: pointer; font-size: 14px; font-weight: 700; display: none; z-index: 1000; }

/* === Number input styles === */
.number-tag { display: inline-flex; align-items: center; background: #E3F2FD; color: var(--primary); border-radius: 6px; padding: 3px 8px; font-size: 13px; font-weight: 700; margin: 2px; }

/* === Entry type colors === */
.type-lo { color: #1565C0; font-weight: 700; }
.type-bacang { color: #6A1B9A; font-weight: 700; }
.type-dau { color: #00695C; font-weight: 700; }
.type-cuoi { color: #E65100; font-weight: 700; }
.type-xien2, .type-xien3 { color: #AD1457; font-weight: 700; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #B0BEC5; border-radius: 3px; }
