/* ===== CSS Variables ===== */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #ea580c;
  --warning-light: #fef3c7;
  --error: #dc2626;
  --error-light: #fee2e2;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: all 0.2s ease;
}

/* ===== Reset & Base ===== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--gray-800);
  background: var(--gray-100);
  -webkit-font-smoothing: antialiased;
}

/* ===== Login Page ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px;
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 8px;
}

.login-header p {
  color: var(--gray-500);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ===== Main App Layout ===== */
.main-app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: white;
  border-right: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--gray-200);
}

.sidebar-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--gray-900);
}

.sidebar-nav {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: none;
  background: transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  color: var(--gray-600);
  transition: var(--transition);
  text-align: left;
}

.nav-item:hover {
  background: var(--gray-100);
  color: var(--gray-800);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
}

.nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--gray-200);
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

#current-username {
  font-weight: 500;
  color: var(--gray-800);
}

.role-badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  display: inline-block;
  width: fit-content;
}

.role-badge.admin {
  background: var(--error-light);
  color: var(--error);
}

.role-badge.package {
  background: var(--warning-light);
  color: var(--warning);
}

.content {
  flex: 1;
  margin-left: 240px;
  padding: 24px 32px;
  max-width: calc(100% - 240px);
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--gray-200);
}

.content-header h2 {
  font-size: 24px;
  font-weight: 600;
  color: var(--gray-900);
}

.quota-badge {
  padding: 8px 16px;
  background: var(--warning-light);
  color: var(--warning);
  border-radius: var(--radius);
  font-weight: 500;
}

.quota-badge.full {
  background: var(--error-light);
  color: var(--error);
}

/* ===== Tab Content ===== */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Cards ===== */
.card {
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-100);
}

.card-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.card-subtitle {
  font-size: 13px;
  color: var(--gray-500);
}

.card > .form,
.card > .table-container,
.card > .search-bar,
.card > .pagination,
.card > .user-stats,
.card > .form-actions,
.card > .filter-bar,
.card > div {
  padding: 24px;
}

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.stat-card {
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1;
}

.stat-label {
  font-size: 14px;
  color: var(--gray-500);
  margin-top: 4px;
}

/* ===== Fetch Page ===== */
.fetch-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  padding: 40px 0;
}

.fetch-card {
  text-align: center;
  max-width: 400px;
}

.fetch-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.fetch-card h3 {
  font-size: 20px;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 8px;
}

.fetch-card > p {
  color: var(--gray-500);
  margin-bottom: 24px;
}

.quota-panel {
  background: var(--gray-50);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
}

.quota-bar-container {
  height: 8px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.quota-bar {
  height: 100%;
  background: var(--success);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.quota-bar.warning {
  background: var(--warning);
}

.quota-bar.danger {
  background: var(--error);
}

.quota-text {
  font-size: 13px;
  color: var(--gray-600);
  text-align: center;
}

.fetch-result {
  width: 100%;
  max-width: 500px;
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-header {
  padding: 16px 24px;
  background: var(--success-light);
  border-bottom: 1px solid var(--gray-100);
}

.result-badge {
  font-size: 14px;
  font-weight: 600;
  color: var(--success);
}

.result-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.result-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-item label {
  font-size: 12px;
  font-weight: 500;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.result-value {
  display: flex;
  align-items: center;
  gap: 12px;
}

.result-value code {
  flex: 1;
  font-size: 16px;
  padding: 12px 16px;
}

/* ===== Forms ===== */
.form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
}

.form-group input,
.form-group select {
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-inline {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  padding: 16px 24px 24px;
}

.card > .form-inline {
  padding: 20px 24px 28px;
}

.form-inline input {
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
}

.form-inline input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-inline select {
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  background: white;
}

.form-inline select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.muted.small {
  font-size: 12px;
  color: var(--gray-500);
}

.inline-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn.btn-primary,
button[type="submit"].btn-primary {
  background: #2563eb;
  color: #ffffff;
  border: 1px solid #2563eb;
}

.btn.btn-primary:hover:not(:disabled),
button[type="submit"].btn-primary:hover:not(:disabled) {
  background: #2563eb;
  border-color: #2563eb;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
  transform: translateY(-1px);
}

.btn.btn-primary span {
  color: #ffffff;
}

.btn-secondary {
  background: white;
  color: var(--gray-700);
  border-color: var(--gray-300);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--gray-50);
  border-color: var(--gray-400);
}

.btn-text {
  background: transparent;
  color: var(--gray-500);
  padding: 8px 12px;
}

.btn-text:hover:not(:disabled) {
  color: var(--gray-700);
  background: var(--gray-100);
}

.btn-block {
  width: 100%;
}

.btn-large {
  padding: 16px 32px;
  font-size: 16px;
}

.btn-small {
  padding: 6px 12px;
  font-size: 13px;
}

.btn-icon {
  padding: 8px;
  font-size: 16px;
}

.btn-loading {
  display: inline;
}

/* ===== Tables ===== */
.table-container {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--gray-100);
}

.data-table th {
  font-weight: 600;
  color: var(--gray-600);
  background: var(--gray-50);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table tbody tr {
  cursor: pointer;
  transition: var(--transition);
}

.data-table tbody tr:hover {
  background: var(--gray-50);
}

.data-table tbody tr.selected {
  background: var(--primary-light);
}

.data-table .empty-row td {
  text-align: center;
  color: var(--gray-400);
  padding: 40px;
}

.data-table code {
  font-size: 13px;
  padding: 4px 8px;
  background: var(--gray-100);
  border-radius: var(--radius-sm);
  font-family: "SF Mono", Monaco, monospace;
}

/* ===== Users Layout ===== */
.users-layout {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 20px;
}

.users-right .user-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  padding: 0;
}

.user-stat {
  text-align: center;
  padding: 16px;
  background: var(--gray-50);
  border-radius: var(--radius);
}

.user-stat-value {
  display: block;
  font-size: 24px;
  font-weight: 700;
  color: var(--gray-900);
}

.user-stat-label {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 4px;
}

.search-bar {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--gray-100);
}

.search-bar input {
  flex: 1;
  max-width: 300px;
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
}

.filter-bar {
  display: flex;
  gap: 12px;
  align-items: center;
}

.filter-bar select {
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 14px;
  background: white;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px 24px;
  border-top: 1px solid var(--gray-100);
}

.page-info {
  font-size: 14px;
  color: var(--gray-600);
}

/* ===== Toast Notifications ===== */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toast {
  padding: 14px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  max-width: 400px;
  animation: slideInRight 0.3s ease;
}

.toast.success {
  background: white;
  border-left: 4px solid var(--success);
}

.toast.error {
  background: white;
  border-left: 4px solid var(--error);
}

.toast.warning {
  background: white;
  border-left: 4px solid var(--warning);
}

.toast.info {
  background: white;
  border-left: 4px solid var(--primary);
}

.toast-icon {
  font-size: 20px;
}

.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--error); }
.toast.warning .toast-icon { color: var(--warning); }
.toast.info .toast-icon { color: var(--primary); }

.toast-message {
  flex: 1;
  font-size: 14px;
  color: var(--gray-700);
}

.toast-close {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--gray-400);
  cursor: pointer;
  padding: 4px;
}

.toast-close:hover {
  color: var(--gray-600);
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  animation: scaleIn 0.2s ease;
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-content h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.modal-content > p {
  color: var(--gray-500);
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* ===== Utilities ===== */
.hidden {
  display: none !important;
}

.admin-only {
  display: none;
}

.is-admin .admin-only {
  display: flex;
}

.is-admin .admin-only.nav-item {
  display: flex;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .users-layout {
    grid-template-columns: 1fr;
  }
  
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .content {
    margin-left: 0;
    max-width: 100%;
    padding: 16px;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .form-row {
    grid-template-columns: 1fr;
  }
  
  .users-right .user-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}
