/* DivInCon — shared reset, layout tokens and cross-template components.
   Fluid/responsive, no framework/build step. Fragment-specific rules live in
   their own static/css/<template>.css file — see CLAUDE.md.

   COLOURS ARE NOT DEFINED HERE: every var(--color-…) (plus --font-family and
   --radius) comes from config/theme.py, injected as an inline <style> in
   <head> by {% theme_style %}. Never hard-code a brand colour in CSS. */

:root {
  --space-1: clamp(0.5rem, 0.45rem + 0.25vw, 0.75rem);
  --space-2: clamp(0.75rem, 0.6rem + 0.6vw, 1.25rem);
  --space-3: clamp(1.25rem, 1rem + 1vw, 2rem);
  --space-4: clamp(2rem, 1.5rem + 2vw, 3.5rem);
  --page-width: 72rem;
  --shadow-card: 0 0.2rem 0 rgb(0 0 0 / 0.12);
  --tap-size: 2.75rem; /* 44px minimum touch target */
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-family);
  font-size: 1rem; /* respects the visitor's browser font size */
  line-height: 1.6;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

h1,
h2,
h3 {
  line-height: 1.25;
}

a {
  color: var(--color-main);
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--color-main-hover);
}

img {
  max-width: 100%;
  height: auto;
}

code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--color-main);
  outline-offset: 2px;
}

/* Programmatic focus targets (section <h1>s and <main> get focus after an
   HTMX navigation so screen readers announce the new content): not
   interactive, so no focus ring. Scoped to h1/main so inactive tabs or
   focused alerts keep theirs. */
h1[tabindex="-1"]:focus,
main[tabindex="-1"]:focus {
  outline: none;
}

/* Keep the bottom toast from covering whatever is being tabbed to. */
html:has(#app-toast:not([hidden])) {
  scroll-padding-bottom: 8rem;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-2);
  top: -10rem;
  z-index: 1000;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  background: var(--color-main);
  color: var(--color-on-main);
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus,
.skip-link:hover {
  top: var(--space-2);
  color: var(--color-on-main);
}

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  vertical-align: middle;
}

.icon--inline {
  width: 1em;
  height: 1em;
  margin-inline: 0.25em;
  vertical-align: -0.125em;
}

/* --- Page layout + section header ------------------------------------------ */
/* #app-viewport is full width (so the home hero and the backoffice sidebar can
   go edge to edge, like divintech.es); regular sections wrap in .page. */
.page {
  width: min(100%, var(--page-width));
  margin-inline: auto;
  padding: var(--space-3) var(--space-3) var(--space-4);
}

/* Shared by every fragment's <h1>. The teal bar under it is divintech.es'
   .section-divider in the new brand colour. */
.section-heading {
  margin: 0 0 var(--space-2);
  overflow-wrap: anywhere;
  color: var(--color-main);
  font-size: clamp(1.5rem, 1.25rem + 1vw, 2rem);
  font-weight: 700;
}

.section-heading::after {
  content: "";
  display: block;
  width: 3rem;
  height: 4px;
  margin-top: 0.75rem;
  border-radius: 2px;
  background: var(--color-accent);
}

.section-intro {
  margin: 0 0 var(--space-1);
  color: var(--color-muted);
  font-size: 1.05rem;
}

/* "Application: <name>" — which Django app renders the section. */
.app-badge {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.4em;
  align-items: center;
  margin: 0 0 var(--space-3);
  padding: 0.3rem 0.85rem;
  border-radius: 999px;
  background: var(--color-accent-soft);
  color: var(--color-text);
  font-size: 0.875rem;
}

.app-badge code {
  font-weight: 700;
  color: var(--color-accent-text);
}

.placeholder-card {
  padding: var(--space-3);
  border: 2px dashed var(--color-main-tint);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-muted);
}

.placeholder-card p {
  margin: 0;
}

.empty-state {
  color: var(--color-muted);
}

/* Shown when a translation is missing and the default language is displayed. */
.fallback-note {
  margin: 0.5rem 0 0;
  color: var(--color-muted);
  font-size: 0.875rem;
  font-style: italic;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 0.25rem;
  background: var(--color-main-soft);
  color: var(--color-text);
  font-size: 0.8125rem;
  font-weight: 700;
}

/* Shared by news-detail. */
.back-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-size);
  margin-bottom: var(--space-1);
  font-weight: 600;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

/* --- Buttons ---------------------------------------------------------------------- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: var(--tap-size);
  padding: 0.55rem 1.25rem;
  border: 2px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.button .icon {
  width: 1.1em;
  height: 1.1em;
}

/* Main action (submit). */
.button--primary {
  background: var(--color-main);
  color: var(--color-on-main);
}

.button--primary:hover {
  background: var(--color-main-hover);
  color: var(--color-on-main);
}

/* divintech.es' rounded gold "primary-button", in brand teal. */
.button--secondary {
  border-radius: 1rem;
  background: var(--color-accent-muted);
  color: var(--color-text);
}

.button--secondary:hover {
  background: var(--color-accent-muted-hover);
  color: var(--color-text);
}

/* divintech.es' "Cancelar": white with a blue border. */
.button--outline {
  border-color: var(--color-main);
  background: var(--color-bg);
  color: var(--color-text);
}

.button--outline:hover {
  background: var(--color-main-soft);
}

.button--danger {
  background: var(--color-danger);
  color: var(--color-on-main);
}

.button--danger:hover {
  filter: brightness(0.88);
}

.button--block {
  width: 100%;
}

/* --- Forms (login + backoffice dialogs) ---------------------------------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: var(--space-2);
}

.field label {
  font-weight: 600;
}

.required-mark {
  color: var(--color-danger);
  font-weight: 700;
}

/* divintech.es inputs: tinted background + blue bottom border. */
input:not([type="checkbox"], [type="radio"], [type="file"], [type="hidden"]),
select,
textarea {
  width: 100%;
  min-height: var(--tap-size);
  padding: 0.6rem 0.75rem;
  border: 1px solid transparent;
  border-bottom: 2px solid var(--color-main);
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--color-accent-soft);
  color: var(--color-text);
  font: inherit;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--color-main);
  outline-offset: 1px;
  background: var(--color-bg);
}

textarea {
  resize: vertical;
}

/* Browser default placeholders are ~3.5–4:1 on the tinted inputs. */
::placeholder {
  color: var(--color-muted);
  opacity: 1;
}

input[type="file"] {
  max-width: 100%;
  font: inherit;
}

input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  accent-color: var(--color-main);
}

.field--invalid input:not([type="checkbox"]),
.field--invalid textarea,
.field--invalid select {
  border-bottom-color: var(--color-danger);
  background: var(--color-danger-soft);
}

.field-help {
  color: var(--color-muted);
  font-size: 0.875rem;
}

.field-help ul {
  margin: 0.25rem 0 0;
  padding-left: 1.25rem;
}

.field-error {
  display: flex;
  align-items: flex-start;
  gap: 0.15rem;
  margin: 0;
  color: var(--color-danger);
  font-size: 0.875rem;
  font-weight: 600;
}

.field--checkbox {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.field--checkbox .field-help,
.field--checkbox .field-error {
  flex-basis: 100%;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 3.25rem;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 0.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-main);
  cursor: pointer;
  transform: translateY(-50%);
}

.password-toggle:hover {
  background: var(--color-main-soft);
}

.password-toggle__hide,
.password-toggle[aria-pressed="true"] .password-toggle__show {
  display: none;
}

.password-toggle[aria-pressed="true"] .password-toggle__hide {
  display: block;
}

/* --- Alerts ------------------------------------------------------------------------ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin: 0 0 var(--space-2);
  padding: 0.75rem 1rem;
  border-left: 4px solid currentColor;
  border-radius: var(--radius);
}

.alert__icon {
  margin-top: 0.15rem;
}

.alert--error {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}

.alert--success {
  background: var(--color-success-soft);
  color: var(--color-success);
}

.alert--info {
  background: var(--color-main-soft);
  color: var(--color-main);
}

.alert ul {
  margin: 0.25rem 0 0;
  padding-left: 1.1rem;
}

.alert a {
  color: inherit;
  font-weight: 600;
}

/* --- Dialogs (backoffice add/edit/delete/notice) -------------------------------- */
/* Native <dialog> opened with showModal(): the browser provides the focus
   trap, Escape to close and the inert backdrop. */
.dialog {
  width: min(100% - 2rem, 46rem);
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 0;
  border-radius: calc(var(--radius) * 1.5);
  background: var(--color-bg);
  color: var(--color-text);
  box-shadow: 0 1.5rem 3rem rgb(0 0 0 / 0.25);
}

.dialog[open] {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.dialog::backdrop {
  background: color-mix(in srgb, var(--color-subfooter-bg) 60%, transparent);
}

.dialog__form {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.dialog__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  color: var(--color-main);
  font-size: 1.25rem;
}

.dialog__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--tap-size);
  height: var(--tap-size);
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
}

.dialog__close:hover {
  background: var(--color-main-soft);
}

.dialog__body {
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--space-2) var(--space-3);
  overflow-y: auto;
}

.dialog__footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--color-border);
}

/* A request that fails while a dialog is open (a 500 on save, no network,
   429): reported here by shell.js, because the page toast would sit behind
   the modal dialog, covered and inert. */
.dialog__request-error {
  display: flex;
  flex-basis: 100%;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0;
  padding: 0.6rem 0.75rem;
  border-left: 4px solid currentColor;
  border-radius: var(--radius);
  background: var(--color-danger-soft);
  color: var(--color-danger);
  font-weight: 600;
}

.dialog__request-error .icon {
  margin-top: 0.15rem;
}

/* Phones: add/edit forms take the whole screen (header and the
   Cancelar / Guardar bar stay put while the fields scroll), the small
   confirmations stay cards; footer buttons share the width equally. */
@media (max-width: 39.99rem) {
  html:has(.dialog[open]) {
    overflow: hidden;
  }

  .dialog {
    width: calc(100% - 1.5rem);
  }

  .dialog--form {
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border-radius: 0;
  }

  .dialog--form .dialog__header {
    padding: max(0.5rem, env(safe-area-inset-top)) 0.5rem 0.5rem var(--space-2);
  }

  .dialog__body {
    padding: var(--space-2);
  }

  .dialog__footer {
    gap: 0.5rem;
    padding: 0.75rem var(--space-2);
  }

  .dialog--form .dialog__footer {
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }

  .dialog__footer .button {
    flex: 1 1 0;
    min-width: max-content;
  }
}

/* Short viewports / 400% zoom: a fixed header + footer would leave almost no
   room for the form, so the whole dialog scrolls instead of just the body. */
@media (max-height: 32rem) {
  .dialog[open] {
    overflow-y: auto;
  }

  .dialog__body {
    flex: none;
    overflow: visible;
  }
}
