/* ============================================================
   B2B Admin Dashboard — Souleyrol
   ============================================================ */

:root {
  --green-dark:   #2d6a4f;
  --green-main:   #40916c;
  --green-light:  #d8f3dc;
  --green-pale:   #f0faf4;
  --text:         #1a1a1a;
  --text-muted:   #888;
  --border:       #e0e0e0;
  --surface:      #f8f9fa;
  --surface2:     #f1f3f1;
  --danger:       #c0392b;
  --accent:       #2980b9;
  --radius:       8px;
  --shadow:       0 2px 8px rgba(0,0,0,.08);
}

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

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

/* ---- Login ---- */
#login-screen {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--green-dark);
}
#login-screen.active { display: flex; }

.login-box {
  background: #fff;
  border-radius: 12px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.login-box h1 {
  font-size: 1.4rem;
  color: var(--green-dark);
  margin-bottom: .25rem;
}
.login-box p {
  color: var(--text-muted);
  font-size: .88rem;
  margin-bottom: 1.5rem;
}

/* ---- App layout ---- */
#app {
  display: none;
  flex-direction: column;
  min-height: 100vh;
}
#app.active { display: flex; }

/* ---- Top bar ---- */
#topbar {
  background: var(--green-dark);
  color: #fff;
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .55rem 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.topbar-brand {
  font-size: .95rem;
  font-weight: 700;
  white-space: nowrap;
}

#admin-nav {
  display: flex;
  gap: .2rem;
  flex: 1;
  overflow-x: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
#admin-nav::-webkit-scrollbar { display: none; }

.nav-tab {
  background: rgba(255,255,255,.1);
  border: none;
  color: rgba(255,255,255,.75);
  padding: .32rem .8rem;
  border-radius: 5px;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav-tab:hover  { background: rgba(255,255,255,.2); color: #fff; }
.nav-tab.active { background: rgba(255,255,255,.22); color: #fff; font-weight: 700; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-left: auto;
}
.topbar-user { font-size: .8rem; opacity: .8; white-space: nowrap; }

.btn-logout {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  padding: .3rem .65rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: .88rem;
}
.btn-logout:hover { background: rgba(255,255,255,.25); }

/* ---- Main content ---- */
#main-content {
  flex: 1;
  padding: 1.25rem;
  max-width: 1150px;
  margin: 0 auto;
  width: 100%;
}

/* ---- Section header ---- */
.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.section-title    { font-size: 1.2rem; font-weight: 700; }
.section-subtitle { font-size: .85rem; color: var(--text-muted); margin-top:.2rem; }

/* ---- Sub-tabs ---- */
.sub-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--border);
}
.sub-tab {
  background: none;
  border: none;
  padding: .45rem 1.1rem;
  cursor: pointer;
  font-size: .88rem;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.sub-tab:hover  { color: var(--green-main); }
.sub-tab.active { color: var(--green-dark); font-weight: 700; border-bottom-color: var(--green-dark); }

/* ---- Alert bar ---- */
.alert-bar {
  background: #fff3e0;
  border-left: 3px solid #e67e22;
  color: #a04000;
  padding: .5rem .85rem;
  border-radius: 4px;
  font-size: .85rem;
  margin-bottom: .75rem;
}

/* ---- Toolbar ---- */
.toolbar {
  display: flex;
  gap: .5rem;
  margin-bottom: .75rem;
  flex-wrap: wrap;
  align-items: center;
}
.toolbar input[type="search"],
.toolbar select {
  flex: 1;
  min-width: 140px;
  max-width: 240px;
  padding: .42rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .88rem;
  background: #fff;
}

/* ---- Table ---- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}
thead th {
  background: var(--surface2);
  padding: .55rem .85rem;
  text-align: left;
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: .5rem .85rem;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }

.cat-root-hdr td, .cat-sub-hdr td { padding-top: .55rem; padding-bottom: .55rem; }
.cat-prod-row:hover td { background: #f9fcf9; }
.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: #f5fbf7; }

.table-footer-total {
  text-align: right;
  padding: .6rem .85rem;
  font-size: .85rem;
  color: var(--text-muted);
}

/* ---- Utility column classes ---- */
.id-col      { color: var(--text-muted); font-size: .8rem; }
.center-col  { text-align: center; }
.right-col   { text-align: right; }
.empty-cell  { text-align: center; padding: 2rem; color: var(--text-muted); }
.actions-col { white-space: nowrap; }
.text-muted  { color: var(--text-muted); }

/* ---- Status badge ---- */
.status-badge {
  display: inline-block;
  padding: .18rem .55rem;
  border-radius: 20px;
  font-size: .76rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ---- Tags ---- */
.tag-depannage {
  display: inline-block;
  background: #fff3e0;
  color: #e67e22;
  font-size: .72rem;
  font-weight: 600;
  padding: .1rem .3rem;
  border-radius: 3px;
  margin-left: .3rem;
  vertical-align: middle;
}
.bl-ref {
  display: inline-block;
  background: var(--green-light);
  color: var(--green-dark);
  font-size: .74rem;
  font-weight: 600;
  padding: .1rem .4rem;
  border-radius: 4px;
  margin-left: .3rem;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .42rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.btn:hover     { opacity: .85; }
.btn:disabled  { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--green-dark); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-sm        { padding: .28rem .7rem; font-size: .82rem; border-radius: 5px; }
.btn-xs        { padding: .18rem .55rem; font-size: .78rem; border-radius: 4px; }
.btn-block     { width: 100%; }

/* ---- Forms ---- */
.form-group { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .8rem; }
.form-group label { font-size: .82rem; font-weight: 600; color: var(--text-muted); }
.form-group input,
.form-group select,
.form-group textarea {
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  background: #fff;
  font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--green-main);
  box-shadow: 0 0 0 2px rgba(64,145,108,.15);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}
@media (max-width: 500px) { .form-row { grid-template-columns: 1fr; } }

/* ---- Modal ---- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  align-items: flex-start;
  justify-content: center;
  padding: 1.5rem 1rem;
  overflow-y: auto;
}
.modal-overlay.active { display: flex; }

.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 1.75rem;
  width: 100%;
  max-width: 600px;
  position: relative;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
  margin: auto;
}

.modal-close {
  position: absolute;
  top: .75rem;
  right: .85rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ---- Detail table (modal) ---- */
.detail-table {
  width: 100%;
  font-size: .85rem;
  border-collapse: collapse;
  margin-bottom: .75rem;
}
.detail-table th {
  text-align: left;
  padding: .35rem .5rem;
  border-bottom: 1px solid var(--border);
  font-size: .76rem;
  color: var(--text-muted);
  text-transform: uppercase;
}
.detail-table td {
  padding: .38rem .5rem;
  border-bottom: 1px solid #f5f5f5;
}

.detail-meta {
  color: var(--text-muted);
  font-size: .84rem;
  margin-bottom: .9rem;
}

.detail-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .6rem 0 0;
  border-top: 1px solid var(--border);
  font-weight: 700;
  font-size: .9rem;
  margin-top: .35rem;
}

/* ---- Order note ---- */
.order-note {
  background: #fffde7;
  border-left: 3px solid #f9a825;
  padding: .45rem .7rem;
  border-radius: 4px;
  font-size: .85rem;
  color: #555;
  margin-bottom: .75rem;
}

/* ---- Custom request item ---- */
.cr-item {
  background: #fff3e0;
  border-radius: 5px;
  padding: .4rem .65rem;
  margin-bottom: .3rem;
  font-size: .85rem;
}

/* ---- Order checkbox (invoice creation) ---- */
.order-checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: .4rem;
  cursor: pointer;
  font-size: .88rem;
}
.order-checkbox-row:hover { background: var(--green-pale); }
.order-checkbox-row input[type=checkbox] { margin-top: .15rem; flex-shrink: 0; }

/* ---- Error / toast ---- */
.error-msg { color: var(--danger); font-size: .85rem; margin-top: .5rem; min-height: 1.2em; }

#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.toast {
  background: var(--green-dark);
  color: #fff;
  padding: .65rem 1.1rem;
  border-radius: 8px;
  font-size: .88rem;
  box-shadow: var(--shadow);
  animation: fadeIn .2s;
  max-width: 280px;
}
.toast.error { background: var(--danger); }
@keyframes fadeIn { from { opacity:0; transform: translateY(8px); } }

/* ---- Price input (catalogue) ---- */
.price-input {
  width: 90px;
  padding: .3rem .45rem;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: .85rem;
  text-align: right;
}
.price-input:disabled { background: var(--surface2); color: var(--text-muted); }
