/* ============================================
   INTERNATIONAL STANDARD DESIGN SYSTEM 2025
   Common styles for all admin pages
   ============================================ */

:root {
  /* Neutral Gray Scale */
  --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;

  /* Primary Blue */
  --primary-50: #EFF6FF;
  --primary-100: #DBEAFE;
  --primary-500: #3B82F6;
  --primary-600: #2563EB;
  --primary-700: #1D4ED8;

  /* Semantic Colors */
  --success: #10B981;
  --warning: #F59E0B;
  --error: #EF4444;
  --info: #06B6D4;

  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
  --shadow-focus: 0 0 0 3px rgba(59, 130, 246, 0.15);

  /* Page Colors */
  --bg-card: #FFFFFF;
  --border-color: var(--gray-200);
  --text-primary: var(--gray-900);
  --text-secondary: var(--gray-700);
  --text-muted: var(--gray-500);

  /* Status Colors */
  --status-draft: #9CA3AF;
  --status-pending: #F59E0B;
  --status-partial: #3B82F6;
  --status-paid: #10B981;
  --status-sent: #3B82F6;
  --status-accepted: #10B981;
  --status-rejected: #EF4444;
  --status-expired: #F59E0B;
  --status-converted: #8B5CF6;
}

/* === CONTAINERS === */
.admin-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* === PAGE HEADER === */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.page-header p {
  color: var(--text-muted);
  font-size: 14px;
  margin: 4px 0 0 0;
}

/* === BUTTONS === */
.btn, .btn-primary, .btn-secondary,
main button, .admin-container button {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-md);
  padding: 8px 16px;
  transition: all 0.15s ease;
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.btn-primary {
  background: var(--primary-600);
  color: white;
  border-color: var(--primary-600);
}

.btn-primary:hover {
  background: var(--primary-700);
}

.btn-secondary {
  background: white;
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background: var(--gray-50);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === INPUTS === */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="search"],
input[type="url"],
input[type="password"],
select,
textarea {
  background: white;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--gray-900);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  font-family: inherit;
  min-height: 40px;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: var(--shadow-focus);
}

input::placeholder,
textarea::placeholder {
  color: var(--gray-400);
}

input:disabled,
select:disabled,
textarea:disabled {
  background: var(--gray-50);
  color: var(--gray-400);
  cursor: not-allowed;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
}

/* === CARDS === */
.card, .stat-card, .table-card, .calendar-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

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

.stat-card {
  padding: 20px;
}

.stat-card .label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* === TOOLBAR === */
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 14px;
}

/* === TABLE === */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
  background: var(--gray-50);
}

.data-table td {
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: var(--gray-50);
}

/* Mobile table cards */
@media (max-width: 768px) {
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td {
    display: block;
    width: 100%;
  }
  .data-table tr {
    margin-bottom: 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
  }
  .data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .data-table td:last-child { border-bottom: none; }
  .data-table td::before {
    content: attr(data-label);
    font-weight: 500;
    color: var(--text-secondary);
  }
}

/* === BADGES === */
.badge, .status-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
}

.badge-blue, .status-badge-sent, .status-badge-partial { background: var(--primary-50); color: var(--primary-700); }
.badge-green, .status-badge-paid, .status-badge-accepted { background: #D1FAE5; color: #047857; }
.badge-yellow, .status-badge-pending, .status-badge-expired { background: #FEF3C7; color: #B45309; }
.badge-red, .status-badge-rejected { background: #FEF2F2; color: #DC2626; }
.badge-gray, .status-badge-draft { background: var(--gray-100); color: var(--gray-600); }
.badge-purple { background: #F3E8FF; color: #7C3AED; }

/* === MODAL === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
}

.modal-overlay.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: white;
  border-radius: var(--radius-xl);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

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

.modal-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
}

.modal-body {
  padding: 20px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
}

/* === FORM === */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* === EMPTY STATE === */
.empty-state {
  text-align: center;
  padding: 48px 20px;
}

.empty-state svg {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  margin: 0 auto 16px;
}

.empty-state h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 4px 0;
}

.empty-state p {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0;
}

/* === LOADING === */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary-600);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === MOBILE RESPONSIVE === */
@media (max-width: 768px) {
  .admin-container {
    padding: 16px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .toolbar {
    flex-direction: column;
  }

  .search-input, .filter-select {
    width: 100%;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  /* Touch targets */
  input, select, textarea, button, .btn {
    min-height: 44px;
  }

  /* Stats grid on mobile */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* === UTILITIES === */
.text-xs { font-size: 11px; }
.text-sm { font-size: 12px; }
.text-base { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 18px; }

.text-gray-400, .text-gray-500, .text-gray-600 { color: var(--text-muted); }
.text-gray-700, .text-gray-800, .text-gray-900 { color: var(--text-primary); }

.bg-white { background: white; }
.bg-gray-50 { background: var(--gray-50); }

.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }

.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }

.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }

/* === MOBILE BOTTOM NAVIGATION === */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  background: white;
  border-top: 1px solid var(--border-color);
  padding: 8px 0;
  z-index: 50;
  box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05);
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s ease;
  flex: 1;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.65rem;
  font-weight: 500;
}

.mobile-nav-item svg {
  width: 20px;
  height: 20px;
}

.mobile-nav-item.active {
  color: var(--primary-600);
}

@media (max-width: 1024px) {
  .mobile-bottom-nav {
    display: flex;
  }
  body {
    padding-bottom: 60px;
  }
}

/* Hide mobile footer on specific pages */
.hide-mobile-footer .mobile-bottom-nav {
  display: none !important;
}

/* ============================================
   DARK MODE (Manual Toggle)
   Applied when [data-theme="dark"] on html element
   ============================================ */
[data-theme="dark"] {
  --gray-50: #111827;
  --gray-100: #1F2937;
  --gray-200: #374151;
  --gray-300: #4B5563;
  --gray-400: #6B7280;
  --gray-500: #9CA3AF;
  --gray-600: #D1D5DB;
  --gray-700: #E5E7EB;
  --gray-800: #F3F4F6;
  --gray-900: #F9FAFB;

  --bg-card: #1F2937;
  --border-color: var(--gray-700);
  --text-primary: var(--gray-100);
  --text-secondary: var(--gray-300);
  --text-muted: var(--gray-500);
}

[data-theme="dark"] body {
  background: #0A0A0B;
  color: var(--text-primary);
}

[data-theme="dark"] .card,
[data-theme="dark"] .settings-card,
[data-theme="dark"] .content-card {
  background: var(--bg-card);
  border-color: var(--border-color);
}

[data-theme="dark"] .mobile-bottom-nav {
  background: #1F2937;
  border-top-color: var(--border-color);
}

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
  background: var(--gray-800);
  border-color: var(--border-color);
  color: var(--text-primary);
}

[data-theme="dark"] .btn-primary {
  background: var(--primary-600);
}

[data-theme="dark"] .btn-secondary {
  background: var(--gray-700);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.hide-mobile-footer body {
  padding-bottom: 0 !important;
}
