:root{
  --bg: #fbf7f7;
  --card: #ffffff;
  --text: #1b1b1f;
  --muted: #6b6b76;
  --red: #b10f2e;
  --red-2: #d61f45;
  --border: rgba(0,0,0,.08);
  --shadow: 0 10px 30px rgba(0,0,0,.08);
  --radius: 18px;
  --maxw: 1100px;
  --gap: 18px;
}

*{ box-sizing: border-box; }

html, body{ height: 100%; }

body{
  margin:0;
  min-height: 100vh;
  display:flex;
  flex-direction:column;

  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background: radial-gradient(900px 400px at 20% 0%, rgba(214,31,69,.10), transparent 60%),
              radial-gradient(900px 400px at 80% 20%, rgba(177,15,46,.08), transparent 60%),
              var(--bg);
  color: var(--text);
}

/* ---------- Topbar ---------- */
.topbar{
  position: sticky; top:0; z-index:10;
  backdrop-filter: blur(10px);
  background: rgba(251,247,247,.72);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.brand{
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px 18px;
  display:flex;
  gap:14px;
  align-items:center;
}

.brand-mark{
  width: 44px; height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--red), var(--red-2));
  box-shadow: 0 12px 25px rgba(177,15,46,.25);
}

.brand h1{ margin:0; font-size: 18px; letter-spacing: .2px;}
.brand p{ margin:2px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- Main layout (estable) ---------- */
.container{
  max-width: var(--maxw);
  width: min(var(--maxw), calc(100% - 36px));
  margin: 0 auto;
  padding: 18px 0 18px;

  flex: 1 1 auto;
  min-height: 0;

  display:grid;
  grid-template-columns: 1fr 420px; /* reserva fixa pel panell */
  gap: var(--gap);
  align-items:start;
}

/* ---------- Categories grid ---------- */
.grid{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
  align-content:start;
}

/* Botó categoria (card) */
.card-btn{
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #fff, #fff6f6);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);

  cursor: pointer;
  text-align: left;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
  position: relative;
  overflow: hidden;

  height: 165px;                 /* alçada fixa */
  display:flex;
  flex-direction: column;
  justify-content: space-between; /* no varia per contingut */
}

.card-btn:hover{
  transform: translateY(-2px);
  border-color: rgba(177,15,46,.28);
  box-shadow: 0 14px 34px rgba(0,0,0,.10);
}

/* Badge: “pastilla” petita només per al número */
.card-btn .badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;

  width: fit-content;
  max-width: fit-content;

  padding: 6px 10px;
  border-radius: 999px;

  background: linear-gradient(135deg, var(--red), var(--red-2));
  color: rgba(255,255,255,.95);

  font-size:12px;
  font-weight:700;
  white-space: nowrap;

  /* Important: evita qualsevol estirament */
  align-self: flex-start;
}

.card-btn h3{
  margin: 12px 0 6px;
  font-size: 18px;
  line-height: 1.15;

  /* màxim 2 línies */
  max-height: calc(1.15em * 2);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card-btn p{
  margin:0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;

  /* màxim 2 línies */
  max-height: calc(1.35em * 2);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ---------- Panel subopcions ---------- */
.panel{
  border: 1px solid var(--border);
  background: rgba(255,255,255,.75);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;

  min-height: 0;
  max-height: calc(100vh - 120px); /* scroll intern, “one page” */
  display:flex;
  flex-direction:column;
}

.panel-head{
  display:flex;
  align-items:center;
  justify-content: space-between;
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.8);
  flex: 0 0 auto;
}

.panel-head h2{
  margin:0;
  font-size: 15px;
}

.suboptions{
  padding: 10px;
  display:flex;
  flex-direction: column;
  gap: 10px;

  flex: 1 1 auto;
  overflow:auto;
  scrollbar-gutter: stable both-edges;
}

.sub-btn{
  width:100%;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 14px;
  padding: 12px 12px;
  cursor:pointer;
  text-align:left;
  transition: border-color .12s ease, transform .12s ease;
}
.sub-btn:hover{
  border-color: rgba(177,15,46,.25);
  transform: translateY(-1px);
}
.sub-btn .title{ font-weight: 650; }
.sub-btn .meta{ color: var(--muted); font-size: 12px; margin-top: 3px;}

/* ---------- Buttons ---------- */
.btn{
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}
.btn.primary{
  border-color: rgba(177,15,46,.30);
  background: linear-gradient(135deg, var(--red), var(--red-2));
  color: #fff;
  font-weight: 650;
}
.btn.ghost{ background: transparent; }

.muted{ color: var(--muted); }
.small{ font-size: 12px; }

/* ---------- Modal ---------- */
.modal::backdrop{ background: rgba(0,0,0,.42); }

.modal{
  border: none;
  padding: 0;
  width: min(860px, calc(100vw - 20px));
  border-radius: 22px;
  box-shadow: 0 28px 80px rgba(0,0,0,.22);
}

.modal-card{
  padding: 16px;
  background: #fff;
}

.modal-head{
  display:flex;
  justify-content: space-between;
  gap: 12px;
  align-items:flex-start;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3{ margin:0; font-size: 16px; }
.modal-head p{ margin: 4px 0 0; }

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

label{ display:flex; flex-direction: column; gap: 6px; font-size: 13px; }

input, textarea, select{
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 10px;
  font-size: 14px;
  outline: none;
}

input:focus, textarea:focus, select:focus{
  border-color: rgba(177,15,46,.35);
  box-shadow: 0 0 0 4px rgba(214,31,69,.10);
}

.full{ grid-column: 1 / -1; }
.checkbox{ flex-direction: row; align-items:center; gap:10px; padding-top: 4px; }

.signature{
  border: 1px dashed rgba(177,15,46,.30);
  border-radius: 16px;
  padding: 12px;
  background: linear-gradient(180deg, rgba(214,31,69,.06), transparent);
}

.sig-head{
  display:flex; justify-content: space-between; align-items:flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

#signaturePad{
  width: 100%;
  height: 180px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--border);
  touch-action: none;
}

.modal-foot{
  display:flex;
  justify-content: space-between;
  align-items:center;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.actions{ display:flex; gap:10px; }

/* ---------- Responsive ---------- */
@media (max-width: 980px){
  .container{
    grid-template-columns: 1fr;
    padding: 16px 0 18px;
  }
  .panel{
    max-height: none; /* en mòbil, scroll normal */
  }
}

@media (max-width: 620px){
  .grid{ grid-template-columns: 1fr; }
  .form-grid{ grid-template-columns: 1fr; }
}
