/* ============================================================
   app.css — Estilos compartidos de la aplicación FacturaES
   Páginas: clientes, facturas, informes, verifactu, perfil
   ============================================================ */

/* === RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* === VARIABLES === */
:root {
  --bg:        #f5f4f0;
  --surface:   #ffffff;
  --border:    #e2e0d8;
  --accent:    #1a3a5c;
  --accent2:   #2e6da4;
  --accent-lt: #e8f0f8;
  --danger:    #c0392b;
  --danger-lt: #fdf0ee;
  --success:   #1e7d4f;
  --success-lt:#e8f5ee;
  --warn:      #b45309;
  --warn-lt:   #fef3e2;
  --orange:    #b45309;
  --orange-lt: #fff7ed;
  --text:      #1c1b18;
  --muted:     #7a7870;
  --tag-bg:    #eceae3;
  --radius:    10px;
  --shadow:    0 2px 12px rgba(0,0,0,.07);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.13);
  --font:      'DM Sans', sans-serif;
  --mono:      'DM Mono', monospace;
}

/* === BODY === */
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }

/* === TOPBAR === */
.topbar { background: var(--accent); color: #fff; padding: 0 2rem; height: 56px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 100; }
.topbar-brand { font-size: 1.05rem; font-weight: 600; letter-spacing: -.3px; display: flex; align-items: center; gap: .55rem; }
.topbar-brand span { opacity: .5; font-weight: 400; }
.topbar-nav { display: flex; gap: 1.5rem; align-items: center; }
.topbar-nav a { color: rgba(255,255,255,.6); text-decoration: none; font-size: .875rem; transition: color .15s; }
.topbar-nav a:hover, .topbar-nav a.active { color: #fff; }

/* === LAYOUT === */
.page { max-width: 1260px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 1.75rem; flex-wrap: wrap; gap: 1rem; }
.page-title { font-size: 1.6rem; font-weight: 600; letter-spacing: -.5px; }
.page-subtitle { font-size: .875rem; color: var(--muted); margin-top: .2rem; }

/* === STATS (columnas definidas por cada página) === */
.stats { display: grid; gap: 1rem; margin-bottom: 1.75rem; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.3rem; display: flex; align-items: center; gap: 1rem; box-shadow: var(--shadow); }
.stat-icon { width: 40px; height: 40px; border-radius: 8px; background: var(--accent-lt); color: var(--accent2); display: grid; place-items: center; flex-shrink: 0; }
.stat-val { font-size: 1.5rem; font-weight: 600; line-height: 1; font-family: var(--mono); }
.stat-label { font-size: .78rem; color: var(--muted); margin-top: .25rem; }

/* === TOOLBAR === */
.toolbar { display: flex; gap: .75rem; margin-bottom: 1.25rem; align-items: center; flex-wrap: wrap; }
.search-wrap { position: relative; flex: 1; min-width: 220px; }
.search-wrap svg { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; pointer-events: none; }
.search-input, .search-wrap input { width: 100%; padding: .55rem .9rem .55rem 2.3rem; border: 1px solid var(--border); border-radius: var(--radius); font-family: var(--font); font-size: .875rem; background: var(--surface); outline: none; transition: border-color .15s; }
.search-input:focus, .search-wrap input:focus { border-color: var(--accent2); }
.filter-select, .select-anio { padding: .55rem .8rem; border: 1px solid var(--border); border-radius: var(--radius); font-family: var(--font); font-size: .875rem; background: var(--surface); color: var(--text); outline: none; cursor: pointer; }
.filter-select:focus, .select-anio:focus { border-color: var(--accent2); }

/* === BUTTONS === */
.btn { display: inline-flex; align-items: center; gap: .45rem; padding: .55rem 1.1rem; border-radius: var(--radius); border: 1px solid transparent; font-family: var(--font); font-size: .875rem; font-weight: 500; cursor: pointer; transition: all .15s; white-space: nowrap; text-decoration: none; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary  { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover  { background: var(--accent2); border-color: var(--accent2); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-outline  { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover  { border-color: var(--accent2); color: var(--accent2); }
.btn-danger   { background: var(--danger-lt); border-color: #e8c0bc; color: var(--danger); }
.btn-danger:hover   { background: #f5d5d2; }
.btn-success  { background: var(--success-lt); border-color: #b8dfc8; color: var(--success); }
.btn-warn     { background: var(--warn); color: #fff; border-color: var(--warn); }
.btn-warn:hover     { background: #92400e; border-color: #92400e; }
.btn-ghost    { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover    { background: var(--tag-bg); }
.btn-excel    { background: #1d6f42; color: #fff; border-color: #1d6f42; }
.btn-excel:hover    { background: #165a35; }
.btn-pdf      { background: #c0392b; color: #fff; border-color: #c0392b; }
.btn-pdf:hover      { background: #a93226; }
.btn-sm  { padding: .35rem .75rem; font-size: .8rem; }
.btn-icon { padding: .42rem; border-radius: 7px; }

/* === TABLE === */
.table-card, .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
thead th { background: #f9f8f5; padding: .7rem 1rem; text-align: left; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
thead th.num { text-align: right; }
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #fafaf7; }
tbody tr.total-row { background: var(--accent-lt); font-weight: 600; }
td { padding: .85rem 1rem; font-size: .875rem; vertical-align: middle; }
td.num { text-align: right; font-family: var(--mono); font-size: .85rem; }
td.num-bold { text-align: right; font-family: var(--mono); font-size: .9rem; font-weight: 700; }
.mono { font-family: var(--mono); font-size: .82rem; }
.actions { display: flex; gap: .4rem; }
.empty-state, .empty { text-align: center; padding: 4rem 2rem; color: var(--muted); }
.empty-state svg, .empty svg { width: 48px; height: 48px; margin: 0 auto 1rem; opacity: .3; display: block; }
.empty-row td { text-align: center; padding: 3rem; color: var(--muted); }

/* === SKELETON === */
.skel, .skeleton { background: linear-gradient(90deg,#eee 25%,#f5f5f5 50%,#eee 75%); background-size: 200%; animation: shimmer 1.3s infinite; border-radius: 5px; height: 16px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* === 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; }
.overlay.open { opacity: 1; pointer-events: all; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 680px; box-shadow: var(--shadow-lg); transform: translateY(16px) scale(.98); transition: transform .2s; overflow: hidden; position: relative; }
.overlay.open .modal { transform: none; }
.modal-sm  { max-width: 400px; }
.modal-lg  { max-width: 780px; }
.modal-header { padding: 1.25rem 1.5rem 1rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 1.05rem; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--muted); padding: .3rem; border-radius: 6px; line-height: 0; transition: background .15s; }
.modal-close:hover { background: var(--tag-bg); }
.modal-body { padding: 1.3rem 1.5rem; max-height: 75vh; overflow-y: auto; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .6rem; }

/* === FORMS === */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
.form-full { grid-column: 1 / -1; }
.section-sep { grid-column: 1 / -1; border: none; border-top: 1px solid var(--border); margin: .4rem 0 .2rem; }
.section-label { grid-column: 1 / -1; font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin-top: .2rem; }
.field label { display: block; font-size: .8rem; font-weight: 500; margin-bottom: .35rem; color: var(--muted); }
.field label .req { color: var(--danger); margin-left: .15rem; }
.field input, .field select, .field textarea { width: 100%; padding: .55rem .8rem; border: 1px solid var(--border); border-radius: 8px; font-family: var(--font); font-size: .875rem; background: var(--surface); outline: none; transition: border-color .15s; }
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent2); }
.field input:disabled { background: var(--bg); color: var(--muted); cursor: not-allowed; }
.field input.err { border-color: var(--danger); }
.err-msg { font-size: .75rem; color: var(--danger); margin-top: .3rem; min-height: 1rem; }

/* === DETAIL === */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem 1.5rem; }
.detail-full { grid-column: 1 / -1; }
.detail-label { font-size: .75rem; color: var(--muted); margin-bottom: .2rem; }
.detail-val { font-size: .9rem; font-weight: 500; word-break: break-word; }
.detail-section { margin-bottom: 1.2rem; }
.detail-section-title { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin-bottom: .7rem; padding-bottom: .4rem; border-bottom: 1px solid var(--border); }
.detail-row { display: flex; justify-content: space-between; padding: .55rem 0; border-bottom: 1px solid var(--border); font-size: .875rem; }
.detail-row:last-child { border-bottom: none; }
.detail-row .detail-val { text-align: right; max-width: 60%; word-break: break-all; }

/* === CONFIRM === */
.confirm-wrap { text-align: center; padding: .5rem 0; }
.confirm-icon { width: 52px; height: 52px; border-radius: 50%; background: var(--danger-lt); display: grid; place-items: center; margin: 0 auto 1rem; }
.confirm-icon svg { color: var(--danger); }
.confirm-wrap h3 { font-size: 1rem; margin-bottom: .4rem; }
.confirm-wrap p { font-size: .875rem; color: var(--muted); }

/* === SPINNER === */
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* === TOAST === */
.toast-wrap { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 999; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: #1c1b18; color: #fff; padding: .65rem 1rem; border-radius: 9px; font-size: .875rem; display: flex; align-items: center; gap: .55rem; box-shadow: var(--shadow-lg); animation: tIn .2s ease; }
.toast.ok  { background: var(--success); }
.toast.err { background: var(--danger); }
@keyframes tIn { from { transform: translateX(16px); opacity: 0; } }
/* variante verifactu */
#toast { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: .5rem; }
.toast-item { padding: .65rem 1rem; border-radius: 8px; font-size: .875rem; font-weight: 500; box-shadow: var(--shadow); animation: slideIn .2s ease; max-width: 320px; }
.toast-ok  { background: var(--success); color: #fff; }
.toast-err { background: var(--danger); color: #fff; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* === RESPONSIVE === */
@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr !important; }
  .form-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .topbar { padding: 0 1rem; }
}
