/* ============================================================
   CertiDoc — kit visual compartit dels portals de llicències
   (botiga, portal de partners i panell comercial).
   Replica el llenguatge visual de l'app: slate-50 de fons,
   targetes blanques rounded-2xl amb vora slate-200 i accent indi.
   ============================================================ */

:root {
  --ind-50:  #eef2ff;
  --ind-100: #e0e7ff;
  --ind-200: #c7d2fe;
  --ind-500: #6366f1;
  --ind:     #4f46e5;
  --ind-700: #4338ca;
  --ind-900: #312e81;
  --slate:   #0f172a;
  --slate-600: #475569;
  --mut:     #64748b;
  --line:    #e2e8f0;
  --bg:      #f8fafc;
  --card:    #ffffff;
  --ok:      #059669;
  --ok-bg:   #ecfdf5;
  --warn:    #b45309;
  --warn-bg: #fef3c7;
  --err:     #dc2626;
  --err-bg:  #fef2f2;
}

* { box-sizing: border-box; margin: 0; }

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--slate);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ── Capçalera ─────────────────────────────────────────────── */
.cd-header {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: .7rem 1.4rem;
  display: flex;
  align-items: center;
  gap: 1.1rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 40;
}
.cd-header .cd-brand { display: flex; align-items: center; gap: .7rem; text-decoration: none; }
.cd-header .cd-brand img { height: 34px; display: block; }
.cd-header .cd-app {
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ind); background: var(--ind-50); border: 1px solid var(--ind-100);
  padding: .2rem .55rem; border-radius: 999px; white-space: nowrap;
}
.cd-nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.cd-nav button {
  border: 0; background: transparent; padding: .45rem .85rem; border-radius: .6rem;
  cursor: pointer; font-weight: 600; font-size: .875rem; color: var(--mut);
  font-family: inherit; transition: background .15s, color .15s;
}
.cd-nav button:hover { background: #f1f5f9; color: var(--slate); }
.cd-nav button.on { background: var(--ind-50); color: var(--ind); }
.cd-header .cd-right { margin-left: auto; display: flex; align-items: center; gap: .8rem; }
.cd-who { color: var(--mut); font-size: .82rem; text-align: right; line-height: 1.3; }
.cd-who b { color: var(--slate); display: block; }

/* ── Contingut ─────────────────────────────────────────────── */
.cd-main { flex: 1; width: 100%; max-width: 1180px; margin: 1.5rem auto; padding: 0 1rem; }
.cd-main.narrow { max-width: 760px; }

.cd-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 1rem;
  padding: 1.4rem; margin-bottom: 1.2rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.cd-card h2 { font-size: 1.05rem; margin-bottom: .9rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.cd-card h3 { font-size: .95rem; margin-bottom: .6rem; }
.cd-sub { color: var(--mut); font-size: .875rem; margin-top: -.5rem; margin-bottom: 1rem; }

/* ── Pantalla d'accés (mateix patró que l'app) ─────────────── */
.cd-auth { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 3rem 1rem; }
.cd-auth-inner { width: 100%; max-width: 27rem; margin: 0 auto; }
.cd-auth-logo { display: flex; justify-content: center; margin-bottom: 1.6rem; }
.cd-auth-logo img { height: 72px; object-fit: contain; }
.cd-auth-title { text-align: center; font-size: 1.3rem; font-weight: 700; margin-bottom: .3rem; }
.cd-auth-desc { text-align: center; color: var(--mut); font-size: .875rem; margin-bottom: 1.5rem; }
.cd-auth-card {
  background: #fff; border: 1px solid var(--line); border-radius: 1rem;
  padding: 2rem 1.75rem; box-shadow: 0 1px 3px rgba(15, 23, 42, .07);
}
.cd-auth-icon {
  width: 3.5rem; height: 3.5rem; border-radius: 999px; background: var(--ind-100); color: var(--ind);
  display: flex; align-items: center; justify-content: center; margin: 0 auto .8rem; font-size: 1.5rem;
}

/* ── Formularis ────────────────────────────────────────────── */
label.cd-f { display: block; font-size: .82rem; font-weight: 600; margin: .8rem 0 .3rem; color: var(--slate-600); }
input:not([type]), input[type=text], input[type=email], input[type=tel], input[type=password],
input[type=number], input[type=date], select, textarea {
  width: 100%; padding: .6rem .8rem; border: 1px solid #cbd5e1; border-radius: .7rem;
  font-size: .9rem; font-family: inherit; color: var(--slate); background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--ind); box-shadow: 0 0 0 3px var(--ind-100);
}
input:disabled, select:disabled { background: #f8fafc; color: var(--mut); }
select.cd-mini { width: auto; padding: .3rem .5rem; font-size: .78rem; border-radius: .5rem; }
.cd-code {
  text-align: center; font-size: 1.7rem; letter-spacing: .45em; font-family: Consolas, monospace;
  padding: .8rem .5rem;
}
.cd-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.cd-grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .9rem; }
.cd-grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: .9rem; }
@media (max-width: 760px) { .cd-grid2, .cd-grid3, .cd-grid4 { grid-template-columns: 1fr; } }

.cd-btn {
  border: 0; border-radius: .7rem; padding: .65rem 1.3rem; font-size: .9rem; font-weight: 600;
  cursor: pointer; font-family: inherit; background: var(--ind); color: #fff;
  transition: background .15s, opacity .15s; display: inline-flex; align-items: center; gap: .45rem;
}
.cd-btn:hover:not(:disabled) { background: var(--ind-700); }
.cd-btn:disabled { opacity: .55; cursor: default; }
.cd-btn.block { width: 100%; justify-content: center; }
.cd-btn.ghost { background: #f1f5f9; color: var(--slate); }
.cd-btn.ghost:hover:not(:disabled) { background: #e2e8f0; }
.cd-btn.danger { background: var(--err); }
.cd-btn.danger:hover:not(:disabled) { background: #b91c1c; }
.cd-btn.sm { padding: .32rem .7rem; font-size: .78rem; border-radius: .5rem; background: var(--ind-50); color: var(--ind); }
.cd-btn.sm:hover:not(:disabled) { background: var(--ind-100); }
.cd-btn.sm.danger { background: var(--err-bg); color: var(--err); }
.cd-btn.sm.danger:hover:not(:disabled) { background: #fee2e2; }

/* ── Missatges ─────────────────────────────────────────────── */
.cd-msg { padding: .8rem 1rem; border-radius: .7rem; margin: .9rem 0; font-size: .875rem; display: none; }
.cd-msg.err { background: var(--err-bg); color: var(--err); border: 1px solid #fecaca; display: block; }
.cd-msg.ok  { background: var(--ok-bg);  color: var(--ok);  border: 1px solid #a7f3d0; display: block; }
.cd-msg.info{ background: var(--ind-50); color: var(--ind-700); border: 1px solid var(--ind-100); display: block; }

/* ── Taules ────────────────────────────────────────────────── */
.cd-table-wrap { overflow-x: auto; }
table.cd-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.cd-table th {
  text-align: left; color: var(--mut); font-size: .7rem; text-transform: uppercase;
  letter-spacing: .04em; padding: .5rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.cd-table td { padding: .55rem .6rem; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
table.cd-table tr:hover td { background: #f8fafc; }
.cd-mut { color: var(--mut); font-size: .82rem; }

/* ── KPIs ──────────────────────────────────────────────────── */
.cd-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: .9rem; margin-bottom: 1.2rem; }
.cd-kpi { background: #fff; border: 1px solid var(--line); border-radius: .9rem; padding: 1rem; }
.cd-kpi .l { font-size: .74rem; color: var(--mut); }
.cd-kpi .v { font-size: 1.45rem; font-weight: 700; margin-top: .25rem; }

/* ── Badges ────────────────────────────────────────────────── */
.cd-badge { font-size: .7rem; padding: .16rem .55rem; border-radius: 999px; font-weight: 600; white-space: nowrap; display: inline-block; }
.b-ok   { background: #d1fae5; color: #047857; }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-err  { background: #fee2e2; color: #b91c1c; }
.b-mut  { background: #f1f5f9; color: var(--mut); }
.b-ind  { background: var(--ind-50); color: var(--ind); }

/* ── Gràfic de barres ──────────────────────────────────────── */
.cd-bars { display: flex; align-items: flex-end; gap: 4px; height: 132px; margin-top: .9rem; }
.cd-bars .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: .25rem; font-size: .62rem; color: var(--mut); }
.cd-bars .b .cols { display: flex; gap: 2px; width: 100%; height: 100px; align-items: flex-end; }
.cd-bars .b i { display: block; flex: 1; background: var(--ind); border-radius: 3px 3px 0 0; min-height: 2px; }
.cd-bars .b i.prev { background: var(--ind-200); }

/* ── Peu ───────────────────────────────────────────────────── */
.cd-footer {
  border-top: 1px solid var(--line); background: #fff; padding: 1.1rem 1.4rem;
  color: var(--mut); font-size: .78rem; margin-top: auto;
}
.cd-footer .cd-footer-in {
  max-width: 1180px; margin: 0 auto; display: flex; gap: .6rem 1.4rem;
  align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.cd-footer a { color: var(--mut); text-decoration: none; }
.cd-footer a:hover { color: var(--ind); text-decoration: underline; }
.cd-footer .cd-links { display: flex; gap: 1rem; flex-wrap: wrap; }

/* ── Diàlegs ───────────────────────────────────────────────── */
dialog.cd-modal {
  border: 0; border-radius: 1rem; padding: 0; max-width: 680px; width: 94%;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .25); color: var(--slate);
  /* Centrat real a la finestra (no depenem del marge per defecte del navegador) */
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  margin: 0; max-height: 90vh;
}
dialog.cd-modal::backdrop { background: rgba(15, 23, 42, .45); }
dialog.cd-modal .bd { padding: 1.4rem; max-height: 74vh; overflow-y: auto; }
dialog.cd-modal .ft {
  padding: 1rem 1.4rem; border-top: 1px solid var(--line);
  display: flex; justify-content: flex-end; gap: .6rem;
}

.cd-hide { display: none !important; }
.cd-checks label { display: flex; gap: .5rem; align-items: center; font-size: .88rem; padding: .28rem 0; cursor: pointer; }
.cd-right-align { text-align: right; }
