/* =========================================================================
   QuincaGest-Cloud — Feuille de style principale
   ========================================================================= */

:root {
  --qgc-primary: #1e5631;
  --qgc-primary-dark: #143d22;
  --qgc-primary-light: #e6f2ea;
  --qgc-accent: #d97706;
  --qgc-danger: #dc2626;
  --qgc-bg: #f4f6f5;
  --qgc-card-bg: #ffffff;
  --qgc-border: #e2e6e4;
  --qgc-text: #1f2937;
  --qgc-text-muted: #6b7280;
  --sidebar-width: 250px;
  --topbar-height: 64px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--qgc-bg);
  color: var(--qgc-text);
}

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

/* ---------------------------- Layout global ----------------------------- */

#qgc-app-shell {
  display: flex;
  min-height: 100vh;
}

#qgc-sidebar {
  width: var(--sidebar-width);
  background: var(--qgc-primary-dark);
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform .25s ease;
}

#qgc-sidebar .sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
#qgc-sidebar .sidebar-brand .logo-icon {
  width: 36px; height: 36px;
  background: var(--qgc-accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
#qgc-sidebar .sidebar-brand .brand-text { font-weight: 700; font-size: 16px; line-height: 1.2; }
#qgc-sidebar .sidebar-brand .brand-sub { font-size: 11px; color: rgba(255,255,255,.6); }

#qgc-sidebar nav { padding: 10px 0; flex: 1; }
#qgc-sidebar .nav-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: rgba(255,255,255,.4); padding: 14px 20px 6px;
}
#qgc-sidebar .nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; font-size: 14px; color: rgba(255,255,255,.85);
  border-left: 3px solid transparent;
  cursor: pointer;
}
#qgc-sidebar .nav-link:hover { background: rgba(255,255,255,.06); }
#qgc-sidebar .nav-link.active {
  background: rgba(255,255,255,.1);
  border-left-color: var(--qgc-accent);
  color: #fff; font-weight: 600;
}
#qgc-sidebar .nav-link i { width: 18px; text-align: center; }

#qgc-main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#qgc-topbar {
  height: var(--topbar-height);
  background: #fff;
  border-bottom: 1px solid var(--qgc-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
}
#qgc-topbar .page-title { font-size: 18px; font-weight: 700; color: var(--qgc-primary-dark); }
#qgc-topbar .user-box { display: flex; align-items: center; gap: 12px; }
#qgc-topbar .user-info { text-align: right; }
#qgc-topbar .user-name { font-size: 13px; font-weight: 600; }
#qgc-topbar .user-role { font-size: 11px; color: var(--qgc-text-muted); }
#qgc-topbar .user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--qgc-primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
#qgc-topbar .btn-logout {
  background: none; border: 1px solid var(--qgc-border);
  padding: 7px 14px; border-radius: 6px; cursor: pointer; font-size: 13px;
  color: var(--qgc-text-muted);
}
#qgc-topbar .btn-logout:hover { background: #fee2e2; color: var(--qgc-danger); border-color: #fecaca; }

.shop-selector {
  display: flex; align-items: center; gap: 8px;
  background: var(--qgc-primary-light); color: var(--qgc-primary-dark);
  padding: 6px 12px; border-radius: 7px; font-size: 12.5px; font-weight: 600;
}
.shop-selector select {
  border: none; background: transparent; color: var(--qgc-primary-dark);
  font-weight: 600; font-size: 12.5px; cursor: pointer; outline: none;
}
.shop-selector-single { cursor: default; }

#qgc-sidebar-toggle {
  display: none;
  background: none; border: none; font-size: 20px; cursor: pointer;
}

#qgc-content { padding: 24px; flex: 1; }

/* ------------------------------- Cartes --------------------------------- */

.card {
  background: var(--qgc-card-bg);
  border: 1px solid var(--qgc-border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}
.card-title {
  font-size: 15px; font-weight: 700; margin: 0 0 16px;
  display: flex; align-items: center; justify-content: space-between;
  color: var(--qgc-primary-dark);
}

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi-card {
  background: #fff; border: 1px solid var(--qgc-border); border-radius: 10px;
  padding: 18px; display: flex; align-items: center; gap: 14px;
}
.kpi-card .kpi-icon {
  width: 46px; height: 46px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 20px; color: #fff;
}
.kpi-card .kpi-value { font-size: 22px; font-weight: 800; color: var(--qgc-text); }
.kpi-card .kpi-label { font-size: 12px; color: var(--qgc-text-muted); }

/* ------------------------------- Boutons -------------------------------- */

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 7px; font-size: 14px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; transition: .15s;
}
.btn-primary { background: var(--qgc-primary); color: #fff; }
.btn-primary:hover { background: var(--qgc-primary-dark); }
.btn-accent { background: var(--qgc-accent); color: #fff; }
.btn-accent:hover { background: #b45f04; }
.btn-outline { background: #fff; border-color: var(--qgc-border); color: var(--qgc-text); }
.btn-outline:hover { background: #f3f4f6; }
.btn-danger { background: var(--qgc-danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ------------------------------- Formulaires ----------------------------- */

.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--qgc-text); }
.form-control {
  width: 100%; padding: 9px 12px; border: 1px solid var(--qgc-border); border-radius: 7px;
  font-size: 14px; background: #fff; color: var(--qgc-text);
}
.form-control:focus { outline: none; border-color: var(--qgc-primary); box-shadow: 0 0 0 3px var(--qgc-primary-light); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
textarea.form-control { resize: vertical; min-height: 70px; }

/* -------------------------------- Tableaux ------------------------------- */

.table-wrap { overflow-x: auto; }
table.qgc-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.qgc-table th {
  text-align: left; padding: 10px 12px; background: #f9fafb;
  font-weight: 700; color: var(--qgc-text-muted); text-transform: uppercase; font-size: 11px;
  border-bottom: 2px solid var(--qgc-border); white-space: nowrap;
}
table.qgc-table td { padding: 10px 12px; border-bottom: 1px solid var(--qgc-border); vertical-align: middle; }
table.qgc-table tr:hover td { background: #fafbfa; }
table.qgc-table .row-actions { display: flex; gap: 6px; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700;
}
.badge-green { background: #dcfce7; color: #15803d; }
.badge-yellow { background: #fef9c3; color: #92400e; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-gray { background: #f3f4f6; color: #4b5563; }

/* -------------------------------- Modale --------------------------------- */

.qgc-modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(15,23,20,.55);
  z-index: 1000; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.qgc-modal-overlay.open { display: flex; }
.qgc-modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 640px;
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.qgc-modal.modal-lg { max-width: 900px; }
.qgc-modal-header {
  padding: 18px 22px; border-bottom: 1px solid var(--qgc-border);
  display: flex; align-items: center; justify-content: space-between;
}
.qgc-modal-header h3 { margin: 0; font-size: 16px; color: var(--qgc-primary-dark); }
.qgc-modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--qgc-text-muted); }
.qgc-modal-body { padding: 22px; max-height: 70vh; overflow-y: auto; }
.qgc-modal-footer { padding: 16px 22px; border-top: 1px solid var(--qgc-border); display: flex; justify-content: flex-end; gap: 10px; }

/* ------------------------------ Filtres / recherche ------------------------ */

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; justify-content: space-between; }
.toolbar .toolbar-left { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search-box { position: relative; }
.search-box input { padding-left: 34px; min-width: 220px; }
.search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--qgc-text-muted); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--qgc-text-muted); }
.empty-state i { font-size: 40px; margin-bottom: 12px; opacity: .4; }

/* ------------------------------- Login ------------------------------------ */

.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--qgc-primary-dark), var(--qgc-primary));
  padding: 20px;
}
.login-card {
  background: #fff; border-radius: 14px; padding: 36px 32px; width: 100%; max-width: 400px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.login-card .logo-block { text-align: center; margin-bottom: 24px; }
.login-card .logo-block .icon { font-size: 40px; color: var(--qgc-primary); }
.login-card .logo-block h1 { font-size: 20px; margin: 8px 0 2px; color: var(--qgc-primary-dark); }
.login-card .logo-block p { font-size: 12.5px; color: var(--qgc-text-muted); margin: 0; }
.login-hint { margin-top: 18px; padding: 12px 14px; background: var(--qgc-primary-light); border-radius: 8px; font-size: 12px; color: #14532d; }
.login-error { background: #fee2e2; color: #b91c1c; padding: 10px 12px; border-radius: 7px; font-size: 13px; margin-bottom: 14px; display: none; }

/* -------------------------------- Print ------------------------------------ */

.print-only { display: none; }

@media print {
  #qgc-sidebar, #qgc-topbar, .no-print { display: none !important; }
  #qgc-main { margin-left: 0 !important; }
  #qgc-content { padding: 0 !important; }
  body { background: #fff !important; }
}

.print-sheet {
  background: #fff; max-width: 210mm; margin: 0 auto; padding: 14mm;
  border: 1px solid var(--qgc-border); border-radius: 6px;
}
.doc-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid var(--qgc-primary); padding-bottom: 16px; margin-bottom: 20px; }
.doc-header .company-block { display: flex; gap: 14px; align-items: center; }
.doc-header .company-logo { width: 64px; height: 64px; border-radius: 8px; object-fit: contain; background: var(--qgc-primary-light); }
.doc-header .company-logo-fallback {
  width: 64px; height: 64px; border-radius: 8px; background: var(--qgc-primary);
  color: #fff; display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 800;
}
.doc-header .company-name { font-size: 18px; font-weight: 800; color: var(--qgc-primary-dark); margin: 0; }
.doc-header .company-meta { font-size: 11.5px; color: var(--qgc-text-muted); line-height: 1.5; }
.doc-header .doc-type-block { text-align: right; }
.doc-header .doc-type { font-size: 20px; font-weight: 800; color: var(--qgc-accent); text-transform: uppercase; }
.doc-header .doc-number { font-size: 13px; color: var(--qgc-text-muted); }

.doc-meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.doc-meta-box { background: #f9fafb; border-radius: 8px; padding: 12px 14px; font-size: 12.5px; }
.doc-meta-box h4 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; color: var(--qgc-text-muted); }

.doc-signature-row { display: flex; justify-content: space-between; margin-top: 40px; }
.doc-signature-box { width: 45%; text-align: center; font-size: 12px; color: var(--qgc-text-muted); }
.doc-signature-box .sign-line { border-top: 1px solid var(--qgc-text-muted); margin-top: 50px; padding-top: 6px; }

.doc-footer { margin-top: 26px; padding-top: 12px; border-top: 1px solid var(--qgc-border); font-size: 11px; color: var(--qgc-text-muted); text-align: center; }

/* -------------------------------- Responsive ------------------------------- */

@media (max-width: 900px) {
  #qgc-sidebar { transform: translateX(-100%); }
  #qgc-sidebar.open { transform: translateX(0); }
  #qgc-main { margin-left: 0; }
  #qgc-sidebar-toggle { display: inline-flex; }
  .doc-meta-grid { grid-template-columns: 1fr; }
}

/* -------------------------------- Assistant IA -------------------------------- */
#assistant-widget { position: fixed; bottom: 24px; right: 24px; z-index: 500; }
#assistant-fab {
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--qgc-primary); color: #fff; font-size: 22px; cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); display: flex; align-items: center; justify-content: center;
  position: relative;
}
#assistant-fab:hover { background: var(--qgc-primary-dark); }
.assistant-bell-count {
  position: absolute; top: -4px; right: -4px; background: var(--qgc-danger); color: #fff;
  font-size: 11px; font-weight: 800; min-width: 20px; height: 20px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
  border: 2px solid #fff;
}
.assistant-panel {
  position: absolute; bottom: 68px; right: 0; width: 360px; max-height: 520px;
  background: var(--qgc-card-bg); border: 1px solid var(--qgc-border); border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25); display: none; flex-direction: column; overflow: hidden;
}
.assistant-panel.open { display: flex; }
.assistant-tabs { display: flex; align-items: center; border-bottom: 1px solid var(--qgc-border); background: #fafafa; }
.assistant-tab {
  flex: 1; border: none; background: none; padding: 12px 10px; font-size: 13px; font-weight: 600;
  color: var(--qgc-text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;
  border-bottom: 2px solid transparent;
}
.assistant-tab.active { color: var(--qgc-primary); border-bottom-color: var(--qgc-primary); }
#assistant-close { border: none; background: none; font-size: 18px; color: var(--qgc-text-muted); cursor: pointer; padding: 0 12px; }
.assistant-tab-content { flex: 1; overflow-y: auto; max-height: 440px; }

.assistant-notif-list { padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.assistant-empty { padding: 24px; text-align: center; color: var(--qgc-text-muted); font-size: 13px; }
.assistant-notif { display: flex; gap: 10px; padding: 10px; border: 1px solid var(--qgc-border); border-radius: 10px; position: relative; background: #fff; }
.assistant-notif-icon { font-size: 18px; padding-top: 2px; }
.assistant-notif-body { flex: 1; min-width: 0; }
.assistant-notif-title { font-size: 13px; font-weight: 700; color: var(--qgc-text); }
.assistant-notif-message { font-size: 12px; color: var(--qgc-text-muted); margin-top: 2px; }
.assistant-notif-link { font-size: 12px; font-weight: 600; color: var(--qgc-primary); display: inline-block; margin-top: 4px; }
.assistant-notif-dismiss { border: none; background: none; color: var(--qgc-text-muted); font-size: 16px; cursor: pointer; align-self: flex-start; }
.assistant-notif-dismiss:hover { color: var(--qgc-danger); }

.assistant-chat-log { padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 260px; }
.assistant-chat-msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.4; white-space: pre-wrap; }
.assistant-chat-bot { background: var(--qgc-primary-light); color: var(--qgc-text); align-self: flex-start; }
.assistant-chat-user { background: var(--qgc-primary); color: #fff; align-self: flex-end; }
.assistant-chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--qgc-border); }
.assistant-chat-form .form-control { flex: 1; }

@media (max-width: 900px) {
  #assistant-widget { bottom: 16px; right: 16px; }
  .assistant-panel { width: calc(100vw - 32px); right: -8px; }
}
