/* ============================================================
   FF Crafting BMS — Master Stylesheet
   ============================================================ */

/* ── Variables ──────────────────────────────────────────────── */
:root {
  --brand-primary: #0074D9;
  --brand-dark: #555555;
  --brand-medium: #7A7A7A;
  --brand-light: #D8D8D8;
  --brand-white: #FFFFFF;
  --brand-text: #333333;

  --sidebar-bg: var(--brand-white);
  --sidebar-hover: #f5f7fa;
  --sidebar-border: var(--brand-light);
  --sidebar-text: var(--brand-medium);
  --sidebar-text-bright: var(--brand-dark);
  --sidebar-label: var(--brand-medium);
  --sidebar-width: 250px;

  --track-orders: var(--brand-primary);
  --track-orders-light: #e8f3fc;
  --track-bills: var(--brand-dark);
  --track-bills-light: #f0f0f0;
  --track-cash: var(--brand-primary);
  --track-cash-light: #e8f3fc;

  --bg-main: #f4f4f4;
  --bg-card: var(--brand-white);
  --bg-table-alt: #fafafa;
  --bg-secondary: #f5f5f5;

  --text-primary: var(--brand-text);
  --text-secondary: var(--brand-dark);
  --text-muted: var(--brand-medium);
  --text-light: var(--brand-light);

  --border: var(--brand-light);
  --border-dark: #c8c8c8;

  --blue: var(--brand-primary);
  --blue-dark: #005bb0;
  --blue-light: #e8f3fc;
  --green: #2e7d32;
  --green-light: #E8F5E9;
  --red: #c62828;
  --red-light: #FFEBEE;
  --orange: #e65100;
  --orange-light: #FFF3E0;
  --teal: var(--brand-primary);
  --teal-light: #e8f3fc;
  --gray: var(--brand-medium);

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 4px 6px rgba(0,0,0,.07), 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 10px 15px rgba(0,0,0,.08), 0 4px 6px rgba(0,0,0,.05);

  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ── Layout ─────────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
  overflow: hidden;
  min-width: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.brand-logo-img {
  width: 60px;
  height: 60px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
.brand-logo {
  width: 40px; height: 40px;
  background: var(--blue-light);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--brand-primary);
  font-weight: 800;
  font-size: .95rem;
  flex-shrink: 0;
}
.brand-info { display: flex; flex-direction: column; }
.brand-name { color: var(--brand-dark); font-weight: 700; font-size: .95rem; line-height: 1.2; }
.brand-sub { color: var(--brand-medium); font-size: .72rem; }

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: .75rem 0;
  scrollbar-width: thin;
  scrollbar-color: var(--sidebar-border) transparent;
}
.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 2px; }

.nav-group-label {
  padding: .6rem 1rem .25rem;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--sidebar-label);
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem 1rem;
  color: var(--sidebar-text);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
  text-decoration: none !important;
}
.nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-bright);
}
.nav-item.active {
  background: var(--blue-light);
  color: var(--brand-primary);
  border-left-color: var(--brand-primary);
  font-weight: 600;
}
.nav-item.active-orders { border-left-color: var(--brand-primary); }
.nav-item.active-bills  { border-left-color: var(--brand-primary); }
.nav-item.active-cash   { border-left-color: var(--brand-primary); }

.nav-icon {
  flex-shrink: 0;
  width: 1.15rem;
  height: 1.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  color: currentColor;
}
.nav-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}
.nav-item:hover .nav-icon,
.nav-item.active .nav-icon {
  opacity: 1;
}
.nav-icon-orders,
.nav-icon-orders-queue,
.nav-icon-cutting,
.nav-icon-cash,
.nav-icon-settings,
.nav-icon-users { color: var(--brand-medium); }
.nav-item:hover .nav-icon-orders,
.nav-item:hover .nav-icon-orders-queue,
.nav-item:hover .nav-icon-cutting,
.nav-item:hover .nav-icon-cash,
.nav-item:hover .nav-icon-settings,
.nav-item:hover .nav-icon-users,
.nav-item.active .nav-icon-orders,
.nav-item.active .nav-icon-orders-queue,
.nav-item.active .nav-icon-cutting,
.nav-item.active .nav-icon-cash,
.nav-item.active .nav-icon-settings,
.nav-item.active .nav-icon-users { color: var(--brand-primary); }

.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding: .85rem 1rem;
  flex-shrink: 0;
}
.user-info { display: flex; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.user-avatar {
  width: 32px; height: 32px;
  background: var(--brand-primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: .8rem;
  flex-shrink: 0;
}
.user-details { display: flex; flex-direction: column; }
.user-name { color: var(--sidebar-text-bright); font-size: .82rem; font-weight: 600; }
.user-role { color: var(--sidebar-label); font-size: .72rem; text-transform: capitalize; }
.logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  width: 100%;
  padding: .4rem .75rem;
  background: var(--bg-table-alt);
  color: var(--brand-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: .82rem;
  transition: background .15s, color .15s, border-color .15s;
  text-decoration: none !important;
}
.logout-btn:hover { background: var(--blue-light); color: var(--brand-primary); border-color: var(--brand-primary); }
.logout-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  opacity: 0.85;
}

/* ── Main Wrapper ────────────────────────────────────────────── */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* ── Top Bar ─────────────────────────────────────────────────── */
.top-bar {
  background: var(--bg-card);
  border-bottom: 3px solid var(--brand-primary);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}
.sidebar-toggle {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-secondary);
  padding: .25rem;
  display: none;
}
.page-heading {
  font-size: 1rem;
  font-weight: 600;
  color: var(--brand-dark);
  flex: 1;
}
.top-bar-right { color: var(--text-muted); font-size: .82rem; }

/* ── Main Content ─────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 1.5rem;
}

/* ── Alerts / Flash ──────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .875rem;
  font-weight: 500;
  position: relative;
}
.alert-success { background: var(--green-light); color: var(--green); border: 1px solid #c8e6c9; }
.alert-error   { background: var(--red-light);   color: var(--red);   border: 1px solid #ffcdd2; }
.alert-icon { font-size: 1rem; }
.alert-close {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: inherit;
  opacity: .7;
  line-height: 1;
  padding: 0 .2rem;
}
.alert-close:hover { opacity: 1; }

/* ── Page Header Row ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: .75rem;
}
.page-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--brand-dark);
}
.page-header-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}
.card-body { padding: 1.25rem; }
.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: .95rem;
}

/* ── Dashboard Stats ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.stat-label { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.stat-value { font-size: 1.75rem; font-weight: 800; color: var(--text-primary); line-height: 1; }
.stat-sub   { font-size: .78rem; color: var(--text-muted); }
.stat-card.orders-accent { border-top: 3px solid var(--track-orders); }
.stat-card.bills-accent  { border-top: 3px solid var(--track-bills);  }
.stat-card.cash-accent   { border-top: 3px solid var(--track-cash);   }
.stat-card.neutral-accent{ border-top: 3px solid var(--gray);         }

/* ── Tables ──────────────────────────────────────────────────── */
.table-wrap {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}
.table-responsive { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
thead th {
  padding: .75rem 1rem;
  text-align: left;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: var(--bg-table-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:nth-child(even) { background: var(--bg-table-alt); }
tbody tr:hover { background: var(--blue-light); }
tbody td {
  padding: .7rem 1rem;
  color: var(--text-primary);
  vertical-align: middle;
}
.table-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.table-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem .95rem;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: filter .15s, transform .1s;
  text-decoration: none !important;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn:active { transform: translateY(0); filter: brightness(.96); }
.btn-primary   { background: var(--blue);  color: #fff; }
.btn-danger    { background: var(--red);   color: #fff; }
.btn-success   { background: var(--green); color: #fff; }
.btn-secondary { background: var(--gray);  color: #fff; }
.btn-teal      { background: var(--teal);  color: #fff; }
.btn-outline   { background: transparent; border: 1.5px solid var(--border-dark); color: var(--text-secondary); }
.btn-outline:hover { background: var(--bg-table-alt); }
.btn-sm { padding: .3rem .65rem; font-size: .78rem; }
.btn-block { width: 100%; justify-content: center; }

/* ── Forms ───────────────────────────────────────────────────── */
.form-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  max-width: 780px;
}
.form-card-wide { max-width: 1000px; }
.form-card-header {
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}
.form-card-body { padding: 1.5rem; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }
.form-group { display: flex; flex-direction: column; gap: .3rem; }
.form-label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-control {
  padding: .55rem .8rem;
  border: 1.5px solid var(--border-dark);
  border-radius: var(--radius);
  font-size: .875rem;
  color: var(--text-primary);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
  font-family: inherit;
}
.form-control:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(0, 116, 217, .12);
}
.form-control:disabled, .form-control[readonly] {
  background: var(--bg-table-alt);
  color: var(--text-muted);
  cursor: default;
}
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: .75rem; color: var(--text-muted); }
.form-actions {
  display: flex;
  gap: .75rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* Finance form sections */
.finance-section {
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.finance-section-header {
  padding: .65rem 1rem;
  font-weight: 700;
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  background: var(--bg-table-alt);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}
.finance-section-body { padding: 1rem; }
.calc-field {
  background: var(--bg-table-alt) !important;
  font-weight: 700;
  color: var(--blue-dark) !important;
}
.calc-profit.positive { color: var(--green) !important; }
.calc-profit.negative { color: var(--red) !important; }

/* ── Badges / Status ─────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.badge-pending    { background: var(--orange-light); color: var(--orange); }
.badge-in-progress{ background: var(--blue-light);   color: var(--blue-dark); }
.badge-completed  { background: var(--green-light);  color: var(--green); }
.badge-cancelled  { background: #f3f4f6;              color: #6b7280; }
.badge-open       { background: var(--blue-light);   color: var(--blue-dark); }
.badge-partial    { background: var(--orange-light); color: var(--orange); }
.badge-paid       { background: var(--green-light);  color: var(--green); }
.badge-unpaid     { background: var(--red-light);    color: var(--red); }
.badge-draft      { background: #f3f4f6;              color: #6b7280; }
.badge-sent       { background: var(--blue-light);   color: var(--blue-dark); }
.badge-overdue    { background: var(--red-light);    color: var(--red); }
.badge-whatsapp   { background: #e8f5e9; color: #1b5e20; }
.badge-manual     { background: #f3f4f6; color: #374151; }
.badge-resolved   { background: var(--green-light); color: var(--green); }
.badge-review     { background: var(--orange-light); color: var(--orange); }
.badge-not-started{ background: #f3f4f6; color: #6b7280; }
.badge-done       { background: var(--green-light); color: var(--green); }
.badge-success    { background: var(--green-light);  color: var(--green); }
.badge-warning    { background: var(--orange-light); color: var(--orange); }
.badge-danger     { background: var(--red-light);    color: var(--red); }
.badge-admin      { background: #ede9fe; color: #5b21b6; }

/* ── User chip (audit logs) ──────────────────────────────────── */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .85rem;
}
.user-chip-avatar {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--blue-light);
  color: var(--blue-dark);
  font-size: .72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.text-xs   { font-size: .72rem; }
.text-mono { font-family: monospace; }
.text-sm   { font-size: .82rem; }
.fw-medium { font-weight: 600; }

/* ── Image Upload ─────────────────────────────────────────────── */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: .75rem;
  background: #fafafa;
  transition: border-color .2s, background .2s;
  cursor: pointer;
}
.upload-area:hover { border-color: var(--blue); background: var(--blue-light); }
.upload-input { display: none; }
.upload-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  cursor: pointer;
  gap: .4rem;
}
.upload-icon  { font-size: 2rem; }
.upload-text  { font-weight: 600; color: var(--text); }
.upload-hint  { font-size: .78rem; color: var(--text-muted); }

/* Preview grid (shared for existing + new) */
.img-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: .75rem;
}
.img-preview-item {
  position: relative;
  border-radius: .5rem;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #f3f4f6;
}
.img-preview-item img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  display: block;
}
.img-delete-check {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(220,38,38,.85);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  padding: .25rem .4rem;
  display: flex;
  align-items: center;
  gap: .3rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
}
.img-preview-item:hover .img-delete-check { opacity: 1; }
.img-delete-check input { accent-color: #fff; }
.img-new-label {
  position: absolute;
  top: .3rem; right: .3rem;
  background: var(--blue);
  color: #fff;
  font-size: .65rem;
  font-weight: 700;
  border-radius: 999px;
  padding: .1rem .4rem;
}

/* ── Image Gallery (show page) ───────────────────────────────── */
.img-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: .75rem;
}
.img-gallery-item {
  display: block;
  border-radius: .5rem;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform .15s, box-shadow .15s;
}
.img-gallery-item:hover { transform: scale(1.03); box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.img-gallery-item img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  display: block;
}

/* ── Danger button ───────────────────────────────────────────── */
.btn-danger {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }

/* ── Pagination ──────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: 1rem;
  border-top: 1px solid var(--border);
}
.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 .65rem;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  background: #fff;
  text-decoration: none !important;
  transition: background .1s, border-color .1s, color .1s;
}
.page-link:hover { background: var(--blue-light); border-color: var(--blue); color: var(--blue); }
.page-link.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.page-link.disabled { opacity: .4; pointer-events: none; }
.page-info { font-size: .8rem; color: var(--text-muted); padding: 0 .5rem; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(-12px);
  transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-lg { max-width: 720px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-weight: 700; font-size: 1rem; color: var(--brand-dark); }
.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: .1rem .3rem;
}
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 1.4rem; }
.modal-footer {
  display: flex;
  gap: .75rem;
  justify-content: flex-end;
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--border);
}

/* ── Project Image Gallery (show page) ───────────────────────── */
.project-img-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .85rem;
}
.project-img-card {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform .15s, box-shadow .15s;
  cursor: pointer;
}
.project-img-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.project-img-card img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  display: block;
}
.project-img-empty {
  grid-column: 1/-1;
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: .875rem;
}
.project-img-empty .empty-icon { font-size: 2.5rem; display: block; margin-bottom: .5rem; }

/* ── Lightbox ────────────────────────────────────────────────── */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.9);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.lightbox-overlay.open { opacity: 1; pointer-events: all; }
.lightbox-overlay img {
  max-width: 90vw;
  max-height: 85vh;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  object-fit: contain;
}

/* ── 3-dots Action Menu ──────────────────────────────────────── */
.action-menu { position: relative; display: inline-block; }
.btn-dots {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 2px 10px;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  transition: background .15s, border-color .15s, color .15s;
  letter-spacing: 1px;
}
.btn-dots:hover { background: var(--bg-secondary); border-color: var(--border); color: var(--text-primary); }
.action-dropdown {
  display: none;
  position: fixed;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  min-width: 148px;
  z-index: 9999;
  overflow: hidden;
}
.action-dropdown.open { display: block; }
.action-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: .55rem 1rem;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-primary);
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  transition: background .13s;
  white-space: nowrap;
}
.action-item:hover { background: var(--bg-secondary); }
.action-item-danger { color: var(--red) !important; }
.action-item-danger:hover { background: #fef2f2; }
.action-dropdown form { margin: 0; padding: 0; }

/* ── Login Page ──────────────────────────────────────────────── */
.login-body {
  background: var(--bg-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-wrap { width: 100%; max-width: 400px; }
.login-card {
  background: var(--brand-white);
  border-radius: var(--radius-lg);
  border-top: 3px solid var(--brand-primary);
  padding: 2.5rem;
  box-shadow: var(--shadow-md);
}
.login-header { text-align: center; margin-bottom: 2rem; }
.login-logo-img {
  width: 100px;
  height: 100px;
  object-fit: contain;
  display: block;
  margin: 0 auto .75rem;
}
.login-logo {
  width: 64px; height: 64px;
  background: var(--blue-light);
  border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--brand-primary);
  font-weight: 900;
  font-size: 1.5rem;
  margin-bottom: .75rem;
}
.login-title { font-size: 1.4rem; font-weight: 800; color: var(--brand-dark); }
.login-subtitle { color: var(--brand-medium); font-size: .875rem; }
.login-form .form-group { margin-bottom: 1rem; }
.login-copy { text-align: center; color: var(--brand-medium); font-size: .78rem; margin-top: 1.25rem; }

.login-demo-box {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--bg-table-alt);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.login-demo-title {
  font-size: .75rem;
  font-weight: 700;
  color: var(--brand-dark);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .5rem;
}
.login-demo-list { display: grid; gap: .3rem; font-size: .82rem; font-family: monospace; color: var(--brand-text); }
.login-demo-row {
  display: flex;
  justify-content: space-between;
  padding: .25rem .4rem;
  background: var(--brand-white);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.login-role-badge {
  padding: .1rem .4rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 700;
}
.login-role-admin { background: var(--blue-light); color: var(--brand-primary); }
.login-role-manager { background: #f0f0f0; color: var(--brand-dark); }
.login-role-accountant { background: var(--green-light); color: var(--green); }
.login-role-user { background: #f0f0f0; color: var(--brand-medium); }

/* ── Brand utility classes ───────────────────────────────────── */
.info-banner {
  margin-bottom: 1.25rem;
  background: var(--blue-light);
  border: 1px solid #b3d7f5;
}
.info-banner p {
  font-size: .875rem;
  color: var(--brand-primary);
  margin: 0;
}

.queue-table .col-extracted,
.queue-table .col-confidence {
  display: none;
}
.queue-table .col-raw-message {
  max-width: none;
  min-width: 280px;
}
.badge-demo {
  background: var(--blue-light);
  color: var(--brand-primary);
  padding: .2rem .6rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
}
.badge-you {
  background: var(--blue-light);
  color: var(--brand-primary);
  padding: .1rem .4rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 700;
}
.error-page {
  text-align: center;
  color: var(--brand-text);
}
.error-page-code {
  font-size: 5rem;
  font-weight: 900;
  margin-bottom: 1rem;
  color: var(--brand-primary);
}
.error-page h2 {
  font-size: 1.4rem;
  margin-bottom: .5rem;
  color: var(--brand-dark);
}
.error-page p {
  color: var(--brand-medium);
  margin-bottom: 1.5rem;
}

/* ── Order detail ─────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem 2rem;
  margin-bottom: 1.5rem;
}
.detail-item { display: flex; flex-direction: column; gap: .2rem; }
.detail-label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.detail-value { font-size: .95rem; color: var(--text-primary); font-weight: 500; }

/* ── Running balance colour ──────────────────────────────────── */
.balance-positive { color: var(--green); font-weight: 700; }
.balance-negative { color: var(--red);   font-weight: 700; }

/* ── Misc helpers ────────────────────────────────────────────── */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-success{ color: var(--green); }
.text-danger { color: var(--red);   }
.fw-bold     { font-weight: 700; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }

/* Review queue */
.review-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}
.review-card-header {
  padding: .75rem 1rem;
  background: var(--bg-table-alt);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.review-card-body { padding: 1rem; }
.review-message {
  font-size: .875rem;
  background: var(--bg-table-alt);
  padding: .65rem .85rem;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--border-dark);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: .75rem;
}
.review-matches { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.match-badge {
  padding: .25rem .65rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
}
.match-badge.high { border-color: var(--green); color: var(--green); }
.match-badge.mid  { border-color: var(--orange); color: var(--orange); }
.match-badge.low  { border-color: var(--red); color: var(--red); }

/* ── Responsive Scrollbar & Table Fixes ──────────────────────── */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
/* Style scrollbars neatly to indicate scrollability */
.table-responsive::-webkit-scrollbar {
  height: 6px;
}
.table-responsive::-webkit-scrollbar-track {
  background: var(--bg-table-alt);
}
.table-responsive::-webkit-scrollbar-thumb {
  background: var(--border-dark);
  border-radius: 3px;
}
/* Prevent table column squishing on smaller devices */
.table-responsive table {
  min-width: 700px;
}
/* Utility to allow narrow tables to shrink if needed */
.table-responsive table.table-narrow {
  min-width: auto;
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
  backdrop-filter: blur(2px); /* premium design aesthetics */
  transition: opacity 0.25s ease;
}
.sidebar-overlay.active {
  display: block;
}

/* ── Breakpoints ────────────────────────────────────────────── */

/* Tablet Viewport (Laptops/Screens <= 900px) */
@media (max-width: 900px) {
  .sidebar {
    width: min(85vw, 280px);
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.open {
    width: min(85vw, 280px);
    transform: translateX(0);
    box-shadow: 0 0 30px rgba(0,0,0,0.25);
  }
  .main-wrapper {
    margin-left: 0;
  }
  .sidebar-toggle {
    display: block;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .form-grid-3 {
    grid-template-columns: 1fr 1fr;
  }
}

/* Intermediate screen adjustments (e.g. tablet vertical <= 768px) */
@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Mobile Viewport (Phones <= 600px) */
@media (max-width: 600px) {
  html {
    font-size: 14px; /* Elegant scaling */
  }
  .main-content {
    padding: 1rem;
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  .page-header h2 {
    font-size: 1.15rem;
  }
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
  .form-grid, .form-grid-3 {
    grid-template-columns: 1fr;
  }
  .col-span-2, .col-span-3 {
    grid-column: span 1;
  }
  .detail-grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  .login-card {
    padding: 1.5rem;
  }
  .top-bar-right {
    width: 100%;
    justify-content: flex-start;
  }
  .table-responsive table {
    min-width: auto;
  }
  .table-responsive thead th,
  .table-responsive tbody td {
    padding: .65rem .75rem;
  }
  .modal-overlay {
    padding: 0.5rem;
  }
  .modal-footer {
    flex-direction: column-reverse;
  }
  .modal-footer .btn {
    width: 100%;
    justify-content: center;
  }
}
