/* ============================================================
   G-Trem - Discord Dark Theme
   ============================================================ */

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #36393f;
  --bg-secondary: #2f3136;
  --bg-tertiary: #202225;
  --bg-input: #40444b;
  --bg-hover: #4f545c;
  --bg-active: #42464d;
  --bg-card: #2f3136;
  --bg-sidebar: #2f3136;

  --text-primary: #dcddde;
  --text-secondary: #b9bbbe;
  --text-muted: #72767d;
  --text-link: #00aff4;

  --accent: #5865f2;
  --accent-hover: #4752c4;
  --accent-light: #7983f5;

  --green: #3ba55d;
  --green-hover: #359751;
  --green-bg: rgba(59, 165, 93, 0.15);

  --red: #ed4245;
  --red-hover: #d83c3e;

  --yellow: #faa81a;

  --border: #42464d;
  --radius: 6px;
  --radius-lg: 10px;

  --sidebar-width: 260px;

  --font: 'Segoe UI', 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);

  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  font-size: 15px;
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--bg-hover);
}

/* ---------- Topbar ---------- */
.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: 52px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
  user-select: none;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
  transition: background var(--transition);
}

.topbar-logo:hover {
  background: var(--bg-hover);
}

.topbar-logo-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  flex-shrink: 0;
  transition: background var(--transition), box-shadow var(--transition), transform var(--transition);
}
.topbar-logo:hover .topbar-logo-icon {
  background: var(--accent-hover);
  box-shadow: 0 0 12px rgba(88, 101, 242, 0.5);
  transform: scale(1.08);
}

.topbar-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-left: 0;
  min-width: 0;
}

.topbar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
}

.topbar-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.topbar-item.active {
  background: var(--bg-active);
  color: #fff;
}

.topbar-item .topbar-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.topbar-item .topbar-icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  justify-self: end;
}

.topbar-version {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}



/* ---------- Sidebar context (reused in commande.html main body) ---------- */
.sidebar-context {
  margin: 10px 6px 0;
  padding: 10px;
  border: 1px solid rgba(88, 101, 242, 0.45);
  border-radius: var(--radius);
  background: rgba(88, 101, 242, 0.12);
  box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar-context-label {
  display: block;
  margin-bottom: 4px;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.sidebar-context strong {
  display: block;
  color: #fff;
  font-size: 0.95rem;
  line-height: 1.2;
  margin-bottom: 8px;
  word-break: break-word;
}

.sidebar-context-stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}

.sidebar-context-stats span {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.76rem;
}

.sidebar-context-stats b {
  color: #fff;
}

.sidebar-orders {
  margin: 12px 6px 0;
  min-height: 0;
}

.sidebar-orders-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 2px;
}

.sidebar-order-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  align-items: stretch;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.sidebar-order-row:hover {
  background: var(--bg-hover);
}

.sidebar-order-row.active {
  border-color: rgba(88, 101, 242, 0.55);
  background: rgba(88, 101, 242, 0.14);
}

.sidebar-order {
  width: 100%;
  min-width: 0;
  padding: 8px 4px 8px 9px;
  border: none;
  border-radius: var(--radius) 0 0 var(--radius);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: color var(--transition);
}

.sidebar-order:hover {
  color: var(--text-primary);
}

.sidebar-order-row.active .sidebar-order {
  color: #fff;
}

.sidebar-order-delete {
  width: 28px;
  border: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.72;
  transition: background var(--transition), color var(--transition), opacity var(--transition);
}

.sidebar-order-delete:hover {
  background: var(--red);
  color: #fff;
  opacity: 1;
}

.sidebar-order-client {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.2;
}

.sidebar-order-meta {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 0.7rem;
  line-height: 1.2;
}

.sidebar-empty {
  display: block;
  padding: 8px 9px;
  color: var(--text-muted);
  font-size: 0.76rem;
}

/* ---------- Main Content ---------- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-header {
  position: relative;
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
}

.main-header h2 {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.15rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  margin: 0;
}

.main-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.main-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 22px;
}

.has-active-client .main-body {
  padding-top: 8px;
}

/* ---------- Welcome Page ---------- */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  gap: 16px;
}

.welcome-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  color: #fff;
  font-weight: 700;
}

.welcome h2 {
  font-size: 1.8rem;
  color: #fff;
  font-weight: 700;
}

.welcome p {
  color: var(--text-secondary);
  max-width: 400px;
  line-height: 1.5;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.card-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  min-width: 0;
}

.card-body {
  padding: 10px 14px;
}

.client-card {
  margin-bottom: 12px;
}

.has-active-client .client-card {
  display: none;
}

.show-client-panel .client-card {
  display: block;
}

/* ---------- Active client context ---------- */
.active-client-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 7px 12px;
  border: 1px solid rgba(88, 101, 242, 0.55);
  border-radius: var(--radius-lg);
  background: rgba(88, 101, 242, 0.12);
  box-shadow: inset 3px 0 0 var(--accent);
}

.has-active-client .active-client-banner {
  display: none;
}

.active-client-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.active-client-icon svg {
  width: 16px;
  height: 16px;
}

.active-client-label {
  display: block;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  margin-bottom: 1px;
}

.active-client-banner strong {
  display: block;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
}

/* ---------- Grid Layout ---------- */
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.order-tools-grid {
  gap: 10px;
  margin-bottom: 10px;
}

.order-tools-grid .card-header {
  padding: 8px 14px;
}

.order-tools-grid .card-body {
  padding: 10px 14px;
}

.panel-full {
  grid-column: 1 / -1;
}

@media (max-width: 1200px) {
  .grid-3 {
    grid-template-columns: 1fr 1fr;
  }
}
@media (max-width: 800px) {
  .grid-3, .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* ---------- Form Elements ---------- */
.form-group {
  margin-bottom: 6px;
}  .form-group label {
    display: block;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
    letter-spacing: 0.3px;
  }

input[type="text"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9rem;
  transition: border-color var(--transition);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23b9bbbe' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px 12px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition), transform var(--transition);
  white-space: nowrap;
  min-height: 34px;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-green {
  background: var(--green);
  color: #fff;
}
.btn-green:hover {
  background: var(--green-hover);
}

.btn-danger {
  background: var(--red);
  color: #fff;
}
.btn-danger:hover {
  background: var(--red-hover);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-sm {
  padding: 4px 9px;
  font-size: 0.8rem;
}

.btn-icon {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: var(--radius);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ---------- Tags / Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-input);
  color: var(--text-secondary);
}

.badge-green {
  background: var(--green-bg);
  color: var(--green);
}

.entity-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.entity-chip {
  display: inline-flex;
  align-items: stretch;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg-input);
}

.entity-chip-main,
.entity-chip-delete {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.entity-chip-main {
  min-width: 0;
  max-width: 180px;
  padding: 5px 9px 5px 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
  font-weight: 600;
}

.entity-chip-main:hover {
  color: #fff;
  background: var(--accent);
}

.entity-chip-delete {
  width: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.entity-chip-delete:hover {
  color: #fff;
  background: var(--red);
}

/* ---------- Table (Order List) ---------- */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  text-align: left;
  padding: 5px 9px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 4px 9px;
  border-bottom: 1px solid rgba(66, 70, 77, 0.5);
  vertical-align: middle;
}

tbody tr {
  transition: background var(--transition);
}

tbody tr:hover {
  background: rgba(79, 84, 92, 0.3);
}

tbody tr.purchased {
  opacity: 0.6;
}

tbody tr.purchased td {
  text-decoration: line-through;
  text-decoration-color: var(--text-muted);
}

/* ---------- Checkbox ---------- */
.checkbox-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.checkbox-wrap input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: all var(--transition);
  flex-shrink: 0;
}

.checkbox-wrap input[type="checkbox"]:checked {
  background: var(--green);
  border-color: var(--green);
}

.checkbox-wrap input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 0;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ---------- Quick Add Row ---------- */
.quick-add {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.quick-add input {
  flex: 1;
  min-width: 0;
}

.supplier-action-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.supplier-action-row select {
  flex: 1;
}

.btn-add-entry {
  width: auto;
  min-width: 138px;
  padding: 0 12px;
}

.btn-supplier-add {
  width: 86px;
  min-width: 86px;
}

/* ---------- Empty State ---------- */
.empty-state {
  text-align: center;
  padding: 18px 16px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.9rem;
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  color: #fff;
  animation: toastIn 0.3s ease;
  box-shadow: var(--shadow-md);
  max-width: 360px;
}

.toast-success {
  background: var(--green);
}

.toast-info {
  background: var(--accent);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Utility ---------- */
.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.text-green {
  color: var(--green);
}

.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }

/* ---------- Inline row for select+button ---------- */
.inline-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.inline-row .form-group {
  flex: 1;
  margin-bottom: 0;
}

/* ---------- Date chip ---------- */
.date-chip {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
}

/* ---------- Section divider ---------- */
.section-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

/* ---------- Item Chips (clickable quick-add) ---------- */
.item-chips-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 64px;
  overflow-y: auto;
  padding-right: 4px;
}

.item-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  white-space: nowrap;
}

.item-chip:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(88, 101, 242, 0.35);
}

.item-chip:active {
  transform: scale(0.96);
  transition: transform 80ms ease;
}

.item-chip .chip-supplier {
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
  padding: 2px 6px;
  border-radius: 10px;
  background: rgba(250, 168, 26, 0.16);
  border: 1px solid rgba(250, 168, 26, 0.4);
  color: #ffd38a;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  opacity: 1;
}

.item-chip:hover .chip-supplier,
.item-chip.just-added .chip-supplier {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
}

.item-chip .chip-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* ---------- Order Selector ---------- */
.order-selector {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.quick-items-block {
  margin-top: 8px;
}

.no-quick-items {
  margin-top: 10px;
}

.order-selector .form-group {
  flex: 1;
  margin-bottom: 0;
}

/* ---------- Section Header ---------- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.section-header h4 {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

/* ---------- Pulse animation for new items ---------- */
@keyframes chipPulse {
  0%   { box-shadow: 0 0 0 0 rgba(88, 101, 242, 0.5); }
  70%  { box-shadow: 0 0 0 8px rgba(88, 101, 242, 0); }
  100% { box-shadow: 0 0 0 0 rgba(88, 101, 242, 0); }
}

.item-chip.just-added {
  animation: chipPulse 0.6s ease;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- Order badge in selector ---------- */
.order-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
}

/* ---------- Clickable quantity in table ---------- */
.qty-cell {
  text-align: center;
  white-space: nowrap;
}

.qty-cell span {
  display: inline-block;
  min-width: 18px;
  font-weight: 600;
  vertical-align: middle;
}

.qty-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  vertical-align: middle;
  transition: all 0.12s;
  line-height: 1;
  padding: 0;
  margin: 0 3px;
}

.qty-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.qty-btn:active {
  transform: scale(0.9);
}

/* ---------- Chip trash button ---------- */
.item-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chip-click {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.chip-trash {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.12s;
  padding: 0;
  opacity: 0;
  flex-shrink: 0;
}

.item-chip:hover .chip-trash {
  opacity: 1;
}

.chip-trash:hover {
  background: var(--red);
  color: #fff;
}

/* ---------- Active order highlight ---------- */
.card.active-order {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* ---------- Pencil icon for panel edit ---------- */
.client-panel-header .btn-pencil {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: var(--radius);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  margin-left: auto;
  flex-shrink: 0;
}
.client-panel-header .btn-pencil:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}
.client-panel-header .btn-pencil.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.client-panel-header .btn-pencil svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* ---------- Edit mode styles for panels ---------- */
.panel-edit-input {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition);
}
.panel-edit-input:focus {
  border-color: var(--accent);
}
select.panel-edit-input {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23b9bbbe' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

/* ---------- Client Bar (secondary horizontal bar) ---------- */
.client-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 44px;
  user-select: none;
  z-index: 99;
}

.client-bar-list {
  display: flex;
  align-items: center;
  justify-content: safe center;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 0;
  scrollbar-width: thin;
}

.client-bar-list::-webkit-scrollbar {
  height: 4px;
}

.client-bar-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.client-bar-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}

.client-bar-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}

.client-bar-item.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.client-bar-item .client-bar-initials {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.client-bar-item.active .client-bar-initials {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

.client-bar-empty {
  display: flex;
  align-items: center;
  padding: 5px 12px;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
}

/* ---------- Add new client button in client bar ---------- */
.client-bar-add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border: 1.5px dashed var(--accent);
  border-radius: 20px;
  background: rgba(88, 101, 242, 0.08);
  color: var(--accent-light);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font);
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
}
.client-bar-add:hover {
  background: var(--accent);
  color: #fff;
  border-style: solid;
}
.client-bar-add:active {
  transform: scale(0.97);
}

/* ---------- Delete button in client bar pills ---------- */
.client-bar-duration {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent-light);
  background: rgba(88, 101, 242, 0.12);
  padding: 1px 6px;
  border-radius: 8px;
  line-height: 1.4;
  flex-shrink: 0;
}

.client-bar-item.active .client-bar-duration {
  background: rgba(255,255,255,0.18);
  color: #fff;
}

.client-bar-delete {
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--red);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
  margin-left: 2px;
  opacity: 0;
}
.client-bar-item:hover .client-bar-delete {
  opacity: 0.7;
}
.client-bar-item .client-bar-delete:hover {
  opacity: 1;
  background: var(--red);
  color: #fff;
}
.client-bar-item.active .client-bar-delete {
  opacity: 0.6;
}
.client-bar-item.active .client-bar-delete:hover {
  opacity: 1;
  background: rgba(255,255,255,0.2);
  color: #fff;
}

/* ---------- Client Panels (3 columns) ---------- */
.client-panels {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.client-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.client-panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.client-panel-header svg {
  width: 18px;
  height: 18px;
  fill: var(--accent-light);
  flex-shrink: 0;
}

.client-panel-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-light);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.client-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 0.95rem;
}

.client-panel-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}

.client-panel-empty svg {
  width: 40px;
  height: 40px;
  opacity: 0.3;
}

@media (max-width: 1100px) {
  .client-panels {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 700px) {
  .client-panels {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .client-bar {
    padding: 6px 10px;
    gap: 6px;
  }  
}

/* ---------- Responsive sidebar ---------- */
@media (max-width: 700px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    display: block;
  }

  :root {
    --mobile-nav-height: 64px;
  }

  .main {
    height: 100%;
    width: 100%;
  }

  .main-header {
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top));
    min-height: 50px;
    min-width: 0;
  }

  .main-header h2 {
    position: static;
    transform: none;
    flex: 1;
    font-size: 1.05rem;
    min-width: 0;
  }

  .main-header .badge {
    max-width: 32vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .main-header-actions {
    flex-shrink: 0;
  }

  .main-header-actions .btn {
    width: 38px;
    min-width: 38px;
    padding: 0;
    font-size: 0;
    gap: 0;
  }

  .main-header-actions .btn svg {
    margin: 0;
  }

  .main-body {
    padding: 10px;
    padding-bottom: calc(var(--mobile-nav-height) + 14px + env(safe-area-inset-bottom));
  }

  .topbar {
    display: flex;
    position: fixed;
    inset: auto 0 0 0;
    height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    padding: 0 8px;
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--border);
    border-bottom: 0;
    box-shadow: 0 -6px 18px rgba(0,0,0,0.22);
    gap: 0;
  }

  .topbar-right {
    display: none;
  }
  .topbar-left {
    display: flex;
    gap: 0;
    flex-shrink: 0;
  }
  .topbar-left .topbar-logo {
    flex: 0 0 auto;
    justify-content: center;
    padding: 0 4px;
    border-radius: 0;
    font-size: 0;
    gap: 2px;
    background: transparent;
  }
  .topbar-left .topbar-logo:hover {
    background: transparent;
  }
  .topbar-left .topbar-logo-icon {
    width: 20px;
    height: 20px;
    font-size: 0.6rem;
  }
  .topbar-left .topbar-logo svg {
    width: 14px;
    height: 14px;
    display: block;
  }

  .topbar-nav {
    flex: 1;
    margin-left: 0;
    justify-content: space-around;
  }

  .topbar-item {
    flex: 1;
    justify-content: center;
    padding: 0;
    border-radius: 0;
    gap: 0;
  }

  .topbar-item span {
    display: none;
  }

  .topbar-logo span:not(.topbar-logo-icon) {
    display: none;
  }

  .card {
    border-radius: var(--radius);
  }

  .card-header {
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 9px 10px;
  }

  .card-body {
    padding: 10px;
  }

  .client-card {
    margin-bottom: 10px;
  }

  .inline-row,
  .order-selector {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-row .form-group,
  .order-selector .form-group {
    width: 100%;
  }

  .quick-add,
  .supplier-action-row {
    width: 100%;
  }

  .quick-add {
    flex-direction: column;
  }

  .quick-add .btn,
  .btn-supplier-add {
    width: 100%;
    min-width: 0;
  }

  .btn-add-entry,
  .btn-supplier-add {
    width: 100%;
    min-width: 0;
  }

  .item-chips-grid {
    max-height: 116px;
  }

  .section-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .empty-state {
    padding: 24px 12px;
  }

  #noClientMsg {
    padding: 34px 16px !important;
  }

  .table-wrap {
    margin: 0 -10px;
    padding: 0 10px 2px;
  }

  table {
    min-width: 640px;
  }

  .toast-container {
    left: 10px;
    right: 10px;
    bottom: calc(var(--mobile-nav-height) + 12px + env(safe-area-inset-bottom));
  }

  .toast {
    max-width: none;
  }
}

@media (max-width: 430px) {
  html {
    font-size: 14px;
  }

  .main-header {
    gap: 10px;
  }

  .supplier-action-row {
    display: flex;
    flex-direction: column;
  }

  .btn-add-entry {
    width: 100%;
    min-width: 0;
  }

  .card-header > div[style*="display:flex"] {
    width: 100%;
    flex-wrap: wrap;
  }

  .card-header > div[style*="display:flex"] .btn {
    flex: 1 1 140px;
  }
}

/* ---------- Small screen polish (phones in portrait and landscape) ---------- */
@media (max-width: 960px), (max-height: 520px) and (pointer: coarse) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  body {
    display: block;
  }

  :root {
    --mobile-nav-height: 58px;
  }

  .main {
    width: 100%;
    height: 100%;
  }

  .main-header {
    gap: 8px;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    min-height: 48px;
  }

  .main-header h2 {
    position: static;
    transform: none;
    flex: 1 1 auto;
    min-width: 0;
    font-size: 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .main-header-actions {
    flex: 0 1 auto;
    gap: 6px;
    justify-content: flex-end;
  }

  .main-header-actions .btn {
    width: 36px;
    min-width: 36px;
    padding: 0;
    font-size: 0;
    gap: 0;
  }

  .main-header-actions .btn svg {
    width: 18px;
    height: 18px;
  }

  .main-header .badge {
    max-width: 46vw;
    padding: 3px 7px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .main-body {
    padding: 10px;
    padding-bottom: calc(var(--mobile-nav-height) + 12px + env(safe-area-inset-bottom));
  }

  .topbar {
    display: flex;
    position: fixed;
    inset: auto 0 0 0;
    height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    padding: 0 8px;
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--border);
    border-bottom: 0;
    box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.28);
    gap: 0;
  }

  .topbar-right {
    display: none !important;
  }
  .topbar-left {
    display: flex !important;
    gap: 0;
    flex-shrink: 0;
  }
  .topbar-left .topbar-logo {
    flex: 0 0 auto;
    justify-content: center;
    padding: 0 4px;
    border-radius: 0;
    font-size: 0;
    gap: 2px;
    background: transparent;
  }
  .topbar-left .topbar-logo:hover {
    background: transparent;
  }
  .topbar-left .topbar-logo-icon {
    width: 20px;
    height: 20px;
    font-size: 0.6rem;
  }
  .topbar-left .topbar-logo svg {
    width: 14px;
    height: 14px;
    display: block;
  }

  .topbar-nav {
    flex: 1;
    margin-left: 0;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    gap: 0;
  }

  .topbar-item {
    flex: 1 1 0;
    min-width: 0;
    justify-content: center;
    padding: 0;
    border-radius: 0;
    gap: 0;
  }

  .topbar-item span {
    display: none !important;
  }

  .topbar-logo span:not(.topbar-logo-icon) {
    display: none !important;
  }

  .grid-3,
  .grid-2 {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .card {
    border-radius: var(--radius);
  }

  .card-header {
    gap: 8px;
    padding: 9px 10px;
  }

  .card-header h3 {
    line-height: 1.25;
  }

  .card-body {
    padding: 10px;
  }

  .inline-row,
  .order-selector,
  .quick-add,
  .supplier-action-row {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .inline-row .form-group,
  .order-selector .form-group {
    width: 100%;
  }

  .btn,
  input[type="text"],
  input[type="search"],
  select,
  textarea {
    min-height: 40px;
  }

  .quick-add .btn,
  .btn-add-entry,
  .btn-supplier-add,
  .order-selector .btn {
    width: 100%;
    min-width: 0;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .item-chips-grid {
    max-height: 126px;
    padding-right: 0;
  }

  .item-chip,
  .chip-click {
    min-width: 0;
    max-width: 100%;
  }

  .chip-click {
    overflow: hidden;
  }

  .chip-click > :not(svg),
  .item-chip .chip-supplier {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .card-header > div[style*="display:flex"] {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px !important;
  }

  .card-header > div[style*="display:flex"] .btn {
    flex: 1 1 150px;
    min-width: 0;
    padding-inline: 9px;
  }

  .table-wrap {
    overflow: visible;
  }

  #orderTable {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 8px;
  }

  #orderTable thead {
    display: none;
  }

  #orderTable tbody,
  #orderTable tr,
  #orderTable td {
    display: block;
    width: 100%;
  }

  #orderTable tr {
    position: relative;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(64, 68, 75, 0.45);
  }

  #orderTable td {
    border-bottom: 0;
    padding: 6px 0;
  }

  #orderTable td:nth-child(1) {
    position: absolute;
    top: 10px;
    right: 10px;
    width: auto;
    padding: 0;
  }

  #orderTable td:nth-child(2) {
    padding-right: 46px;
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }

  #orderTable td:nth-child(3),
  #orderTable td:nth-child(4),
  #orderTable td:nth-child(5),
  #orderTable td:nth-child(6) {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    min-height: 32px;
  }

  #orderTable td:nth-child(3)::before { content: "Qte"; }
  #orderTable td:nth-child(4)::before { content: "Fournisseur"; }
  #orderTable td:nth-child(5)::before { content: "Ajout"; }
  #orderTable td:nth-child(6)::before { content: "Achat"; }

  #orderTable td:nth-child(3)::before,
  #orderTable td:nth-child(4)::before,
  #orderTable td:nth-child(5)::before,
  #orderTable td:nth-child(6)::before {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
  }

  #orderTable td:nth-child(7) {
    display: flex;
    justify-content: flex-end;
    padding-top: 2px;
  }

  .qty-cell {
    text-align: left;
  }

  .qty-btn,
  .btn-icon {
    width: 32px;
    height: 32px;
  }

  .qty-cell span {
    min-width: 24px;
    text-align: center;
  }

  .checkbox-wrap input[type="checkbox"] {
    width: 24px;
    height: 24px;
  }

  .checkbox-wrap input[type="checkbox"]:checked::after {
    left: 7px;
    top: 2px;
    width: 7px;
    height: 12px;
  }

  .date-chip {
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 380px) {
  .main-header .badge {
    max-width: 40vw;
  }

  .card-header > div[style*="display:flex"] .btn {
    flex-basis: 100%;
  }

  #orderTable td:nth-child(3),
  #orderTable td:nth-child(4),
  #orderTable td:nth-child(5),
  #orderTable td:nth-child(6) {
    grid-template-columns: 78px minmax(0, 1fr);
  }
}
