/* ============================================================
   SIMOLAT PORTAL — Hoja de estilos completa
   ============================================================ */

/* ---- VARIABLES ---- */
:root {
  --primary:            #1a3a5c;
  --primary-dark:       #122a43;
  --primary-light:      #2a5a8c;
  --accent:             #e8a020;
  --accent-dark:        #c88010;
  --sidebar-w:          260px;
  --sidebar-collapsed-w:64px;
  --topbar-h:           60px;
  --radius:             .55rem;
  --shadow-sm:          0 1px 4px rgba(0,0,0,.07);
  --shadow-md:          0 3px 12px rgba(0,0,0,.1);
  --border-color:       #dee2e6;
  --bg-page:            #f0f2f5;
  --text-muted:         #6c757d;
  --font-size-sm:       .83rem;
  --font-size-xs:       .74rem;
}

/* ---- RESET / BASE ---- */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', sans-serif;
  background: var(--bg-page);
  color: #212529;
  font-size: .9rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }
a:hover { color: var(--primary-light); }

/* ============================================================
   SIDEBAR
   ============================================================ */

#sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--primary);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width .22s ease, transform .25s ease;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 2px; }

/* Marca / logo */
#sidebar .sidebar-brand {
  padding: 1.1rem 1.2rem .9rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
  flex-shrink: 0;
}

#sidebar .sidebar-brand .brand-icon {
  font-size: 1.8rem;
  color: var(--accent);
  line-height: 1;
}

#sidebar .sidebar-brand h5 {
  color: #fff;
  font-weight: 700;
  font-size: .95rem;
  margin: .25rem 0 0;
  letter-spacing: -.01em;
}

#sidebar .sidebar-brand small {
  color: rgba(255,255,255,.45);
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* Secciones de nav */
.nav-section {
  padding: .9rem .9rem .25rem 1.1rem;
  font-size: .6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(255,255,255,.3);
  user-select: none;
}

/* Links del sidebar */
#sidebar .nav-link {
  color: rgba(255,255,255,.72);
  padding: .42rem 1rem;
  margin: 1px .45rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: .84rem;
  text-decoration: none;
  transition: background .14s, color .14s;
  white-space: nowrap;
}

#sidebar .nav-link i {
  font-size: 1.05rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
  opacity: .85;
}

#sidebar .nav-link:hover {
  background: rgba(255,255,255,.1);
  color: #fff;
}

#sidebar .nav-link:hover i { opacity: 1; }

#sidebar .nav-link.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

#sidebar .nav-link.active i { opacity: 1; }

/* Pie del sidebar */
#sidebar .sidebar-footer {
  margin-top: auto;
  border-top: 1px solid rgba(255,255,255,.1);
  padding: .6rem .45rem .8rem;
  flex-shrink: 0;
}

/* Badge contador sidebar */
#sidebar .nav-badge {
  margin-left: auto;
  background: rgba(255,255,255,.2);
  color: #fff;
  font-size: .6rem;
  padding: .15rem .45rem;
  border-radius: 99px;
  font-weight: 600;
  flex-shrink: 0;
}

#sidebar .nav-link.active .nav-badge {
  background: rgba(0,0,0,.2);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */

#main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left .22s ease;
}

/* ============================================================
   TOPBAR
   ============================================================ */

#topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 1.4rem;
  gap: .85rem;
  z-index: 900;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

#sidebar-toggle {
  display: block;
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--primary);
  padding: 0;
  line-height: 1;
  cursor: pointer;
}

.page-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--primary);
  margin: 0;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-shrink: 0;
}

/* Si no hi cap tot en una línia (pàgines amb molts botons, iPad en horitzontal, finestres estretes),
   els botons baixen a la línia següent en lloc de tallar-se. Amb espai de sobres no canvia res. */
#topbar {
  height: auto;
  min-height: var(--topbar-h);
  flex-wrap: wrap;
  row-gap: .35rem;
  padding-top: .45rem;
  padding-bottom: .45rem;
}
.page-title { flex: 1 1 8rem; }
.topbar-actions {
  flex-shrink: 1;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 100%;
  row-gap: .35rem;
  margin-left: auto;
}

/* Breadcrumb en topbar */
.topbar-breadcrumb {
  font-size: .75rem;
  color: var(--text-muted);
}

.topbar-breadcrumb a {
  color: var(--text-muted);
  text-decoration: none;
}

.topbar-breadcrumb a:hover { color: var(--primary); }

/* ============================================================
   CONTENT AREA
   ============================================================ */

#content {
  flex: 1;
  padding: 1.4rem 1.5rem;
  min-width: 0;
}

footer#page-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: .68rem;
  padding: .6rem;
  border-top: 1px solid #eee;
  flex-shrink: 0;
}

/* ============================================================
   CARDS
   ============================================================ */

.card {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: #fff;
  overflow: hidden; /* evita que les taules sobrepassin la card */
}

/* ── Taules scrollables dins de cards ──────────────────────────────────────── */
.card .table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
/* Degradat + icona de scroll quan la taula és més ampla que la card */
.card .table-responsive.is-scrollable::after {
  content: '⟷';
  position: sticky;
  right: 0;
  bottom: 0;
  display: block;
  width: 100%;
  text-align: right;
  padding: 2px 10px 2px 40px;
  background: linear-gradient(to right, transparent, rgba(255,255,255,.92) 40%);
  color: #adb5bd;
  font-size: .75rem;
  pointer-events: none;
  margin-top: -1.6rem;
  line-height: 1.6rem;
}
/* Indicador al card-header quan la taula és scrollable */
.card-header .scroll-hint {
  margin-left: auto;
  color: #adb5bd;
  font-size: .72rem;
  display: flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  flex-shrink: 0;
}
.card-header .scroll-hint i { font-size: .8rem; }

.card-header {
  background: #fff;
  border-bottom: 1px solid #f0f2f5;
  font-weight: 600;
  font-size: .88rem;
  padding: .8rem 1.1rem;
  border-radius: var(--radius) var(--radius) 0 0 !important;
  display: flex;
  align-items: center;
}

.card-header .card-actions {
  margin-left: auto;
  display: flex;
  gap: .4rem;
  align-items: center;
}

.card-footer {
  background: #fafbfc;
  border-top: 1px solid #f0f2f5;
  padding: .7rem 1.1rem;
  font-size: var(--font-size-sm);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* Card destacada con borde de color */
.card-accent-left {
  border-left: 4px solid var(--accent) !important;
}

.card-accent-primary {
  border-left: 4px solid var(--primary) !important;
}

/* ============================================================
   STAT CARDS (dashboard)
   ============================================================ */

.stat-card {
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
  color: #fff;
  text-decoration: none;
  transition: transform .15s, box-shadow .15s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  color: #fff;
}

.stat-icon {
  font-size: 2rem;
  opacity: .8;
  flex-shrink: 0;
}

.stat-value {
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1;
}

.stat-label {
  font-size: .75rem;
  opacity: .85;
  margin-top: .15rem;
}

.stat-primary  { background: linear-gradient(135deg, #1a3a5c 0%, #2a5a8c 100%); }
.stat-success  { background: linear-gradient(135deg, #157347 0%, #198754 100%); }
.stat-warning  { background: linear-gradient(135deg, #c88010 0%, #e8a020 100%); }
.stat-danger   { background: linear-gradient(135deg, #b02a37 0%, #dc3545 100%); }
.stat-purple   { background: linear-gradient(135deg, #4e2d7a 0%, #6f42c1 100%); }
.stat-teal     { background: linear-gradient(135deg, #0d6b7a 0%, #0dcaf0 100%); }
.stat-indigo   { background: linear-gradient(135deg, #2b2d8a 0%, #6610f2 100%); }
.stat-orange   { background: linear-gradient(135deg, #c05000 0%, #fd7e14 100%); }

/* ============================================================
   TABLAS
   ============================================================ */

.table {
  font-size: var(--font-size-sm);
  margin-bottom: 0;
}

.table th {
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  font-weight: 600;
  border-top: none;
  white-space: nowrap;
  padding: .6rem .75rem;
  background: #fafbfc;
}

.table td {
  vertical-align: middle;
  padding: .6rem .75rem;
  border-color: #f0f2f5;
}

.table-hover tbody tr {
  cursor: pointer;
  transition: background .1s;
}

.table-hover tbody tr:hover {
  background: #f4f7ff;
}

/* Columna acciones (no clickable) */
.td-actions {
  cursor: default !important;
  width: 1%;
  white-space: nowrap;
  text-align: right;
}

/* Tabla compacta para detalles */
.table-detail th {
  font-weight: 500;
  font-size: var(--font-size-xs);
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
  width: 38%;
  background: transparent;
  padding: .45rem .6rem;
}

.table-detail td {
  padding: .45rem .6rem;
  font-size: var(--font-size-sm);
}

/* Bootstrap no porta aquesta classe i les vistes la fan servir perquè el text retallat no surti de la card */
.min-width-0 { min-width: 0; }

/* Taules etiqueta-valor (fitxes): l'etiqueta i el valor parteixen línia en lloc de tallar-se a la vora de la card */
.table-borderless th { white-space: normal; }
.table-borderless td { overflow-wrap: anywhere; }

/* ============================================================
   FORMULARIOS
   ============================================================ */

.form-label {
  font-weight: 500;
  font-size: .84rem;
  margin-bottom: .3rem;
  color: #344054;
}

.form-label .required {
  color: #dc3545;
  margin-left: 2px;
}

.form-control,
.form-select {
  font-size: var(--font-size-sm);
  border-color: #ced4da;
  border-radius: .4rem;
  padding: .42rem .75rem;
  transition: border-color .15s, box-shadow .15s;
}

/* El padding de dalt treia l'espai de la fletxa: amb amplada automàtica el text quedava a sota */
.form-select { padding-right: 2.25rem; }

.form-control:focus,
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 .18rem rgba(26,58,92,.15);
  outline: none;
}

.form-control.is-invalid:focus,
.form-select.is-invalid:focus {
  box-shadow: 0 0 0 .18rem rgba(220,53,69,.15);
}

.form-control-sm,
.form-select-sm {
  font-size: var(--font-size-xs);
  padding: .3rem .6rem;
}
.form-select.form-select-sm { padding-right: 1.9rem; }

.form-text {
  font-size: .74rem;
  color: var(--text-muted);
}

/* Switch */
.form-switch .form-check-input {
  cursor: pointer;
  width: 2.4em;
  height: 1.3em;
}

.form-switch .form-check-input:checked {
  background-color: var(--primary);
  border-color: var(--primary);
}

/* Input con icono prefijo */
.input-icon-wrap {
  position: relative;
}

.input-icon-wrap .input-icon {
  position: absolute;
  left: .7rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: .9rem;
}

.input-icon-wrap .form-control {
  padding-left: 2.2rem;
}

/* Sección de formulario */
.form-section {
  margin-bottom: 1.5rem;
}

.form-section-title {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--primary);
  border-bottom: 2px solid var(--primary);
  padding-bottom: .3rem;
  margin-bottom: 1rem;
}

/* ============================================================
   BOTONES
   ============================================================ */

.btn {
  font-size: var(--font-size-sm);
  border-radius: .4rem;
  font-weight: 500;
  transition: all .15s;
}

.btn-sm { font-size: var(--font-size-xs); padding: .28rem .65rem; }
.btn-xs { font-size: .7rem; padding: .18rem .5rem; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover, .btn-primary:focus {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: #fff;
}

.btn-outline-primary {
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline-primary:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-accent:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #fff;
}

/* Botón icono solo */
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: .4rem;
}

/* ============================================================
   BADGES
   ============================================================ */

.badge {
  font-weight: 500;
  font-size: .68rem;
  letter-spacing: .02em;
  padding: .3em .6em;
  border-radius: .35rem;
}

/* Badges departamento */
.dept-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2em .55em;
  border-radius: .35rem;
  font-size: .68rem;
  font-weight: 600;
}

.dept-sound       { background: #cfe2ff; color: #084298; }
.dept-lighting    { background: #fff3cd; color: #664d03; }
.dept-video       { background: #d1e7dd; color: #0a3622; }
.dept-staging     { background: #e8d5f5; color: #3d1a6a; }
.dept-production  { background: #fde8d3; color: #6e2800; }
.dept-admin       { background: #e2e3e5; color: #41464b; }
.dept-direction   { background: #f8d7da; color: #842029; }

/* Badge tipo personal */
.badge-employee   { background: #cfe2ff; color: #084298; }
.badge-freelance  { background: #fff3cd; color: #664d03; }
.badge-external   { background: #e2e3e5; color: #41464b; }

/* ============================================================
   ALERTAS / FLASH
   ============================================================ */

.flash-container {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 9999;
  width: 340px;
  max-width: calc(100vw - 40px);
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.flash-container .alert {
  font-size: var(--font-size-sm);
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: .75rem 1rem;
}

/* ============================================================
   LOGIN
   ============================================================ */

.login-page {
  min-height: 100vh;
  background: linear-gradient(160deg, var(--primary) 0%, #2c6496 60%, #1a5080 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 420px;
  border: none;
  border-radius: 1rem;
  box-shadow: 0 16px 48px rgba(0,0,0,.3);
  overflow: hidden;
}

.login-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  padding: 2.2rem 1.5rem 1.8rem;
  text-align: center;
}

.login-header .brand-logo-icon {
  font-size: 3rem;
  color: var(--accent);
  line-height: 1;
  display: block;
  margin-bottom: .5rem;
}

.login-header h4 {
  color: #fff;
  font-weight: 700;
  font-size: 1.3rem;
  margin: 0 0 .2rem;
}

.login-header small {
  color: rgba(255,255,255,.6);
  font-size: .78rem;
}

/* ============================================================
   FICHA DE DETALLE (show pages)
   ============================================================ */

.detail-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  margin-bottom: 1.2rem;
  box-shadow: var(--shadow-md);
}

.detail-header h4 {
  color: #fff;
  font-weight: 700;
  margin: 0 0 .2rem;
  font-size: 1.15rem;
}

.detail-header .detail-meta {
  color: rgba(255,255,255,.7);
  font-size: .8rem;
  display: flex;
  flex-wrap: wrap;
  gap: .6rem 1.2rem;
  margin-top: .6rem;
}

.detail-header .detail-meta i {
  margin-right: .25rem;
}

.detail-header .detail-meta a {
  color: #fff !important;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.detail-header .detail-meta a:hover {
  color: rgba(255,255,255,.8) !important;
}

/* Avatar circular con inicial */
.avatar-circle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.3rem;
  color: #fff;
  flex-shrink: 0;
}

.avatar-lg {
  width: 70px;
  height: 70px;
  font-size: 1.8rem;
}

/* ============================================================
   TABS EN FICHAS DE DETALLE
   ============================================================ */

.nav-tabs-custom {
  border-bottom: 2px solid #e9ecef;
  margin-bottom: 1.2rem;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.nav-tabs-custom .nav-link {
  font-size: .83rem;
  font-weight: 500;
  color: var(--text-muted);
  border: none;
  border-bottom: 2px solid transparent;
  padding: .55rem .9rem;
  margin-bottom: -2px;
  border-radius: 0;
  white-space: nowrap;
  text-decoration: none;
  transition: color .15s, border-color .15s;
}

.nav-tabs-custom .nav-link:hover {
  color: var(--primary);
  border-bottom-color: rgba(26,58,92,.3);
}

.nav-tabs-custom .nav-link.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* ============================================================
   UPLOAD DE DOCUMENTOS
   ============================================================ */

.upload-zone {
  border: 2px dashed #ced4da;
  border-radius: var(--radius);
  padding: 1.8rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  background: #fafbfc;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--primary);
  background: #eef3fb;
}

.upload-zone .upload-icon {
  font-size: 2rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: .4rem;
}

.upload-zone p {
  margin: 0;
  font-size: .83rem;
  color: var(--text-muted);
}

.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* Tarjetas de documentos */
.doc-card {
  border: 1px solid #e9ecef;
  border-radius: var(--radius);
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}

.doc-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(26,58,92,.1);
}

.doc-card .doc-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
  width: 2.2rem;
  text-align: center;
}

.doc-card .doc-info { flex: 1; min-width: 0; }

.doc-card .doc-name {
  font-weight: 600;
  font-size: .83rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #212529;
  text-decoration: none;
}

.doc-card .doc-name:hover { color: var(--primary); }

.doc-card .doc-meta {
  font-size: .7rem;
  color: var(--text-muted);
  margin-top: .1rem;
}

.doc-card .doc-actions {
  flex-shrink: 0;
  display: flex;
  gap: .3rem;
}

/* Indicador de vencimiento */
.expiry-ok      { color: #198754; }
.expiry-soon    { color: #c88010; }
.expiry-expired { color: #dc3545; }
.expiry-none    { color: var(--text-muted); }

/* ============================================================
   LÍNEAS DE PRESUPUESTO / FACTURA
   ============================================================ */

.doc-lines-container .doc-line {
  background: #fafbfc;
  border: 1px solid #e9ecef;
  border-radius: var(--radius);
  padding: .75rem;
  margin-bottom: .5rem;
  position: relative;
}

.doc-line.is-section {
  background: var(--primary);
  color: #fff;
}

.doc-line.is-section .form-control {
  background: rgba(255,255,255,.15);
  border-color: rgba(255,255,255,.3);
  color: #fff;
}

.doc-line.is-section .form-control::placeholder { color: rgba(255,255,255,.5); }

.doc-line-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 0 .3rem;
}

.totals-box {
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
}

.totals-box .total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .25rem 0;
  font-size: .85rem;
}

.totals-box .total-row.total-final {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--primary);
  border-top: 2px solid var(--primary);
  margin-top: .4rem;
  padding-top: .6rem;
}

/* ============================================================
   SELECTOR DE ESTADO (proyectos, facturas...)
   ============================================================ */

.status-stepper {
  display: flex;
  align-items: center;
  gap: 0;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.status-step {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.status-step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #dee2e6;
  border: 2px solid #dee2e6;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  color: #fff;
  font-weight: 700;
  transition: all .2s;
}

.status-step.done  .status-step-dot { background: #198754; border-color: #198754; }
.status-step.current .status-step-dot { background: var(--primary); border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,58,92,.2); }

.status-step-line {
  flex: 1;
  min-width: 24px;
  height: 2px;
  background: #dee2e6;
}

.status-step.done + .status-step .status-step-line { background: #198754; }

.status-step-label {
  font-size: .65rem;
  color: var(--text-muted);
  margin-top: .3rem;
  text-align: center;
  white-space: nowrap;
}

.status-step.current .status-step-label,
.status-step.done    .status-step-label {
  color: var(--primary);
  font-weight: 600;
}

/* ============================================================
   TIMELINE / HISTORIAL
   ============================================================ */

.timeline {
  position: relative;
  padding-left: 1.6rem;
}

.timeline::before {
  content: '';
  position: absolute;
  left: .55rem;
  top: .4rem;
  bottom: 0;
  width: 2px;
  background: #e9ecef;
}

.timeline-item {
  position: relative;
  padding-bottom: 1.1rem;
}

.timeline-item:last-child { padding-bottom: 0; }

.timeline-item::before {
  content: '';
  position: absolute;
  left: -1.15rem;
  top: .35rem;
  width: .6rem;
  height: .6rem;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--primary);
}

.timeline-item.warning::before { background: #e8a020; box-shadow: 0 0 0 2px #e8a020; }
.timeline-item.danger::before  { background: #dc3545; box-shadow: 0 0 0 2px #dc3545; }
.timeline-item.success::before { background: #198754; box-shadow: 0 0 0 2px #198754; }

.timeline-time {
  font-size: .7rem;
  color: var(--text-muted);
}

.timeline-content {
  font-size: .83rem;
}

/* ============================================================
   BÚSQUEDA / FILTROS
   ============================================================ */

.filter-bar {
  background: #fff;
  border-radius: var(--radius);
  padding: .7rem 1rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem;
}

.filter-bar .filter-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ============================================================
   PAGINACIÓN
   ============================================================ */

.pagination .page-link {
  font-size: .78rem;
  padding: .3rem .6rem;
  color: var(--primary);
  border-color: #dee2e6;
}

.pagination .page-item.active .page-link {
  background: var(--brand-primary, var(--primary));
  border-color: var(--brand-primary, var(--primary));
  color: #fff;
  font-weight: 600;
}

.pagination .page-item.disabled .page-link {
  color: #adb5bd;
}

/* Botó missatgeria al topbar (substitueix la bombolla flotant) */
#chatTopBtn .badge { font-size: .6rem; }
#chatPanel {
  top: calc(var(--topbar-h) + 6px);
  right: 16px;
  width: min(360px, calc(100vw - 24px));
  height: min(520px, calc(100vh - var(--topbar-h) - 24px));
}

.pagination .page-link:focus {
  box-shadow: 0 0 0 .2rem rgba(26,58,92,.15);
}

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: .75rem;
  opacity: .4;
}

.empty-state h6 {
  font-weight: 600;
  color: #495057;
  margin-bottom: .3rem;
}

.empty-state p {
  font-size: .85rem;
  margin-bottom: 1rem;
}

/* ============================================================
   MODAL CONFIRMACIÓN
   ============================================================ */

.modal-header-danger { background: #dc3545; color: #fff; border-radius: .5rem .5rem 0 0; }
.modal-header-danger .btn-close { filter: brightness(0) invert(1); }

/* ============================================================
   SELECT2 PERSONALIZADO
   ============================================================ */

.select2-container--bootstrap-5 .select2-selection {
  font-size: var(--font-size-sm) !important;
  border-color: #ced4da !important;
  border-radius: .4rem !important;
}

.select2-container--bootstrap-5 .select2-dropdown {
  border-color: var(--primary) !important;
  border-radius: .4rem !important;
  font-size: var(--font-size-sm) !important;
}

.select2-container--bootstrap-5 .select2-results__option--highlighted {
  background: var(--primary) !important;
  color: #fff !important;
}

/* ============================================================
   FLATPICKR PERSONALIZADO
   ============================================================ */

.flatpickr-calendar .flatpickr-day.selected,
.flatpickr-calendar .flatpickr-day.selected:hover {
  background: var(--primary);
  border-color: var(--primary);
}

/* ============================================================
   UTILIDADES
   ============================================================ */

.text-primary  { color: var(--primary) !important; }
.bg-primary    { background-color: var(--primary) !important; color: #fff !important; }
.border-primary { border-color: var(--primary) !important; }

.cursor-pointer { cursor: pointer; }
.cursor-grab    { cursor: grab; }
.cursor-default { cursor: default !important; }

.min-w-0  { min-width: 0; }
.flex-1   { flex: 1; }

.fs-7 { font-size: .82rem !important; }
.fs-8 { font-size: .74rem !important; }
.fs-9 { font-size: .66rem !important; }

.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }

.text-truncate-2 {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.nowrap { white-space: nowrap; }

/* Separador vertical */
.vr-sm { width: 1px; background: #dee2e6; align-self: stretch; margin: .1rem 0; }

/* Highlight búsqueda */
.highlight { background: #fff3cd; border-radius: 2px; padding: 0 2px; }

/* Número / código */
.code-tag {
  font-family: 'Courier New', monospace;
  font-size: .78rem;
  background: #f0f2f5;
  color: var(--primary);
  padding: .15rem .4rem;
  border-radius: .25rem;
  font-weight: 600;
}

/* Indicador activo/inactivo */
.status-dot {
  width: .5rem;
  height: .5rem;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-dot.active   { background: #198754; }
.status-dot.inactive { background: #adb5bd; }

/* ============================================================
   IMPRESIÓN
   ============================================================ */

@media print {
  #sidebar,
  #topbar,
  .topbar-actions,
  .btn,
  .filter-bar,
  footer#page-footer,
  .flash-container,
  .no-print { display: none !important; }

  #main-content { margin-left: 0 !important; }
  #content { padding: 0 !important; }

  body { background: #fff; font-size: 10pt; }

  .card {
    box-shadow: none !important;
    border: 1px solid #ddd !important;
  }

  a[href]::after { content: none !important; }

  .print-header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid var(--primary);
    padding-bottom: .75rem;
    margin-bottom: 1rem;
  }

  .print-header .company-name {
    font-size: 16pt;
    font-weight: 700;
    color: var(--primary);
  }

  .table th { background: #f5f5f5 !important; }
}

/* ============================================================
   RESPONSIVE — MOBILE
   ============================================================ */

/* Overflow: only on #main-content — never on html/body (iOS Safari breaks position:fixed) */
#main-content { overflow-x: hidden; }

/* ============================================================
   SIDEBAR COLLAPSED — desktop icon-only mode
   ============================================================ */

@media (min-width: 1025px) {
  body.sidebar-collapsed #sidebar {
    width: var(--sidebar-collapsed-w);
  }

  body.sidebar-collapsed #main-content {
    margin-left: var(--sidebar-collapsed-w);
  }

  /* Hide text, keep icons — font-size:0 collapses text nodes */
  body.sidebar-collapsed #sidebar .nav-link {
    font-size: 0;
    justify-content: center;
    padding: .45rem 0;
    gap: 0;
    position: relative;
  }

  body.sidebar-collapsed #sidebar .nav-link i {
    font-size: 1.15rem;
    width: auto;
    margin: 0;
  }

  /* Badge in collapsed mode — absolute top-right */
  body.sidebar-collapsed #sidebar .nav-link .badge {
    position: absolute;
    top: 2px;
    right: 3px;
    font-size: .48rem !important;
    min-width: 14px;
    height: 14px;
    padding: 0 2px;
    line-height: 14px;
  }

  /* Section separators — hide label, keep thin line */
  body.sidebar-collapsed #sidebar .nav-section {
    font-size: 0;
    height: 8px;
    padding: 2px 0;
  }

  /* Brand — centered icon only */
  body.sidebar-collapsed #sidebar .sidebar-brand {
    padding: .8rem .25rem;
    text-align: center;
  }

  body.sidebar-collapsed #sidebar .sidebar-brand h5 {
    font-size: 0;
    text-align: center;
    margin: 0;
  }

  body.sidebar-collapsed #sidebar .sidebar-brand h5 i {
    font-size: 1.4rem;
  }

  body.sidebar-collapsed #sidebar .sidebar-brand small {
    display: none;
  }

  body.sidebar-collapsed #sidebar .sidebar-brand img {
    max-width: 36px;
    max-height: 32px;
    object-fit: contain;
  }

  /* Bottom user links */
  body.sidebar-collapsed #sidebar .mt-auto {
    padding: .5rem .25rem 1rem !important;
  }

  body.sidebar-collapsed #sidebar .mt-auto .nav-link {
    font-size: 0;
    justify-content: center;
    padding: .45rem 0;
    gap: 0;
  }

  body.sidebar-collapsed #sidebar .mt-auto .nav-link i {
    font-size: 1.15rem;
  }
}

/* ============================================================
   RESPONSIVE — MOBILE
   ============================================================ */

/* Fins a 1024 px (iPad en vertical, finestres estretes) el menú no ocupa lloc: surt per sobre del contingut.
   El mateix límit és a main.php (SIDEBAR_OVERLAY_MAX): si es canvia, canviar tots dos. */
@media (max-width: 1024px) {
  #sidebar {
    /* Use left instead of transform — avoids stacking context issues */
    left: calc(-1 * var(--sidebar-w)) !important;
    transform: none !important;
    box-shadow: none;
    z-index: 10050 !important; /* above chat bubble (10001) and everything else */
    width: var(--sidebar-w) !important;
    transition: left .28s ease !important;
  }

  #sidebar.open {
    left: 0 !important;
    box-shadow: 4px 0 24px rgba(0,0,0,.35);
  }

  #sidebar-overlay {
    z-index: 10049 !important;
  }

  #main-content { margin-left: 0 !important; }

  .topbar-actions { gap: .3rem; }
  .topbar-actions > * { margin-right: 0 !important; }
  .topbar-actions .btn.btn-sm { padding-left: .45rem; padding-right: .45rem; }

  /* Taules: menys marge entre columnes perquè en quedi més per al text */
  .table th, .table td { padding-left: .5rem; padding-right: .5rem; }
}

@media (max-width: 768px) {
  #content { padding: 1rem; }

  /* Topbar — compact on mobile */
  #topbar {
    padding: .4rem .65rem;
    gap: .4rem;
  }

  .topbar-actions {
    gap: .25rem;
  }

  /* Shrink topbar buttons */
  .topbar-actions .btn.btn-sm {
    padding-left: .4rem;
    padding-right: .4rem;
  }

  /* Hide dropdown-toggle caret text on small screens */
  .topbar-actions .dropdown-toggle::after { display: none; }

  .stat-value { font-size: 1.5rem; }
  .stat-icon  { font-size: 1.5rem; }

  .table-responsive { font-size: .78rem; }

  .page-title { font-size: .9rem; }

  .detail-header { padding: 1rem; }

  /* Panell de xat sota el topbar */
  #chatPanel {
    right: 10px;
    left: 10px;
    width: auto;
  }
}

@media (max-width: 576px) {
  #content { padding: .75rem; }
  .card-body { padding: .85rem; }

  /* Full-screen chat panel on very small screens */
  #chatPanel {
    top: var(--topbar-h);
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: auto;
    border-radius: 0;
  }
}

/* Overlay para sidebar mobile */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1049;
}

#sidebar-overlay.show {
  display: block;
  touch-action: none; /* Prevents background scroll on mobile without body overflow:hidden */
}

/* ============================================================
   ANIMACIONES
   ============================================================ */

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-in-down { animation: fadeInDown .2s ease; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spin { animation: spin 1s linear infinite; }

/* Codi d'OC: es copia en clicar-lo */
.oc-code{cursor:copy;border-bottom:1px dashed currentColor;white-space:nowrap}
.oc-code:hover{opacity:.8}
.oc-code:focus-visible{outline:2px solid var(--bs-primary);outline-offset:2px;border-radius:2px}

/* ============================================================
   EDICIÓ LATERAL (public/js/side-edit.js)
   ============================================================ */
/* Dins l'iframe: sense menú, capçalera, peu ni franges */
html.embed #sidebar,
html.embed #sidebar-overlay,
html.embed #topbar,
html.embed #adminNoticeBanner,
html.embed #impersonateBanner,
html.embed #chatPanel,
html.embed .embed-hide { display: none !important; }
html.embed #main-content { margin-left: 0 !important; min-height: 0; }

.side-edit.offcanvas-end { width: min(1100px, 92vw); }
@media (max-width: 767.98px) { .side-edit.offcanvas-end { width: 100vw; } }
.side-edit iframe { display: block; width: 100%; height: 100%; border: 0; }
.side-edit .side-edit-spin { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(255,255,255,.7); }
.side-edit.is-loading .side-edit-spin { display: flex; }

/* Fila editada, en tornar a la llista */
@keyframes sideEditHl { 0%, 60% { background-color: rgba(255, 193, 7, .35); } 100% { background-color: transparent; } }
.side-edit-hl, .side-edit-hl > td { animation: sideEditHl 2.6s ease-out; }

/* Llistes de factures: les files que no compten (esborrany, anul·lada) van atenuades; amb el desplegable d'estat obert,
   la fila torna a opacitat plena perquè el menú no hereti la transparència */
tr.lg-row.opacity-75:has(.dropdown-menu.show) { opacity: 1 !important; }

/* ── Fitxa de factura emesa (_show_header.php): passos Emesa → Verifactu → Enviada → Cobrada i visor del PDF ── */
.inv-steps { counter-reset: none; }
.inv-step { min-width: 140px; padding: .45rem .7rem; border: 1px solid var(--bs-border-color); border-radius: .5rem; background: var(--bs-body-bg); }
.inv-step-done  { border-color: rgba(var(--bs-success-rgb), .45); background: rgba(var(--bs-success-rgb), .06); }
.inv-step-doing { border-color: rgba(var(--bs-info-rgb), .5); background: rgba(var(--bs-info-rgb), .07); }
.inv-step-bad   { border-color: rgba(var(--bs-danger-rgb), .5); background: rgba(var(--bs-danger-rgb), .07); }
.inv-step-skip  { opacity: .6; border-style: dashed; }
.inv-actions .btn, .inv-actions form { white-space: nowrap; }
.inv-pdf { display: block; width: 100%; height: 75vh; min-height: 520px; border: 0; border-radius: 0 0 .375rem .375rem; }
html.embed .inv-pdf { height: 70vh; }
#invData > summary { cursor: pointer; }

/* Portal de reserva / només lectura (core/Failover.php, partials/failover_banner.php) */
.fo-banner { display: flex; align-items: center; gap: 10px; padding: 7px 20px; font-size: .84rem; position: sticky; top: 0; z-index: 1042; border-bottom: 2px solid rgba(0,0,0,.15); }
.fo-banner.d-none { display: none !important; }
.fo-passive  { background: #0b5ed7; color: #fff; }
.fo-active-b { background: #b45309; color: #fff; }
.fo-ro       { background: #6c757d; color: #fff; }
.fo-notice   { background: #ffc107; color: #212529; }
.fo-observe  { background: #e9ecef; color: #495057; }
@media (max-width: 576px) { .fo-banner { padding: 6px 16px; font-size: .8rem; } }
