/* ─── ERP FSM - Stylesheet ─────────────────────────────────────────────── */

:root {
  --sidebar-width: 248px;
  --sidebar-bg: #1a2744;
  --sidebar-hover: rgba(255,255,255,.08);
  --sidebar-active: rgba(255,255,255,.15);
  --topbar-height: 56px;
  --brand-primary: #2563eb;
  --brand-secondary: #0ea5e9;
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
body { font-family: 'Inter', system-ui, -apple-system, sans-serif; font-size: .875rem; }
.x-small { font-size: .7rem; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  z-index: 1040;
  transition: transform .25s ease;
  overflow-y: auto; overflow-x: hidden;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px; min-height: var(--topbar-height);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-icon {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--brand-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; color: #fff; flex-shrink: 0;
}
.brand-name { color: #fff; font-weight: 700; font-size: .95rem; letter-spacing: .02em; }

.sidebar-user {
  display: flex; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-user img { flex-shrink: 0; border: 2px solid rgba(255,255,255,.2); }

.sidebar-nav { padding: 8px 10px; flex: 1; }
.nav-section-label {
  font-size: .65rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: rgba(255,255,255,.35);
  padding: 10px 8px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; margin-bottom: 1px;
  color: rgba(255,255,255,.75); text-decoration: none;
  font-size: .83rem; font-weight: 500; cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap; overflow: hidden;
}
.nav-item:hover  { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-item i { font-size: 1rem; flex-shrink: 0; width: 20px; text-align: center; }

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

/* ── Topbar ───────────────────────────────────────────────────────────────── */
#topbar {
  height: var(--topbar-height);
  background: var(--bs-body-bg);
  border-bottom: 1px solid var(--bs-border-color);
  display: flex; align-items: center;
  padding: 0 20px; gap: 12px;
  position: sticky; top: 0; z-index: 100;
}

/* ── Page Content ─────────────────────────────────────────────────────────── */
#page-content { flex: 1; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card { border: 1px solid var(--bs-border-color); border-radius: 12px; }
.card-header { background: transparent; border-bottom: 1px solid var(--bs-border-color); }
.stat-card {
  border-radius: 12px; padding: 20px;
  border: 1px solid var(--bs-border-color);
  background: var(--bs-body-bg);
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0,0,0,.07); }
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
}
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .75rem; color: var(--bs-secondary-color); margin-top: 4px; }

/* ── Status badges ────────────────────────────────────────────────────────── */
.status-badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 20px; font-size: .72rem; font-weight: 600; white-space: nowrap; }
.status-new         { background: #e0f2fe; color: #0369a1; }
.status-pending_payment { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.status-scheduled   { background: #f0f9ff; color: #0284c7; }
.status-in_transit  { background: #fef3c7; color: #b45309; }
.status-in_progress { background: #fef3c7; color: #d97706; }
.status-paused      { background: #f3f4f6; color: #6b7280; }
.status-completed   { background: #dcfce7; color: #16a34a; }
.status-invoiced    { background: #d1fae5; color: #059669; }
.status-cancelled   { background: #fee2e2; color: #dc2626; }
.status-waiting_parts     { background: #fce7f3; color: #be185d; }
.status-waiting_approval  { background: #ede9fe; color: #7c3aed; }
.priority-emergency { background: #fee2e2; color: #dc2626; }
.priority-urgent    { background: #fef3c7; color: #b45309; }
.priority-high      { background: #fce7f3; color: #be185d; }
.priority-normal    { background: #e0f2fe; color: #0369a1; }
.priority-low       { background: #f0fdf4; color: #16a34a; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-hover > tbody > tr { cursor: pointer; }
.table th { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--bs-secondary-color); white-space: nowrap; }
.table td { vertical-align: middle; font-size: .83rem; }
.table-actions { white-space: nowrap; width: 1%; }

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pagination-wrapper { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--bs-border-color); }
.pagination-info { font-size: .78rem; color: var(--bs-secondary-color); }

/* ── Timeline ─────────────────────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 4px; bottom: 4px; width: 2px; background: var(--bs-border-color); }
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-dot { position: absolute; left: -24px; top: 4px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 2px var(--bs-border-color); }
.timeline-time { font-size: .72rem; color: var(--bs-secondary-color); }
.timeline-label { font-size: .78rem; font-weight: 600; margin-bottom: 2px; }
.timeline-note  { font-size: .78rem; color: var(--bs-secondary-color); }

/* ── Chat messages ────────────────────────────────────────────────────────── */
.chat-container { height: 350px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.chat-bubble { max-width: 75%; }
.chat-bubble.mine { align-self: flex-end; }
.chat-bubble.mine .bubble-body { background: var(--brand-primary); color: #fff; border-radius: 18px 4px 18px 18px; }
.chat-bubble .bubble-body { background: var(--bs-tertiary-bg); border-radius: 4px 18px 18px 18px; padding: 8px 14px; font-size: .83rem; }
.bubble-meta { font-size: .68rem; color: var(--bs-secondary-color); margin-top: 3px; }
.chat-bubble.mine .bubble-meta { text-align: right; }

/* ── Kanban ───────────────────────────────────────────────────────────────── */
.kanban-board { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 8px; }
.kanban-col { min-width: 260px; max-width: 280px; flex-shrink: 0; }
.kanban-col-header { padding: 10px 14px; border-radius: 8px 8px 0 0; font-weight: 600; font-size: .83rem; display: flex; align-items: center; justify-content: space-between; }
.kanban-col-body { background: var(--bs-tertiary-bg); border-radius: 0 0 8px 8px; padding: 8px; min-height: 100px; }
.kanban-card { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color); border-radius: 8px; padding: 12px; margin-bottom: 8px; cursor: grab; font-size: .82rem; }
.kanban-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-label { font-weight: 500; font-size: .82rem; margin-bottom: 4px; }
.form-control, .form-select { font-size: .85rem; }
.form-section { border-bottom: 1px solid var(--bs-border-color); padding-bottom: 20px; margin-bottom: 20px; }
.form-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.form-section-title { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--bs-secondary-color); margin-bottom: 14px; }

/* ── Offcanvas / Drawers ──────────────────────────────────────────────────── */
.offcanvas.offcanvas-end { width: min(600px, 95vw); }
.offcanvas.offcanvas-wide { width: min(800px, 98vw); }
.offcanvas-header { border-bottom: 1px solid var(--bs-border-color); }
.offcanvas-footer { border-top: 1px solid var(--bs-border-color); padding: 12px 16px; display: flex; gap: 8px; justify-content: flex-end; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  #main-wrapper { margin-left: 0; }
  #sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1039; }
  #sidebar-overlay.d-none { display: none !important; }
}

/* ── Dark mode ────────────────────────────────────────────────────────────── */
[data-bs-theme="dark"] {
  --sidebar-bg: #0f172a;
}
[data-bs-theme="dark"] .stat-card,
[data-bs-theme="dark"] .kanban-col-body { background: #1e293b; }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.cursor-pointer { cursor: pointer; }
.text-truncate-2 { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.bg-primary-subtle-custom { background: rgba(37,99,235,.08); }
.rotate-180 { transform: rotate(180deg); }
.spinner-overlay { position: absolute; inset: 0; background: rgba(255,255,255,.7); display: flex; align-items: center; justify-content: center; border-radius: inherit; z-index: 10; }
[data-bs-theme="dark"] .spinner-overlay { background: rgba(0,0,0,.5); }

/* ── Empty states ─────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--bs-secondary-color); }
.empty-state i { font-size: 3rem; opacity: .35; display: block; margin-bottom: 16px; }
.empty-state h6 { font-weight: 600; color: var(--bs-body-color); }

/* Prevent stacked backdrops */
.modal-backdrop ~ .modal-backdrop { display: none !important; }

/* ── Info Row (label + valor) — usado em detalhes de OS, orçamentos, contratos, etc. ── */
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid var(--bs-border-color);
}
.info-row:last-child { border-bottom: none; }
.info-row > span:first-child { flex-shrink: 0; white-space: nowrap; }
.info-row > span:last-child { text-align: right; }

/* ── Chips de selecção (método de pagamento, serviços, etc.) — usado em várias páginas ── */
.svc-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 20px;
  border: 2px solid var(--bs-border-color);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: all .15s;
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
}
.svc-chip:hover { border-color: #93c5fd; }
.svc-chip.selected {
  border-color: #2563eb;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 700;
  box-shadow: 0 0 0 1px #2563eb inset;
}
[data-bs-theme="dark"] .svc-chip.selected { background: rgba(37,99,235,.2); color: #93c5fd; }
.svc-chip.required { border-color: #dc2626; background: #fef2f2; color: #b91c1c; cursor: default; }
