/* IMPORT GOOGLE FONTS */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:wght@400;500;600&display=swap');

:root {
  --color-bg: #f4f5f6;
  --color-surface: #ffffff;
  --color-text-main: #2b2b2b;
  --color-text-muted: #72777a;
  --color-primary: #111111;
  --color-gold: #c5a880;
  --color-border: #e3e5e6;
  --color-success: #20ba5a;
  --color-success-light: #e8f9ef;
  --color-warning: #f1a80a;
  --color-warning-light: #fef8eb;
  --color-error: #df4444;
  --color-error-light: #fdeded;
  
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-serif: 'Playfair Display', Georgia, serif;
  
  --transition-fast: all 0.2s ease;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.08);
  
  --border-radius: 4px;
}

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

html, body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

body {
  font-family: var(--font-sans);
  background-color: var(--color-bg);
  color: var(--color-text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* --- TOAST NOTIFICATIONS --- */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background-color: var(--color-primary);
  color: white;
  padding: 14px 24px;
  font-size: 0.9rem;
  box-shadow: var(--shadow-md);
  border-left: 4px solid var(--color-gold);
  border-radius: var(--border-radius);
  animation: slideIn 0.3s forwards cubic-bezier(0.25, 0.8, 0.25, 1);
}

@keyframes slideIn {
  from { transform: translateY(100px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* --- LOGIN SCREEN --- */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background-color: #faf7f5;
}

.login-card {
  background-color: var(--color-surface);
  width: 100%;
  max-width: 400px;
  padding: 40px 32px;
  border-radius: var(--border-radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.05);
  border: 1px solid rgba(235, 220, 208, 0.6);
}

.login-logo {
  font-family: var(--font-serif);
  font-size: 2.5rem;
  text-align: center;
  margin-bottom: 8px;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.login-subtitle {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-bottom: 32px;
}

/* --- ADMIN LAYOUT --- */
.admin-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ADMIN HEADER */
.admin-header {
  background-color: var(--color-primary);
  color: white;
  min-height: 64px;
  padding: 0 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.admin-brand {
  font-family: var(--font-serif);
  font-size: 1.45rem;
  letter-spacing: 0.04em;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.admin-brand-badge {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background-color: rgba(197, 168, 128, 0.2);
  color: var(--color-gold);
  border: 1px solid rgba(197, 168, 128, 0.4);
  padding: 2px 7px;
  border-radius: 4px;
}

.admin-user {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.9rem;
}

#currentUserEmail {
  font-size: 0.88rem;
  opacity: 0.85;
}

.btn-logout {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.22);
  color: white;
  padding: 7px 14px;
  font-size: 0.82rem;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn-logout:hover {
  background-color: white;
  color: var(--color-primary);
}

/* ADMIN BODY */
.admin-body {
  display: flex;
  flex-grow: 1;
}

/* SIDEBAR */
.admin-sidebar {
  width: 250px;
  background-color: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 30px 10px;
  flex-shrink: 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
}

.sidebar-footer {
  margin-top: auto;
  padding: 20px 0 0 0;
}

.nav-item {
  background: none;
  border: none;
  text-align: left;
  padding: 12px 16px;
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--color-text-muted);
  border-radius: var(--border-radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: var(--transition-fast);
  width: 100%;
}

.nav-item svg {
  opacity: 0.7;
}

.nav-item:hover {
  background-color: var(--color-bg);
  color: var(--color-primary);
}

.nav-item.active {
  background-color: #faf7f5;
  color: var(--color-primary);
  font-weight: 600;
  border-left: 3px solid var(--color-gold);
  border-radius: 0 var(--border-radius) var(--border-radius) 0;
}

.nav-item.active svg {
  color: var(--color-gold);
  opacity: 1;
}

/* MAIN CONTENT */
.admin-content {
  flex-grow: 1;
  padding: 36px 40px;
  background-color: var(--color-bg);
  overflow-x: hidden;
  min-width: 0;
}

.tab-content {
  display: none;
}

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

.tab-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 26px;
  gap: 16px;
}

.tab-header-titles {
  min-width: 0;
}

.tab-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.tab-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.tab-subtitle {
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

/* CARDS & TABLES */
.card {
  background-color: var(--color-surface);
  border-radius: var(--border-radius);
  padding: 30px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  margin-bottom: 30px;
}

.card.table-card {
  padding: 0;
  overflow: hidden;
  border-radius: var(--border-radius);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

/* Custom subtle scrollbar for tables */
.table-responsive::-webkit-scrollbar {
  height: 6px;
}

.table-responsive::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.table-responsive::-webkit-scrollbar-thumb {
  background: #d4cdc5;
  border-radius: 3px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
  background: var(--color-gold);
}

/* FORM FIELDS */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

.form-input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--color-border);
  padding: 10px 14px;
  border-radius: var(--border-radius);
  outline: none;
  background-color: var(--color-surface);
  transition: var(--transition-fast);
}

.form-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.03);
}

/* BUTTONS */
.btn-primary {
  background-color: var(--color-primary);
  color: white;
  border: 1px solid var(--color-primary);
  padding: 12px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-primary:hover {
  background-color: var(--color-gold);
  border-color: var(--color-gold);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-cancel {
  background-color: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  padding: 12px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-cancel:hover {
  background-color: var(--color-bg);
  color: var(--color-text-main);
}

/* DATA TABLE */
.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th,
.data-table td {
  padding: 16px 24px;
  border-bottom: 1px solid var(--color-border);
}

.data-table th {
  background-color: #fafafa;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}

.data-table tbody tr:hover {
  background-color: #fafafb;
}

.table-img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 2px;
  background-color: var(--color-bg);
}

.tag-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  display: inline-block;
  margin-right: 4px;
}

.tag-badge.promo {
  background-color: var(--color-gold);
  color: white;
}

.tag-badge.new {
  background-color: var(--color-primary);
  color: white;
}

/* ORDER STATUS BADGES */
.status-select {
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 20px;
  border: 1px solid var(--color-border);
  outline: none;
  cursor: pointer;
}

.status-select.Nouvelle {
  background-color: var(--color-warning-light);
  color: var(--color-warning);
  border-color: var(--color-warning);
}

.status-select.Confirmée {
  background-color: #eef2ef; /* sage */
  color: #4e6e58;
  border-color: #4e6e58;
}

.status-select.Livrée {
  background-color: var(--color-success-light);
  color: var(--color-success);
  border-color: var(--color-success);
}

.status-select.Annulée {
  background-color: var(--color-error-light);
  color: var(--color-error);
  border-color: var(--color-error);
}

/* ACTION BUTTONS (CRUD) */
.btn-action {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  transition: var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-action.edit {
  color: var(--color-gold-dark);
}

.btn-action.edit:hover {
  background-color: var(--color-gold-light);
}

.btn-action.delete {
  color: var(--color-error);
}

.btn-action.delete:hover {
  background-color: var(--color-error-light);
}

/* FORM & MODAL UTILITIES */
.price-preview-box {
  background-color: var(--color-gold-light);
  padding: 12px 18px;
  border-radius: var(--border-radius);
  margin-bottom: 20px;
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-left: 3px solid var(--color-gold);
  gap: 8px;
}

.price-preview-box #calculatedPricePreview {
  font-weight: 700;
  color: var(--color-primary);
  font-size: 1.05rem;
  white-space: nowrap;
}

.form-textarea {
  height: 100px;
  resize: vertical;
}

.help-text {
  display: block;
  margin-top: 5px;
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

.tags-checkbox-group {
  display: flex;
  gap: 20px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

/* GRID LAYOUTS */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
}

/* MODAL BOX */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition-fast);
  padding: 20px;
}

.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background-color: var(--color-surface);
  width: 100%;
  max-width: 650px;
  max-height: 94vh;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transform: scale(0.95);
  transition: var(--transition-fast);
  display: flex;
  flex-direction: column;
}

.modal-content form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex-grow: 1;
  overflow: hidden;
}

.modal-backdrop.open .modal-content {
  transform: scale(1);
}

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

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  min-width: 36px;
  min-height: 36px;
}

.close-btn:hover {
  background-color: var(--color-bg);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex-grow: 1;
  min-height: 0;
  max-height: calc(94vh - 140px);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background-color: #fafafa;
  flex-shrink: 0;
}

/* ====================================================
   RESPONSIVE DESIGN BREAKPOINTS
   ==================================================== */

/* Tablet & Mobile Breakpoint (<= 900px) */
@media (max-width: 900px) {
  .admin-header {
    height: auto;
    min-height: 58px;
    padding: 10px 16px;
  }
  
  .admin-body {
    flex-direction: column;
  }
  
  .admin-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    padding: 8px 12px;
    position: sticky;
    top: 58px;
    z-index: 90;
    background-color: var(--color-surface);
    box-shadow: 0 2px 6px rgba(0,0,0,0.03);
  }
  
  .sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 8px;
    align-items: center;
  }
  
  .sidebar-nav::-webkit-scrollbar {
    display: none;
  }
  
  .sidebar-nav .nav-item {
    white-space: nowrap;
    width: auto;
    flex-shrink: 0;
    padding: 8px 14px;
    font-size: 0.88rem;
    border-radius: 20px;
    border: 1px solid transparent;
  }
  
  .sidebar-nav .nav-item.active {
    background-color: var(--color-primary);
    color: white;
    border-left: none;
    border-radius: 20px;
  }
  
  .sidebar-nav .nav-item.active svg {
    color: var(--color-gold);
  }
  
  .sidebar-footer {
    margin-top: 0;
    padding: 0;
    margin-left: auto;
    flex-shrink: 0;
  }
  
  .sidebar-footer .nav-item-shop {
    border: 1px dashed var(--color-border);
    border-radius: 20px;
    padding: 7px 12px;
    font-size: 0.82rem;
  }
  
  .admin-content {
    padding: 20px 16px;
  }
  
  .grid-2 {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  /* Tables on Tablet/Mobile: Ensure readable min-widths and Sticky Actions/Status Column */
  #productsTable {
    min-width: 680px;
  }
  
  #ordersTable {
    min-width: 760px;
  }
  
  .data-table th.col-actions,
  .data-table td:last-child {
    position: sticky;
    right: 0;
    background-color: var(--color-surface);
    box-shadow: -4px 0 8px rgba(0,0,0,0.05);
    z-index: 2;
  }
  
  .data-table th.col-actions,
  .data-table th.col-status {
    position: sticky;
    right: 0;
    background-color: #fafafa;
    box-shadow: -4px 0 8px rgba(0,0,0,0.05);
    z-index: 2;
  }
  
  .data-table tbody tr:hover td:last-child {
    background-color: #fafafb;
  }
  
  .data-table th,
  .data-table td {
    padding: 12px 14px;
    font-size: 0.88rem;
  }
}

/* Mobile Breakpoint (<= 768px) */
@media (max-width: 768px) {
  .tab-header {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    margin-bottom: 20px;
  }
  
  .tab-title {
    font-size: 1.5rem;
  }
  
  .tab-header-actions {
    width: 100%;
    display: flex;
    gap: 10px;
  }
  
  .tab-header-actions .btn-action-bulk,
  .tab-header-actions .btn-action-add {
    flex: 1 1 0;
    min-width: 0;
    padding: 11px 12px;
    font-size: 0.86rem;
    text-align: center;
    justify-content: center;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }
  
  .btn-action {
    padding: 8px;
    min-width: 38px;
    min-height: 38px;
  }
  
  .status-select {
    min-height: 38px;
    padding: 6px 10px;
  }
}

/* Small Mobile Breakpoint (<= 540px) */
@media (max-width: 540px) {
  .admin-header {
    padding: 10px 12px;
    min-height: 54px;
  }
  
  .admin-brand {
    font-size: 1.25rem;
  }
  
  .admin-brand-badge {
    font-size: 0.65rem;
    padding: 1px 5px;
  }
  
  #currentUserEmail {
    display: none; /* Hide email on small phones to keep header uncluttered */
  }
  
  .btn-logout {
    padding: 6px 10px;
    font-size: 0.78rem;
    min-height: 36px;
  }
  
  .logout-text {
    font-size: 0.75rem;
  }
  
  .admin-content {
    padding: 16px 10px;
  }
  
  .card {
    padding: 18px 14px;
    margin-bottom: 20px;
  }
  
  .card.table-card {
    padding: 0;
  }
  
  /* Modals on small mobile */
  .modal-backdrop {
    padding: 8px;
  }
  
  .modal-content {
    max-height: 94vh;
  }
  
  .modal-header {
    padding: 14px 16px;
  }
  
  .modal-header h2 {
    font-size: 1.15rem;
  }
  
  .modal-body {
    padding: 14px 16px;
    max-height: calc(94vh - 125px);
  }
  
  .modal-footer {
    flex-direction: column-reverse;
    gap: 8px;
    padding: 12px 16px;
  }
  
  .modal-footer button {
    width: 100%;
    height: 46px;
  }
  
  .form-input {
    height: 46px;
    font-size: 16px; /* Prevents auto-zoom on iOS Safari */
  }
  
  .btn-primary, .btn-cancel {
    min-height: 44px;
  }
  
  /* Toast notifications */
  .toast-container {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
  }
  
  .toast {
    padding: 12px 18px;
    font-size: 0.85rem;
    text-align: center;
  }
  
  /* Login screen */
  .login-card {
    padding: 28px 18px;
  }
  
  .login-logo {
    font-size: 2.1rem;
  }
}

/* Extra Small Phones (<= 360px) */
@media (max-width: 360px) {
  .admin-header {
    padding: 8px 10px;
  }
  
  .admin-brand {
    font-size: 1.15rem;
  }
  
  .tab-header-actions {
    flex-direction: column;
  }
  
  .tab-header-actions .btn-action-bulk,
  .tab-header-actions .btn-action-add {
    width: 100%;
  }
  
  .sidebar-nav .nav-item {
    padding: 6px 10px;
    font-size: 0.8rem;
  }
}
