/* ========================
   Design tokens
======================== */
:root{
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --line: #e2e8f0;
  --primary: #0f1b2d;   /* azul oscuro corporativo aproximado */
  --accent: #e11d48;    /* rojo */
  --ok: #16a34a;
  --danger: #dc2626;

  --radius: 14px;
  --radius-sm: 10px;

  --shadow: 0 10px 24px rgba(2, 6, 23, .08);
  --shadow-sm: 0 6px 16px rgba(2, 6, 23, .08);

  --gap: 16px;
  --gap-lg: 22px;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* ========================
   Base / reset suave
======================== */
*,
*::before,
*::after{ box-sizing: border-box; }

html{ color-scheme: light; }
body{
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(1200px 600px at 20% 0%, rgba(225, 29, 72, .06), transparent 50%),
              radial-gradient(1200px 600px at 80% 0%, rgba(15, 27, 45, .08), transparent 55%),
              var(--bg);
  line-height: 1.5;
}

img{ max-width: 100%; height: auto; display: block; }
a{ color: #1d4ed8; text-decoration: none; }
a:hover{ text-decoration: underline; }

p{ margin: 0 0 12px; color: var(--muted); }
h1,h2,h3{ margin: 0 0 12px; line-height: 1.2; }
h2{ font-size: 1.15rem; color: var(--text); margin-top: 18px; }
h3{ font-size: 1rem; color: var(--text); margin-top: 14px; }

main, header, footer{
  width: min(1180px, calc(100% - 32px));
  margin-inline: auto;
}

/* ========================
   Header / branding
======================== */
header{
  margin-top: 18px;
  background: rgba(255,255,255,.7);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  backdrop-filter: blur(6px);
}

header h1{
  margin: 0;
}

/* Logos en línea + tamaños razonables */
header h1 a{
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
}
header h1 img{
  border-radius: 12px;
}
header h1 img[alt="Aquais"]{
  width: 92px !important;
  height: 92px !important;
  object-fit: cover;
}
header h1 img:not([alt="Aquais"]){
  width: min(420px, 70vw) !important;
  height: auto !important;
  object-fit: contain;
}

/* La zona "Ola ..." + logout (están como div inline con estilos) */
header > div{
  margin-top: 10px;
}

/* primer div que suele ser el saludo */
header > span[style*="font-size"]{
  font-size: 1.25rem !important;
  font-weight: 700 !important;
  color: var(--text);
}

/* logout a la derecha */
header > span[style*="text-align: right"] a:hover{
  border-color: #cbd5e1;
  text-decoration: none;
}
header svg{
  width: 20px !important;
  height: 20px !important;
  fill: currentColor;
  opacity: .9;
}

/* ========================
   Nav
======================== */
nav{ margin-top: 14px; }
nav ul{
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
nav a{
  display: inline-flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}
nav a:hover{
  text-decoration: none;
  border-color: #cbd5e1;
  box-shadow: 0 2px 12px rgba(2, 6, 23, .06);
}

/* ========================
   Main container
======================== */
main{
  margin-top: 16px;
  margin-bottom: 18px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ========================
   “Botones” a partir de <a role="button">
======================== */
a[role="button"]{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--primary);
  color: #fff !important;
  font-weight: 800;
  letter-spacing: .2px;
  text-decoration: none !important;
}
a[role="button"]:hover{
  filter: brightness(1.05);
  box-shadow: 0 10px 18px rgba(15, 27, 45, .18);
}

/* Respetar tus estilos inline de color/size pero que parezcan botón */
a[role="button"][style*="color: green"]{
  background: var(--ok);
}
a[role="button"][style*="color: red"]{
  background: var(--danger);
}

/* Cuando salen varios links seguidos en "Operacións" */
td a{
  margin-right: 10px;
}
td a[role="button"]{ margin-right: 8px; }

/* Link tipo acción secundaria */
main > a,
main a[href="crear.php"]{
  display: inline-flex;
  margin: 10px 0 14px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px dashed #cbd5e1;
  color: var(--primary);
  background: #f8fafc;
  font-weight: 700;
  text-decoration: none;
}
main > a:hover,
main a[href="crear.php"]:hover{
  border-style: solid;
  text-decoration: none;
}

/* ========================
   Forms
======================== */
form{
  margin: 10px 0 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcff;
}

label{
  font-weight: 700;
  color: var(--text);
}

input, select, textarea, button{
  font: inherit;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="datetime-local"],
select,
textarea{
  width: min(620px, 100%);
  padding: 10px 12px;
  margin: 8px 0 12px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
}
textarea{
  min-height: 92px;
  resize: vertical;
}

input:focus, select:focus, textarea:focus{
  outline: 3px solid rgba(225, 29, 72, .18);
  border-color: rgba(225, 29, 72, .55);
}

fieldset{
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 0 0 12px;
}
legend{
  padding: 0 8px;
  font-weight: 800;
  color: var(--primary);
}

input[type="radio"]{ 
  transform: translateY(1px);
  margin-right: 6px;
}
fieldset label{
  font-weight: 600;
  margin-right: 12px;
  color: var(--muted);
}

input[type="submit"], button{
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}
input[type="submit"]:hover, button:hover{
  filter: brightness(1.05);
  box-shadow: 0 10px 18px rgba(15, 27, 45, .18);
}

/* helper texts */
#axudaInput{
  margin-left: 8px;
  color: var(--muted);
  font-size: .92rem;
}
#alertaBtn{
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
}

/* ========================
   Tables
======================== */
table{
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

thead th{
  background: #0b1220;
  color: #fff;
  text-align: left;
  font-weight: 800;
  padding: 12px;
  border-bottom: 1px solid rgba(255,255,255,.10);
  white-space: nowrap;
}

tbody td, tbody th{
  padding: 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  color: var(--text);
  background: #fff;
}

tbody tr:nth-child(even) td,
tbody tr:nth-child(even) th{
  background: #f9fafb;
}

tbody tr:hover td,
tbody tr:hover th{
  background: #f1f5f9;
}

tbody th{
  font-weight: 700;
  color: var(--text);
}

td, th{
  font-size: .95rem;
}

/* Tablas largas: permitir scroll horizontal en pantallas pequeñas */
main{ overflow-x: auto; }

/* ========================
   Footer
======================== */
footer{
  margin: 16px auto 28px;
  padding: 14px 18px;
  background: rgba(255,255,255,.7);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(6px);
}
footer p{
  margin: 0;
  font-size: .95rem;
  color: var(--muted);
}
footer a{ font-weight: 700; }

/* ========================
   Responsive tweaks
======================== */
@media (max-width: 720px){
  header h1 a{
    flex-direction: column;
    align-items: flex-start;
  }
  nav ul{
    gap: 8px;
  }
  nav a{
    width: 100%;
    justify-content: center;
  }
  input[type="text"],
  input[type="password"],
  input[type="date"],
  input[type="datetime-local"],
  select,
  textarea{
    width: 100%;
  }
}

/* ========================
   Print: más limpio
======================== */
@media print{
  body{ background: #fff; }
  header, main, footer{
    box-shadow: none !important;
    background: #fff !important;
  }
  nav, a[role="button"], header > span[style*="text-align: right"]{ display: none !important; }
  table{ border: 1px solid #000; }
  thead th{ background: #fff; color: #000; }
}

/* ===== Login tweaks (ONLY login) ===== */
.page-login > main{
  max-width: 520px;
}

.page-login > main h2{
  text-align: center;
  margin-bottom: 14px;
}

.page-login > main form{
  margin-top: 12px;
}

.page-login > main form input[type="submit"]{
  width: 100%;
  margin-top: 8px;
}

/* Centrar visualmente en pantallas grandes (ONLY login) */
@media (min-height: 720px){
  .page-login{
    display: grid;
    grid-template-rows: auto 1fr auto;
  }
  .page-login > main{
    align-self: center;
  }
}

/* Evitar desbordamiento horizontal global (opcional, pero inofensivo aquí) */
html, body{
  overflow-x: hidden;
}

/* ===== Logout fix (sin cambiar HTML actual) =====
   HTML esperado:
   <div style="text-align: right;">
     <a href="?sair=1" role="button">Pechar sesión <svg>...</svg></a>
   </div>
*/
header > span[style*="text-align: right"]{
  width: 100%;
  text-align: right;
  padding-right: 16px;
  box-sizing: border-box;
}

header > span[style*="text-align: right"] > a{
  /* neutraliza cualquier regla externa rara */
  position: static !important;
  transform: none !important;
  float: none !important;

  display: inline-flex;
  align-items: center;
  gap: 10px;

  white-space: nowrap;
  overflow: visible;

  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text) !important;
  text-decoration: none !important;
  box-shadow: 0 2px 10px rgba(2, 6, 23, .06);
}

header > span[style*="text-align: right"] > a:hover{
  border-color: #cbd5e1;
}

header > span[style*="text-align: right"] > a svg{
  width: 18px !important;
  height: 18px !important;
  flex: 0 0 auto;
}

/* Forzar que el logout quede dentro del header (sin salirse por la derecha) */
header > span[style*="text-align: right"]{
  display: flex;
  justify-content: flex-end;
}

header > span[style*="text-align: right"] > a{
  max-width: 100%;
}
