/* Shared look: page, header, type, buttons, forms, notices, tables. Tokens live in tokens.css. */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: var(--text-md);
  line-height: 1.55;
}

/* Header: logo, the role's sections, user and logout. */
.site-header { background: var(--paper); border-bottom: 1px solid var(--line); }
.site-header-inner {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2) var(--space-8);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: var(--space-3); color: var(--ink); text-decoration: none; }
.brand img { display: block; height: 2.25rem; width: auto; }
.brand-product { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 500; color: var(--muted); }
.site-nav { display: flex; gap: var(--space-1) var(--space-6); flex-wrap: wrap; flex: 1; }
.site-nav a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: var(--text-sm);
  padding: var(--space-2) 0;
  border-bottom: 3px solid transparent;
}
.site-nav a:hover { border-bottom-color: var(--line-strong); }
.site-nav a[aria-current="page"] { border-bottom-color: var(--lemon-green); }
/* Pending items next to a section name (follow-ups to review). */
.nav-count { display: inline-block; min-width: 1.5em; margin-left: var(--space-1); padding: 0 .4em; border-radius: 1em; background: var(--lemon-green); color: var(--ink); font-size: var(--text-xs); text-align: center; }
/* The settings pages (step 23): a row of links under the h1, the current one underlined like the header. */
.subnav { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-6); margin: calc(-1 * var(--space-2)) 0 var(--space-6); border-bottom: 1px solid var(--line); }
.subnav a { padding: var(--space-2) 0; border-bottom: 3px solid transparent; margin-bottom: -1px; color: var(--ink); text-decoration: none; font-weight: 600; font-size: var(--text-sm); }
.subnav a:hover { border-bottom-color: var(--line-strong); }
.subnav a[aria-current="page"] { border-bottom-color: var(--lemon-green); }
.site-user { display: flex; align-items: center; gap: var(--space-3); margin: 0 0 0 auto; font-size: var(--text-sm); color: var(--muted); }

main {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4) var(--space-8);
}

/* Type. */
h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; margin: 0 0 var(--space-3); }
h1 { font-size: var(--text-2xl); font-weight: 600; }
h2 { font-size: var(--text-xl); font-weight: 500; margin-top: var(--space-8); }
h3 { font-size: var(--text-lg); font-weight: 500; }
p { margin: 0 0 var(--space-4); max-width: 75ch; }
small, .small { font-size: var(--text-sm); }
.lede { color: var(--muted); }
a { color: var(--leaf); text-underline-offset: .15em; }
a:hover { color: var(--ink); }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2) var(--space-6); flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: var(--space-3); font-size: var(--text-sm); }

/* Focus is always visible. */
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }

/* Buttons: secondary by default, .primary for the one main action of a view, .quiet for minor ones. */
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 2.5rem;
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font: 600 var(--text-sm)/1.2 var(--font-text);
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration-fast), border-color var(--duration-fast);
}
button:hover, .button:hover { border-color: var(--ink); color: var(--ink); }
button.primary, .button.primary { background: var(--lemon-green); border-color: var(--lemon-green); }
button.primary:hover, .button.primary:hover { background: #8bd012; border-color: var(--leaf); }
button.quiet, .button.quiet { border-color: transparent; background: transparent; }
button.quiet:hover, .button.quiet:hover { background: var(--info-bg); }
button.current { background: var(--ink); border-color: var(--ink); color: var(--paper); }
button:disabled { cursor: progress; opacity: .75; }
/* Set by busy.js while a slow form is being sent. */
button.is-busy::before {
  content: "";
  width: .9em;
  height: .9em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.actions { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-6); }
form.inline { display: inline-flex; gap: var(--space-2); margin: 0; }

/* Forms. */
.fieldsets { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); align-items: start; gap: var(--space-4); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-4); margin: 0; background: var(--paper); }
/* A fieldset of short label/value pairs, one per row (e.g. one per weekday). */
fieldset.rows { display: grid; grid-template-columns: 7rem minmax(0, 18rem); align-items: center; align-content: start; gap: var(--space-2) var(--space-4); }
fieldset.rows label { margin: 0; }
fieldset.rows .errorlist, fieldset.rows .helptext { grid-column: 1 / -1; margin: 0; }
fieldset > label:first-of-type { margin-top: var(--space-2); }
legend { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 500; padding: 0 var(--space-2); }
label { display: block; margin: var(--space-4) 0 var(--space-1); font-size: var(--text-sm); font-weight: 600; }
input[type=text], input[type=search], input[type=password], input[type=email], input[type=tel], input[type=number], input[type=datetime-local], select, textarea {
  width: 100%;
  max-width: 28rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--leaf); border-radius: var(--radius); }
input[type=checkbox], input[type=radio] { width: 1.1rem; height: 1.1rem; accent-color: var(--leaf); }
textarea { resize: vertical; }
.helptext { display: block; margin-top: var(--space-1); font-size: var(--text-xs); color: var(--muted); }
.required { color: var(--muted); font-weight: 400; }
.errors, .errorlist { color: var(--danger); }
.errorlist { list-style: none; padding: 0; margin: var(--space-1) 0; font-size: var(--text-sm); }
p.errors, div.errors { font-size: var(--text-sm); }
.alert {
  padding: var(--space-3) var(--space-4);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  color: var(--ink);
}

/* Notices (django.contrib.messages). They slide in once; they stay until the next page. */
.messages { list-style: none; padding: 0; margin: 0 0 var(--space-6); display: grid; gap: var(--space-2); }
.messages li {
  padding: var(--space-3) var(--space-4);
  border-left: 4px solid var(--muted);
  border-radius: var(--radius-sm);
  background: var(--info-bg);
  animation: notice-in var(--duration) var(--ease-out) both;
}
.messages li.success { border-left-color: var(--lemon-green); background: var(--success-bg); }
.messages li.error { border-left-color: var(--danger); background: var(--danger-bg); }
.messages li.warning { border-left-color: var(--warning); background: var(--warning-bg); }
@keyframes notice-in { from { opacity: 0; transform: translateY(-.5rem); } }

/* State strip (step 20): what is wrong right now, under the header of every admin page. It is
   persistent state, not the result of an action: no animation. "stopped" halts the agenda; "review"
   is something to look at, with a "Visto" button. */
.notices { background: var(--paper); border-bottom: 1px solid var(--line); }
.notices ul {
  list-style: none;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: grid;
  gap: var(--space-2);
}
.notices li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-4);
  padding: var(--space-2) var(--space-4);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  font-size: var(--text-sm);
}
.notices li.review { border-left-color: var(--warning); background: var(--warning-bg); }
.notices li > span { flex: 1 1 20rem; }
.notices form { margin: 0; }
.notices button { min-height: 2rem; }

/* Sync status (Panel and Hoy): one line per calendar, with its colour. */
.sync-status { list-style: none; padding: 0; margin: 0; font-size: var(--text-sm); color: var(--muted); display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-6); }
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; background: var(--cal, #888); margin-right: var(--space-2); }

/* Tables. */
.table-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: var(--text-xs); font-weight: 600; color: var(--muted); background: var(--canvas); }
tbody tr:last-child td { border-bottom: 0; }
tr.muted { color: var(--muted); }
td small { color: var(--muted); white-space: nowrap; }
/* "Mis reservas" (step 24): the past month's meetings under the upcoming ones. */
#reservas h3 { margin-top: var(--space-6); }
.badge { display: inline-block; padding: 0 var(--space-2); border-radius: var(--radius-sm); background: var(--info-bg); color: var(--muted); font-size: var(--text-xs); font-weight: 600; }

/* Login: the only centred page. */
.login { max-width: 24rem; margin: 8vh auto 0; padding: var(--space-8); background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.login input { max-width: none; }
.login button { width: 100%; margin-top: var(--space-6); }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Changing week cross-fades instead of flashing (browsers without support just navigate). */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: var(--duration); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media (max-width: 40rem) {
  .site-header-inner { gap: var(--space-2) var(--space-4); }
  .brand img { height: 1.9rem; }
  .brand-product { display: none; }
  .site-nav { order: 3; flex-basis: 100%; }
  main { padding-top: var(--space-4); }
  h1 { font-size: var(--text-xl); }
}
