/* ── Layout shell ─────────────────────────────────────────────────── */

body {
  min-height: 100vh;
  background: var(--bg-alt);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--topbar-height);
  padding: 0 16px;
  background: var(--bg-dark);
  color: var(--white);
  border-bottom: 1px solid var(--border-dk);
}

.topbar__home {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--white);
  font-size: 18px;
  border-radius: 6px;
  transition: var(--transition);
}

.topbar__home:hover {
  background: rgba(255,255,255,0.08);
}

.topbar__brand {
  font-family: var(--heading);
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
}

.topbar__title {
  font-size: 13px;
  color: var(--on-dark-muted);
  display: none;
}

@media (min-width: 601px) {
  .topbar__title { display: block; }
}

.topbar__spacer { flex: 1; }

.topbar__nav {
  display: none;
  gap: 4px;
}

@media (min-width: 901px) {
  .topbar__nav { display: flex; }
}

.topbar__link {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--on-dark-muted);
  transition: var(--transition);
}

.topbar__link:hover,
.topbar__link.is-active {
  background: rgba(255,255,255,0.08);
  color: var(--white);
}

.topbar__hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  color: var(--white);
}

@media (min-width: 901px) {
  .topbar__hamburger { display: none; }
}

.nav-overlay__logout {
  color: var(--on-dark-muted);
  font-size: 16px;
  text-align: left;
  padding: 14px 12px;
  border-radius: 8px;
  margin-top: 12px;
  padding-top: 24px;
  border-top: 1px solid var(--on-dark-border);
  transition: var(--transition);
}

.nav-overlay__logout:hover {
  background: rgba(255,255,255,0.08);
  color: var(--white);
}

.nav-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg-dark);
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.nav-overlay[hidden] { display: none !important; }

.nav-overlay__close {
  align-self: flex-end;
  color: var(--white);
  width: 40px;
  height: 40px;
  font-size: 22px;
}

.nav-overlay__links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 24px;
}

.nav-overlay__links a {
  padding: 14px 12px;
  color: var(--white);
  font-size: 16px;
  border-radius: 8px;
}

.nav-overlay__links a:hover,
.nav-overlay__links a.is-active {
  background: rgba(255,255,255,0.08);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

@media (min-width: 901px) {
  main { padding: 32px 40px 80px; }
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.page-header h1 {
  font-family: var(--heading);
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

/* ── Buttons ──────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--sans);
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: var(--white);
}
.btn-primary:hover { background: var(--accent-dark); }

.btn-secondary {
  background: var(--white);
  color: var(--text-mid);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 10px;
}
.btn-ghost:hover { color: var(--accent); }

.btn-danger {
  background: transparent;
  color: #c0392b;
  border: 1px solid #e6b3ac;
}
.btn-danger:hover { background: #fdecea; }

.btn-sm { padding: 6px 10px; font-size: 12.5px; }

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Cards ────────────────────────────────────────────────────────── */

.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.card + .card { margin-top: 12px; }

.section {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 16px;
}

.section h2 {
  font-family: var(--heading);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}

.project-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
}

.project-card__top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.project-card__name {
  font-family: var(--heading);
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.project-card__client {
  font-size: 13px;
  color: var(--text-muted);
}

.project-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 601px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 901px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

/* ── Status badges ────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--white);
  white-space: nowrap;
}

.badge[data-estado="creado"]           { background: var(--status-creado); }
.badge[data-estado="presupuestado"]    { background: var(--status-presupuestado); }
.badge[data-estado="en_curso"]         { background: var(--status-en_curso); }
.badge[data-estado="pendiente_cobro"]  { background: var(--status-pendiente_cobro); }
.badge[data-estado="cobrado"]          { background: var(--status-cobrado); }
.badge[data-estado="finalizado"]       { background: var(--status-finalizado); }

.badge[data-estado="borrador"]  { background: var(--status-borrador); }
.badge[data-estado="enviado"]   { background: var(--status-enviado); }
.badge[data-estado="aceptado"]  { background: var(--status-aceptado); }
.badge[data-estado="rechazado"] { background: var(--status-rechazado); }
.badge[data-estado="anulado"],
.badge[data-estado="anulada"]   { background: var(--status-anulado); color: var(--text-mid); }

.badge[data-estado="emitida"]   { background: var(--status-emitida); }
.badge[data-estado="cobrada"]   { background: var(--status-cobrada); }
.badge[data-estado="vencida"]   { background: var(--status-vencida); }

.badge[data-estado="pendiente"] { background: var(--status-pendiente_cobro); }
.badge[data-estado="firmado"]   { background: var(--status-firmado); }
.badge[data-estado="expirado"]  { background: var(--status-finalizado); }
.badge[data-estado="emitido"]   { background: var(--status-emitida); }

.badge[data-estado="rect"] { background: var(--accent); }

/* ── Forms ────────────────────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-mid);
}

.field input,
.field select,
.field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--sans);
  color: var(--text);
  background: var(--white);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.field textarea { resize: vertical; min-height: 70px; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  padding: 12px;
  background: var(--bg-alt);
  border-radius: 8px;
  margin-top: 10px;
}

.inline-form[hidden] { display: none !important; }

.inline-form .field { margin-bottom: 0; min-width: 120px; flex: 1; }

.error-text {
  color: #c0392b;
  font-size: 13px;
  margin-top: 6px;
}

/* ── Tables / lists ───────────────────────────────────────────────── */

.data-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table th,
.data-table td {
  word-break: break-word;
}

.data-table th:nth-child(1), .data-table td:nth-child(1) { width: 40%; }
.data-table th:nth-child(2), .data-table td:nth-child(2) { width: 25%; }
.data-table th:nth-child(3), .data-table td:nth-child(3) { width: 20%; }
.data-table th:nth-child(4), .data-table td:nth-child(4) { width: 15%; }

.data-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-mid);
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr.is-clickable { cursor: pointer; }
.data-table tr.is-clickable:hover { background: var(--bg-alt); }

.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

.list-row:last-child { border-bottom: none; }
.list-row__main { flex: 1; min-width: 0; }
.list-row__meta { color: var(--text-muted); font-size: 12.5px; }

.nota-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

.nota-row:last-child { border-bottom: none; }
.nota-row__main { flex: 1; min-width: 0; white-space: pre-wrap; word-break: break-word; }
.nota-row__meta { color: var(--text-muted); font-size: 12px; margin-bottom: 4px; }

.totals-row {
  display: flex;
  justify-content: flex-end;
  gap: 24px;
  padding-top: 12px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
}

.totals-row__item { text-align: right; }
.totals-row__label { font-size: 12px; color: var(--text-muted); }
.totals-row__value { font-size: 14px; font-weight: 600; color: var(--text); }
.totals-row__value--total { font-size: 18px; color: var(--accent); }

/* ── Stat badges ──────────────────────────────────────────────────── */

.stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.stat-pill {
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-mid);
}

.stat-pill strong { color: var(--text); font-weight: 700; }

a.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: var(--transition);
}

a.stat-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Concept form (mobile-first stacking) ────────────────────────────── */

.concept-form .form-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@media (min-width: 601px) {
  .concept-form .form-row { flex-direction: row; }
}

.catalog-search { position: relative; }

.catalog-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 4px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.14);
}

.catalog-dropdown-item {
  padding: 10px 12px;
  font-size: 13.5px;
  color: var(--text-mid);
  cursor: pointer;
}

.catalog-dropdown-item:hover { background: var(--bg-alt); }

.catalog-dropdown-empty {
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Element catalog cards ────────────────────────────────────────────── */

.element-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 601px) {
  .element-grid { grid-template-columns: 1fr 1fr; }
}

.element-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.element-card__top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.element-card__name {
  font-family: var(--heading);
  font-weight: 600;
  font-size: 14.5px;
  color: var(--text);
}

.element-card__meta {
  font-size: 12.5px;
  color: var(--text-muted);
}

.element-card__actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 16px;
  transition: var(--transition);
}

.icon-btn:hover { background: var(--bg-alt); color: var(--accent); }
.icon-btn.icon-btn--danger:hover { background: #fdecea; color: #c0392b; }

.confirm-inline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 13px;
  color: var(--text-mid);
}

.confirm-inline span {
  flex: 1 1 auto;
}

.confirm-inline-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.confirm-inline button {
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 6px;
  min-height: 36px;
}

.confirm-inline .confirm-yes {
  background: #ef4444;
  color: white;
}

.confirm-inline .confirm-no {
  background: var(--bg-alt);
  color: var(--text);
}

/* ── Login ────────────────────────────────────────────────────────── */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg-dark);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--white);
  border-radius: 14px;
  padding: 32px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.login-card__logo {
  font-family: var(--heading);
  font-weight: 700;
  font-size: 20px;
  color: var(--text);
  margin-bottom: 4px;
}

.login-card__sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* ── Archivos multimedia ──────────────────────────────────────────── */

.archivos-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.archivos-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
  padding-bottom: 8px;
}

.archivo-thumb {
  flex: 0 0 auto;
  width: 140px;
  height: 140px;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  scroll-snap-align: start;
  background: var(--bg-alt);
  border: 1px solid var(--border);
}

.archivo-thumb img,
.archivo-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: pointer;
}

.archivo-thumb .thumb-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0);
  transition: background 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.archivo-thumb:hover .thumb-overlay,
.archivo-thumb:active .thumb-overlay {
  background: rgba(0,0,0,0.35);
}

.archivo-thumb .btn-delete-archivo {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.archivo-thumb .play-icon {
  font-size: 32px;
  color: white;
  pointer-events: none;
}

.archivo-thumb .archivo-confirm {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(0,0,0,0.72);
}

.archivo-thumb .archivo-confirm button {
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  min-height: 36px;
}

.archivo-thumb .archivo-confirm .confirm-yes {
  background: #ef4444;
  color: white;
}

.archivo-thumb .archivo-confirm .confirm-no {
  background: rgba(255,255,255,0.95);
  color: var(--text);
}

/* Visually hidden but still in the layout — some mobile browsers (notably
   iOS Safari) won't reliably open the file picker for a programmatic
   .click() on an input with display:none. */
.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.archivo-thumb--documento {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  text-align: center;
}

.archivo-thumb--documento .documento-icon {
  font-size: 32px;
  color: var(--text-muted);
}

.archivo-thumb--documento .documento-nombre {
  font-size: 11px;
  color: var(--text-mid);
  word-break: break-word;
  max-height: 42px;
  overflow: hidden;
}

.archivo-thumb--documento a {
  color: var(--accent);
  text-decoration: underline;
}

.archivo-descripcion {
  font-size: 11px;
  color: var(--text-dim);
  padding: 4px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.queue-previews {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0;
}

.queue-thumb {
  flex: 0 0 auto;
  width: 80px;
  height: 80px;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  background: var(--bg-alt);
  border: 1px solid var(--border);
}

.queue-thumb img,
.queue-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.queue-thumb .btn-remove-queue {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 11px;
  cursor: pointer;
}

.anexo-check-row {
  margin-bottom: 12px;
  font-size: 13.5px;
  color: var(--text-mid);
}

.anexo-check-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

/* ── Danger zone (collapsed) ──────────────────────────────────────── */

.danger-zone-toggle { margin-bottom: 16px; }

.btn-danger-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.btn-danger-toggle:hover {
  border-color: #ef4444;
  color: #ef4444;
}

/* ── Accordion sections ───────────────────────────────────────────── */

.accordion-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  cursor: pointer;
  margin-bottom: 0;
  user-select: none;
}

.accordion-header h2 { margin-bottom: 0; }

.accordion-chevron {
  flex: 0 0 auto;
  display: inline-block;
  width: 14px;
  font-size: 11px;
  color: var(--text-muted);
}

.accordion-summary {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.accordion-header .toggle-anulados {
  margin-left: auto;
}

.accordion-body {
  margin-top: 14px;
}

.accordion-body[hidden] {
  display: none;
}

.section-add-toggle {
  margin-top: 12px;
}

/* ── Documents: anulados toggle + edit rows ──────────────────────────── */

.toggle-anulados {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}

.doc-anulado {
  opacity: 0.5;
}

.doc-anulado .doc-numero {
  text-decoration: line-through;
}

.doc-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

.doc-row:last-child { border-bottom: none; }

.doc-row__main {
  display: flex;
  align-items: center;
  gap: 10px;
}

.doc-row__main .list-row__main { flex: 1; min-width: 0; }

.doc-row__ref {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Misc ─────────────────────────────────────────────────────────── */

.text-muted { color: var(--text-muted); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.spinner-text {
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px 0;
}
