/* ============================================================
   STYLE - Comestaz Stock
   ============================================================ */

:root {
  --primary:       #2e7d32;
  --primary-dark:  #1a5c1e;
  --primary-light: #e8f5e9;
  --accent:        #f9a825;
  --bg:            #f0f2f0;
  --surface:       #ffffff;
  --text:          #1a2420;
  --text-light:    #6b7a70;
  --border:        #dde4dd;
  --danger:        #c62828;
  --danger-light:  #fdecea;
  --warning-light: #fff8e1;
  --success-light: #e8f5e9;
  --radius:        8px;
  --radius-lg:     12px;
  --shadow:        0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:     0 4px 12px rgba(0,0,0,0.1);
  --sidebar-w:     240px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 0.95rem;
}

/* ── Sidebar layout ─────────────────────────────────────────── */

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

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 98;
}
.sidebar-overlay.open { display: block; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--primary-dark);
  color: white;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 99;
  transition: transform 0.25s ease;
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  font-size: 1rem;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}
.sidebar-logo .logo-icon { font-size: 1.3rem; }
.sidebar-close {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-section {
  padding: 14px 20px 4px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.4);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: white; }
.nav-item.active {
  background: rgba(255,255,255,0.13);
  color: white;
  border-left-color: var(--accent);
  font-weight: 600;
}
.nav-item-danger { color: rgba(255,120,120,0.85); }
.nav-item-danger:hover { background: rgba(255,100,100,0.1); color: #ff8a80; }

.nav-icon { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }

.sidebar-footer {
  padding: 12px 0;
  border-top: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.6);
}
.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* ── Main content ───────────────────────────────────────────── */

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
  gap: 12px;
}

.page-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hamburger {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text);
}

.page-body {
  padding: 24px;
  flex: 1;
}

/* ── Stat cards ─────────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.stat-card.stat-danger { border-left-color: var(--danger); }
.stat-card.stat-warning { border-left-color: var(--accent); }
.stat-card.stat-info   { border-left-color: #1565c0; }

.stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
  margin-bottom: 6px;
}
.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

/* ── Data table ─────────────────────────────────────────────── */

.data-table-wrapper {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-toolbar {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.table-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.filters-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
}

.filters-row input,
.filters-row select {
  width: auto;
  flex: 1;
  min-width: 140px;
  max-width: 260px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  background: var(--surface);
  color: var(--text);
}
.filters-row input:focus,
.filters-row select:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.table-scroll { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  padding: 11px 14px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-light);
  background: #f7f9f7;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-table th.sortable {
  cursor: pointer;
  user-select: none;
}
.data-table th.sortable:hover { background: #eef1ee; color: var(--text); }
.data-table th.sort-asc .sort-icon::after  { content: ' ↑'; color: var(--primary); }
.data-table th.sort-desc .sort-icon::after { content: ' ↓'; color: var(--primary); }
.data-table th .sort-icon::after { content: ' ↕'; opacity: 0.4; }

.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f7faf7; }

.table-empty {
  text-align: center;
  color: var(--text-light);
  padding: 48px 16px;
}

.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-mono   { font-family: monospace; font-size: 0.82rem; }

/* Photo miniature dans table */
.photo-thumb {
  width: 38px; height: 38px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}
.photo-placeholder {
  width: 38px; height: 38px;
  background: #f0f2f0;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--text-light);
}

/* Lien article dans table */
.article-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}
.article-link:hover { color: var(--primary); text-decoration: underline; }

/* Boutons action */
.action-btns { display: flex; gap: 5px; }

.btn-icon {
  padding: 5px 9px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.4;
  transition: opacity 0.15s;
  white-space: nowrap;
}
.btn-icon:hover { opacity: 0.8; }
.btn-icon-view   { background: var(--success-light); color: var(--primary); }
.btn-icon-edit   { background: #e3f2fd; color: #1565c0; }
.btn-icon-delete { background: var(--danger-light); color: var(--danger); }

/* Stock pills */
.stock-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.73rem;
  font-weight: 700;
  white-space: nowrap;
}
.stock-ok  { background: var(--success-light); color: var(--primary); }
.stock-low { background: var(--danger-light);  color: var(--danger); }
.stock-mid { background: var(--warning-light); color: #b45309; }

/* ── Modales ─────────────────────────────────────────────────── */

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.open { display: flex; }

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-box.modal-sm { max-width: 420px; }

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.modal-header h3 { font-size: 1rem; font-weight: 700; margin: 0; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-light); font-size: 1.2rem; padding: 4px;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

/* ── Formulaires (partagé) ───────────────────────────────────── */

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 4px;
  margin-top: 14px;
}
label:first-child { margin-top: 0; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(46,125,50,0.12);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}

/* ── Boutons ─────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn:active { opacity: 0.8; }
.btn-primary   { background: var(--primary); color: white; }
.btn-primary:hover { box-shadow: 0 2px 8px rgba(46,125,50,0.35); }
.btn-secondary { background: #eceeec; color: var(--text); }
.btn-secondary:hover { background: #e0e4e0; }
.btn-danger    { background: var(--danger); color: white; }
.btn-danger:hover { box-shadow: 0 2px 8px rgba(198,40,40,0.35); }
.btn-accent    { background: var(--accent); color: #2b2200; }
.btn-ghost     { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-block     { width: 100%; margin-top: 14px; }
.btn-sm        { padding: 7px 12px; font-size: 0.82rem; }

/* ── Photo upload ────────────────────────────────────────────── */

.photo-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
}
.photo-upload-area:hover { border-color: var(--primary); }
.photo-upload-area input[type=file] { display: none; }

.photo-preview-large {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: var(--radius);
  display: block;
  margin-bottom: 8px;
}

.photo-preview-edit {
  width: 80px; height: 80px;
  object-fit: cover;
  border-radius: var(--radius);
}

/* ── Cards (compat) ──────────────────────────────────────────── */

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

/* ── Article detail ──────────────────────────────────────────── */

.article-photo-hero {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  display: block;
}

.article-photo-placeholder {
  background: #f0f2f0;
  height: 120px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  color: var(--text-light);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin: 16px 0;
}

.detail-cell { }
.detail-cell .cell-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-light);
  margin-bottom: 3px;
  font-weight: 600;
}
.detail-cell .cell-value {
  font-size: 1.1rem;
  font-weight: 700;
}

.stock-big {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}

/* ── Scanner modal ───────────────────────────────────────────── */

#scanner-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
  flex-direction: column;
  gap: 16px;
}
#scanner-modal.open { display: flex; }
#qr-reader {
  width: 90vw;
  max-width: 420px;
  border-radius: var(--radius);
  overflow: hidden;
}
.scanner-close {
  background: white;
  border: none;
  padding: 12px 28px;
  border-radius: var(--radius);
  font-weight: 700;
  cursor: pointer;
  font-size: 0.95rem;
}

/* ── QR code ─────────────────────────────────────────────────── */

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px;
  background: #fafbfa;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ── Login ───────────────────────────────────────────────────── */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 36px 28px;
  text-align: center;
}
.login-card .logo   { font-size: 1.5rem; font-weight: 800; color: var(--primary); margin-bottom: 4px; }
.login-card .subtitle { color: var(--text-light); font-size: 0.85rem; margin-bottom: 28px; }

/* ── Utilitaires ─────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  color: var(--text-light);
  padding: 48px 16px;
}
.error-text   { color: var(--danger); font-size: 0.85rem; }
.success-text { color: var(--primary); font-size: 0.85rem; }
.flex-row     { display: flex; flex-direction: row; }
.gap-8        { gap: 8px; }
.align-center { align-items: center; }
.mt-16        { margin-top: 16px; }

.article-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.article-row:last-child { border-bottom: none; }
.article-title { font-weight: 600; }
.article-meta  { font-size: 0.8rem; color: var(--text-light); }

/* ── Responsive mobile ───────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.25);
  }
  .sidebar-close { display: block; }
  .main-content  { margin-left: 0; }
  .hamburger     { display: flex; }
  .page-body     { padding: 16px; }
  .stats-grid    { grid-template-columns: 1fr 1fr; }
  .filters-row input, .filters-row select { max-width: 100%; }
  .modal-box     { max-height: 95vh; }
  .field-grid    { grid-template-columns: 1fr; }
}
