:root {
  --white: #ffffff;
  --black: #000000;
  --gray-50: #fafafa;
  --gray-100: #f5f5f5;
  --gray-200: #e5e5e5;
  --gray-300: #d4d4d4;
  --gray-400: #a3a3a3;
  --gray-500: #737373;
  --gray-600: #525252;
  --gray-700: #404040;
  --gray-800: #262626;
  --gray-900: #171717;
  --primary: #dc2626;
  --primary-dark: #b91c1c;
  --primary-light: #fef2f2;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  color: var(--gray-800);
  background: var(--gray-50);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: var(--primary); }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; height: auto; }

h1, h2, h3, h4, h5, h6 { font-weight: 600; line-height: 1.3; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }

.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-primary { color: var(--primary); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 10px 20px; border: none; border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 500; font-family: var(--font);
  cursor: pointer; transition: all 0.15s ease; white-space: nowrap;
  line-height: 1.4;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: var(--white); }
.btn-success:hover:not(:disabled) { background: #2b8a3e; }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover:not(:disabled) { background: #c92a2a; }
.btn-outline { background: var(--white); color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-outline:hover:not(:disabled) { background: var(--gray-50); border-color: var(--gray-400); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 0.95rem; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover:not(:disabled) { background: var(--gray-100); }
.btn-warning { background: var(--warning); color: var(--white); }
.btn-warning:hover:not(:disabled) { background: #b45309; }

.form-group { margin-bottom: 1.25rem; }
.form-label { display: block; margin-bottom: 6px; font-size: 0.825rem; font-weight: 500; color: var(--gray-700); }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 14px; border: 1px solid var(--gray-300);
  border-radius: var(--radius); font-size: 0.9rem; font-family: var(--font);
  background: var(--white); transition: all 0.15s ease; color: var(--gray-800);
}
  .form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(220,38,38,0.1);
}
.form-input::placeholder { color: var(--gray-400); }
.form-textarea { min-height: 100px; resize: vertical; }
.form-error { color: var(--danger); font-size: 0.8rem; margin-top: 4px; }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='%23666' d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
.form-input-sm { padding: 8px 12px; font-size: 0.825rem; }
.form-checkbox { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; cursor: pointer; }

.card {
  background: var(--white); border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200); padding: 24px; margin-bottom: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--gray-100);
}
.card-header h2, .card-header h3 { margin: 0; }

.badge {
  display: inline-flex; align-items: center; padding: 2px 10px;
  border-radius: 100px; font-size: 0.725rem; font-weight: 600;
  letter-spacing: 0.01em;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-secondary { background: var(--gray-100); color: var(--gray-500); }

.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
table th {
  text-align: left; padding: 10px 14px; font-size: 0.75rem; font-weight: 600;
  color: var(--gray-500); border-bottom: 2px solid var(--gray-200);
  white-space: nowrap; letter-spacing: 0.02em;
}
table td { padding: 10px 14px; border-bottom: 1px solid var(--gray-100); font-size: 0.875rem; }
table tbody tr:hover td { background: var(--gray-50); }
.table-empty { text-align: center; padding: 40px 20px !important; color: var(--gray-400); }

.alert {
  padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px;
  font-size: 0.875rem;
}
.alert-info { background: var(--primary-light); color: var(--primary); }
.alert-success { background: var(--success-light); color: var(--success); }
.alert-warning { background: var(--warning-light); color: var(--warning); }
.alert-danger { background: var(--danger-light); color: var(--danger); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: none;
  align-items: center; justify-content: center; z-index: 1000; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--white); border-radius: var(--radius-lg); padding: 28px;
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15); animation: modalIn 0.15s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.97) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-header h3 { margin: 0; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--gray-400); padding: 4px; line-height: 1; border-radius: 4px; }
.modal-close:hover { background: var(--gray-100); color: var(--gray-600); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--gray-200); }

#toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; max-width: 380px;
}
.toast {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--white); border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.1); font-size: 0.875rem;
  animation: toastIn 0.2s ease; border-left: 3px solid var(--gray-400);
}
.toast-success { border-left-color: var(--success); }
.toast-warning { border-left-color: var(--warning); }
.toast-danger { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--primary); }
.toast-close { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--gray-400); padding: 0; line-height: 1; }
.toast-fade-out { animation: toastOut 0.2s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(100%); } }

.loading-overlay {
  position: fixed; inset: 0; background: rgba(255,255,255,0.7); display: none;
  align-items: center; justify-content: center; z-index: 9998;
}
.spinner { width: 32px; height: 32px; border: 3px solid var(--gray-200); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.app-container { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px; background: var(--gray-900); color: var(--white);
  display: flex; flex-direction: column; position: fixed; inset: 0; right: auto;
  z-index: 100; transition: transform 0.2s ease;
}
.sidebar-brand { padding: 24px 20px 20px; border-bottom: 1px solid rgba(255,255,255,0.06); display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.sidebar-brand h2 { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em; color: var(--white); }
.sidebar-brand > span { font-size: 0.75rem; color: var(--gray-500); width: 100%; }
.sidebar-greeting { display: none; }
.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-section { margin-bottom: 8px; }
.nav-section-title {
  font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--gray-500); padding: 8px 12px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: 6px; color: var(--gray-400); transition: all 0.15s ease;
  cursor: pointer; font-size: 0.85rem; margin-bottom: 1px;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: var(--white); }
.nav-item.active { background: rgba(220,38,38,0.15); color: #fca5a5; }
.nav-item .nav-icon { width: 18px; text-align: center; font-size: 0.95rem; opacity: 0.7; }
.sidebar-footer { padding: 12px 10px; border-top: 1px solid rgba(255,255,255,0.06); }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 6px; cursor: pointer; transition: all 0.15s ease; }
.sidebar-user:hover { background: rgba(255,255,255,0.06); }
.sidebar-user-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 0.85rem; color: var(--white); flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 0.825rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 0.7rem; color: var(--gray-500); }

.main-content { flex: 1; margin-left: 240px; padding: 28px 36px; min-height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 28px; gap: 20px;
}
.topbar-left h1 { font-size: 1.35rem; margin-bottom: 2px; }
.topbar-left p { color: var(--gray-500); font-size: 0.85rem; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.mobile-toggle { display: none; background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--gray-600); padding: 4px; }

.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--gray-50); padding: 20px;
}
.auth-container {
  background: var(--white); border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200); width: 100%; max-width: 420px; padding: 40px;
}
.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo h1 { font-size: 1.6rem; color: var(--gray-900); font-weight: 700; }
.auth-logo p { color: var(--gray-500); margin-top: 4px; font-size: 0.85rem; }
.auth-title { font-size: 1.2rem; margin-bottom: 4px; text-align: center; }
.auth-subtitle { color: var(--gray-500); text-align: center; margin-bottom: 28px; font-size: 0.85rem; }
.auth-footer { text-align: center; margin-top: 24px; font-size: 0.85rem; color: var(--gray-500); }
.auth-footer a { font-weight: 500; }

.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 28px;
}
.stat-card {
  background: var(--white); border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200); padding: 20px 24px;
}
.stat-card .stat-label { font-size: 0.8rem; color: var(--gray-500); margin-bottom: 4px; }
.stat-card .stat-value { font-size: 1.65rem; font-weight: 700; line-height: 1.2; letter-spacing: -0.02em; }

.quick-actions {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; margin-bottom: 28px;
}
.quick-action {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 18px 12px; background: var(--white); border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg); cursor: pointer; transition: all 0.15s ease;
  font-size: 0.825rem; font-weight: 500; font-family: var(--font); color: var(--gray-700);
}
.quick-action:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.quick-action .qa-icon { font-size: 1.3rem; }

.accounts-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px; margin-bottom: 28px;
}
.account-card {
  background: var(--gray-900); border-radius: var(--radius-lg);
  padding: 24px; color: var(--white); position: relative;
}
.account-card .card-status { position: absolute; top: 16px; right: 16px; }
.account-card .card-type { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.5; margin-bottom: 6px; }
.account-card .card-number { font-size: 1rem; font-family: 'SF Mono', 'Fira Code', monospace; letter-spacing: 0.06em; margin-bottom: 20px; opacity: 0.7; }
.account-card .account-number { font-size: 1rem; font-family: 'SF Mono', 'Fira Code', monospace; letter-spacing: 0.06em; margin-bottom: 20px; opacity: 0.7; display: flex; align-items: center; gap: 8px; }
.account-card .account-balance { font-size: 1.75rem; font-weight: 700; margin-bottom: 2px; }
.account-card .card-label { font-size: 0.7rem; opacity: 0.4; text-transform: uppercase; letter-spacing: 0.06em; }

.copy-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 4px;
  background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.6);
  font-size: 0.75rem; cursor: pointer; transition: all 0.15s ease;
  border: none; line-height: 1;
}
.copy-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }

.transaction-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--gray-100);
}
.transaction-item:last-child { border-bottom: none; }
.tx-left { display: flex; align-items: center; gap: 12px; }
.tx-icon {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; flex-shrink: 0;
}
.tx-icon.credit { background: var(--success-light); color: var(--success); }
.tx-icon.debit { background: var(--danger-light); color: var(--danger); }
.tx-icon.transfer { background: var(--primary-light); color: var(--primary); }
.tx-details h4 { font-size: 0.875rem; margin-bottom: 1px; font-weight: 500; }
.tx-details span { font-size: 0.775rem; color: var(--gray-500); }
.tx-right { text-align: right; }
.tx-amount { font-weight: 600; font-size: 0.9rem; }
.tx-amount.credit { color: var(--success); }
.tx-amount.debit { color: var(--danger); }
.tx-date { font-size: 0.725rem; color: var(--gray-500); }

.tab-content { display: none; }
.tab-content.active { display: block; }

.tab-back {
  display: inline-flex; align-items: center; gap: 4px;
  margin-bottom: 16px; font-size: 0.85rem; font-weight: 500;
  color: var(--gray-500); cursor: pointer; transition: color 0.15s ease;
  padding: 4px 0;
}
.tab-back:hover { color: var(--primary); }

.empty-state { text-align: center; padding: 48px 20px; color: var(--gray-400); }
.empty-state h3 { color: var(--gray-600); margin-bottom: 6px; font-size: 1rem; }
.empty-state p { font-size: 0.85rem; }

.upload-area {
  border: 2px dashed var(--gray-300); border-radius: var(--radius-lg);
  padding: 28px; text-align: center; cursor: pointer; transition: all 0.15s ease;
  background: var(--gray-50);
}
.upload-area:hover { border-color: var(--primary); background: var(--primary-light); }
.upload-area p { color: var(--gray-500); font-size: 0.85rem; }
.upload-area .upload-icon { margin-bottom: 12px; color: var(--gray-400); }
.upload-preview { margin-top: 12px; max-width: 200px; border-radius: var(--radius); border: 1px solid var(--gray-200); }

.gift-card-item {
  flex: 0 0 100%; width: 100%; scroll-snap-align: start;
  border-radius: 0; padding: 0; color: var(--white); cursor: pointer;
  position: relative; display: flex; flex-direction: column; overflow: hidden;
  min-width: 0;
}
.gift-card-item:hover { transform: translateY(-3px); }
.gift-card-item.unavailable { opacity: 0.5; cursor: default; }
.gift-card-item.unavailable:hover { transform: none; }
.gift-card-bg { padding: 24px 20px; flex: 1; display: flex; flex-direction: column; justify-content: flex-end; background-size: cover; background-position: center; }
.gift-card-icon { font-size: 2rem; margin-bottom: 10px; display: none; }
.gift-card-name { font-size: 1rem; font-weight: 700; margin-bottom: 4px; text-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.gift-card-price { font-size: 1.1rem; font-weight: 700; }
.gift-card-badge { position: absolute; top: 10px; right: 10px; font-size: 0.6rem; padding: 3px 10px; border-radius: 100px; font-weight: 600; background: rgba(0,0,0,0.4); color: rgba(255,255,255,0.8); backdrop-filter: blur(4px); }

.gift-cards-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.gift-cards-grid .gift-card-item { flex: none; border-radius: var(--radius-lg); }

@media (max-width: 1024px) {
  .main-content { margin-left: 0; padding: 24px; }
  .sidebar { transform: translateX(-100%); width: 260px; }
  .sidebar.open { transform: translateX(0); }
  .sidebar.open .sidebar-greeting { display: block; font-size: 0.7rem; color: var(--gray-400); text-align: right; white-space: nowrap; }
  .mobile-toggle { display: block; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .main-content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr; gap: 12px; }
  .quick-actions { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .accounts-grid { grid-template-columns: 1fr; }
  .auth-container { padding: 28px 24px; }
  .modal { padding: 24px 20px; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .topbar-left h1 { font-size: 1.2rem; display: none; }
  .topbar-left p { display: none; }
  table th, table td { padding: 8px 10px; font-size: 0.8rem; }
  .card { padding: 16px; }
  .gift-cards-grid { grid-template-columns: 1fr; }
  .gift-cards-grid .gift-card-item { flex: none; border-radius: var(--radius-lg); }
}