/* =====================================================
   AFFSP SHARED CSS — Design Tokens + Base Layout
   Dùng chung cho user dashboard + admin dashboard
   ===================================================== */

/*
  Google Fonts CDN: phù hợp cho development và MVP.
  Khi production lớn, nên build file CSS riêng bằng Tailwind CLI hoặc Vite.
*/
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ==================== DESIGN TOKENS ==================== */
:root {
  --primary: #d77770;
  --primary-2: #e7b7a2;
  --primary-3: #2E1E1A;
  --primary-4: rgba(215,119,112,.16);
  --navy-900: #050505;
  --navy-800: #0b0b0c;
  --navy-700: #101011;
  --navy-600: #171718;
  --white: #FFFFFF;
  --bg: #050505;
  --bg-2: #0b0b0c;
  --card: #101011;
  --card-border: rgba(233,184,173,.14);
  --text-1: #F7F1EE;
  --text-2: #d4cbc7;
  --text-3: #9c938e;
  --text-inv: #FFFFFF;
  --success: #34D399;
  --danger: #FB7185;
  --warning: #FBBF24;
  --info: #60A5FA;
  --border: rgba(233,184,173,.12);
  --border-subtle: rgba(255,255,255,.05);
  --radius-xl: 28px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --shadow-sm: 0 2px 8px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md: 0 8px 24px rgba(0,0,0,.16), 0 2px 6px rgba(0,0,0,.10);
  --shadow-lg: 0 20px 60px rgba(0,0,0,.22), 0 6px 20px rgba(0,0,0,.12);
  --shadow-xl: 0 30px 80px rgba(0,0,0,.26), 0 10px 30px rgba(0,0,0,.14);
  --shadow-primary: 0 10px 24px rgba(215,119,112,.18);
  --shadow-primary-lg: 0 16px 34px rgba(215,119,112,.24);
  --gradient-primary: linear-gradient(135deg, #d26f68, #e4b39a);
  --gradient-primary-soft: linear-gradient(135deg, rgba(215,119,112,.18), rgba(231,183,162,.08));
  --gradient-gold: linear-gradient(135deg, #dca07d, #efd2bf);
  --gradient-card: linear-gradient(180deg, #121213, #080809);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

.dark {
  --bg: #050505;
  --bg-2: #0b0b0c;
  --card: #101011;
  --card-border: rgba(233,184,173,.14);
  --text-1: #F7F1EE;
  --text-2: #d4cbc7;
  --text-3: #9c938e;
  --border: rgba(233,184,173,.12);
  --border-subtle: rgba(255,255,255,.05);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.30), 0 1px 2px rgba(0,0,0,.20);
  --shadow-md: 0 8px 24px rgba(0,0,0,.40), 0 2px 6px rgba(0,0,0,.25);
  --shadow-lg: 0 20px 60px rgba(0,0,0,.50), 0 6px 20px rgba(0,0,0,.30);
  --gradient-card: linear-gradient(180deg, #121213, #080809);
}

/* ==================== RESET ==================== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background:
    radial-gradient(circle at top left, rgba(215,119,112,.12) 0%, transparent 28%),
    radial-gradient(circle at top right, rgba(233,184,173,.10) 0%, transparent 26%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  color: var(--text-1);
  transition: background .3s, color .3s;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.dark body {
  background:
    radial-gradient(circle at top left, rgba(215,119,112,.10) 0%, transparent 22%),
    radial-gradient(circle at top right, rgba(233,184,173,.06) 0%, transparent 18%),
    linear-gradient(180deg, #050505 0%, #0b0b0c 100%);
}

/* ==================== ANIMATIONS ==================== */
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(20px); }
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slide-in {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==================== LAYOUT ==================== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 50;
  overflow-y: auto;
  transition: transform .3s;
}

.sidebar-logo {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo .logo-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: block;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: var(--shadow-primary);
}

.sidebar-logo .logo-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
  line-height: 1.2;
}

.sidebar-logo .logo-sub {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 12px 8px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all .2s;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--border-subtle);
  color: var(--text-1);
}

.nav-item.active {
  background: var(--primary-4);
  color: var(--primary);
}

.nav-item.active svg {
  stroke: var(--primary);
}

.dark .nav-item.active {
  background: rgba(215,119,112,.18);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke: currentColor;
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid var(--border-subtle);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}

.sidebar-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 11px;
  color: var(--text-3);
}

/* Main content area */
.main-content {
  flex: 1;
  margin-left: 260px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-header {
  padding: 28px 32px 0;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-3);
}

.page-body {
  padding: 24px 32px;
  flex: 1;
}

/* ==================== TOPBAR ==================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-spacer { flex: 1; }

.topbar-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-2);
  transition: all .2s;
  position: relative;
}

.topbar-btn:hover {
  background: var(--border-subtle);
  color: var(--text-1);
}

.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--card);
}

/* ==================== CARDS ==================== */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  animation: fade-in .3s ease-out;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
}

.card-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-1);
  line-height: 1;
  margin-bottom: 4px;
}

.card-change {
  font-size: 12px;
  color: var(--text-3);
}

.card-change.positive { color: var(--success); }
.card-change.negative { color: var(--danger); }

/* ==================== STAT GRID ==================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

/* ==================== TABLES ==================== */
.table-container {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  padding: 14px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .06em;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: 14px 16px;
  font-size: 14px;
  color: var(--text-1);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.table tr:last-child td { border-bottom: none; }

.table tr:hover td { background: var(--border-subtle); }

/* ==================== FORMS ==================== */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

.form-input,
.form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-1);
  font-family: var(--font);
  font-size: 14px;
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(215,119,112,.18);
}

/* ==================== BUTTONS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  border: none;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(180deg, rgba(18,18,19,.98) 0%, rgba(8,8,9,.98) 100%);
  border: 1px solid rgba(215,119,112,.28);
  color: #f2c5bc;
  box-shadow: 0 10px 24px rgba(0,0,0,.18);
}
.btn-primary:hover {
  color: #fff3ee;
  border-color: rgba(233,184,173,.42);
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(0,0,0,.22);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--card);
  color: var(--text-1);
  border: 1px solid var(--card-border);
}
.btn-secondary:hover { background: var(--border-subtle); }

.btn-danger {
  background: rgba(239,68,68,.1);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,.2);
}
.btn-danger:hover { background: rgba(239,68,68,.15); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 15px; }

/* ==================== BADGES ==================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success { background: rgba(34,197,94,.1); color: #22C55E; }
.badge-warning { background: rgba(245,158,11,.1); color: #F59E0B; }
.badge-danger { background: rgba(239,68,68,.1); color: #EF4444; }
.badge-info { background: rgba(59,130,246,.1); color: #3B82F6; }
.badge-neutral { background: var(--bg-2); color: var(--text-3); }

/* ==================== ALERT/HINT BOXES ==================== */
.hint-box {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.hint-warning {
  background: rgba(245,158,11,.08);
  border: 1px solid rgba(245,158,11,.2);
  color: #92400e;
}
.dark .hint-warning { background: rgba(245,158,11,.1); border-color: rgba(245,158,11,.3); color: #fbbf24; }

/* ==================== EMPTY STATE ==================== */
.empty-state {
  text-align: center;
  padding: 64px 32px;
  color: var(--text-3);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  opacity: .4;
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

.empty-state p { font-size: 14px; }

/* ==================== LOADING SPINNER ==================== */
.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.spinner-sm { width: 16px; height: 16px; }
.spinner-lg { width: 40px; height: 40px; border-width: 3px; }

/* ==================== TABS ==================== */
.tab-bar {
  display: flex;
  gap: 4px;
  background: var(--bg-2);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: 24px;
}

.tab-item {
  padding: 8px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: all .2s;
  border: none;
  background: none;
  font-family: var(--font);
}

.tab-item:hover { color: var(--text-1); }

.tab-item.active {
  background: var(--card);
  color: var(--text-1);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

/* ==================== PAGE TRANSITIONS ==================== */
.page-enter {
  animation: fade-in .25s ease-out;
}

/* ==================== MODAL ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fade-in .15s ease-out;
}

.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  animation: fade-in .2s ease-out;
}

.modal-header {
  padding: 24px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-1);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--bg-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: all .2s;
}

.modal-close:hover {
  background: var(--border);
  color: var(--text-1);
}

.modal-body { padding: 24px; }
.modal-footer {
  padding: 0 24px 24px;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .page-header, .page-body { padding-left: 20px; padding-right: 20px; }
  .topbar { padding: 0 20px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
