/*
 * Base components for the Benchmark marca Yes app. Mobile-first (designed at 360px).
 *
 * Rules for this file and every page of the project:
 *  - Colors only through CSS variables. Hex/rgb values live ONLY in the :root token
 *    blocks below and in brand.css; a component rule never contains a color literal.
 *  - Helvetica/Arial only. Never load another font.
 *  - The CSP forbids inline <style>, style="" and inline <script>: add rules here (or in
 *    a new file under public/css) and code under public/js.
 */

/* ---------------------------------------------------------------- tokens */
:root {
  color-scheme: light dark;

  --font: Helvetica, Arial, "Helvetica Neue", sans-serif;

  /* Surfaces and text (light) */
  --bg: #F3F5F7;
  --surface: #FFFFFF;
  --header-bg: #FFFFFF;
  --logo-plate: transparent;
  --border: #CBD2D9;
  --field-border: #6B7280;
  --input-bg: #FFFFFF;
  --text: #1B1F24;
  --muted: #4B5563;
  --on-brand: #FFFFFF;
  --focus: #0B5FA5;
  --shadow: 0 1px 3px rgba(7, 59, 102, 0.12);

  /* Status colors: text/solid, soft background, border */
  --danger: #B42318;
  --danger-solid: #B42318;
  --danger-solid-hover: #8E1B12;
  --danger-bg: #FDECEA;
  --danger-border: #E8A39D;
  --success: #0F6B3B;
  --success-bg: #E7F5EC;
  --success-border: #8FCBA6;
  --warning: #7A4B00;
  --warning-bg: #FFF4DB;
  --warning-border: #E4C46B;
  --info: #073B66;
  --info-bg: #E4EFF8;
  --info-border: #9DBFDD;
  --neutral-bg: #E4E7EB;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141517;
    --surface: #1C1D20;
    --header-bg: #1C1D20;
    --logo-plate: #FFFFFF;
    --border: #3A3B40;
    --field-border: #8B8D93;
    --input-bg: #141517;
    --text: #E8E9EB;
    --muted: #A8A9AA;
    --focus: #8FBCE6;
    --shadow: none;

    --danger: #FF9C92;
    --danger-bg: #3A1C1A;
    --danger-border: #7A3A35;
    --success: #86E0AB;
    --success-bg: #12301F;
    --success-border: #2F6A48;
    --warning: #F5D27A;
    --warning-bg: #3A2E0F;
    --warning-border: #7A6120;
    --info: #CFE3F5;
    --info-bg: #0E2E4B;
    --info-border: #2F5F8A;
    --neutral-bg: #2B2C30;
  }
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

h1,
h2,
h3 {
  color: var(--brand-ink);
  line-height: 1.25;
}

a {
  color: var(--brand-ink);
}

img {
  max-width: 100%;
}

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

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

.skip-link {
  position: absolute;
  left: 8px;
  top: -64px;
  z-index: 10;
  padding: 12px 16px;
  background: var(--brand-dark);
  color: var(--on-brand);
  border-radius: 8px;
}

.skip-link:focus {
  top: 8px;
}

.text-muted {
  color: var(--muted);
}

/* ---------------------------------------------------------------- layout */
.container {
  width: 100%;
  max-width: 72rem;
  margin-inline: auto;
  padding-inline: 16px;
}

.page {
  padding-block: 20px 48px;
}

.page-title {
  margin: 0 0 4px;
  font-size: 1.5rem;
}

.page-lead {
  margin: 0 0 20px;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.stack > * + * {
  margin-top: 16px;
}

/* ---------------------------------------------------------- header / nav */
.app-header {
  background: var(--header-bg);
  border-bottom: 3px solid var(--brand-accent);
}

.app-header__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-block: 10px;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 4px 6px;
  border-radius: 8px;
  background: var(--logo-plate);
}

.brand-logo {
  display: block;
  height: 36px;
  width: auto;
}

.user-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 0;
}

.user-name {
  max-width: 7.5rem;
  overflow: hidden;
  font-size: 0.8125rem;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-nav {
  border-top: 1px solid var(--border);
}

.nav-list {
  display: flex;
  gap: 4px;
  margin: 0;
  padding: 0;
  overflow-x: auto;
  list-style: none;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border-bottom: 3px solid transparent;
  color: var(--brand-ink);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.nav-link:hover {
  border-bottom-color: var(--border);
}

.nav-link[aria-current="page"] {
  border-bottom-color: var(--brand-ink);
}

/* ------------------------------------------------- connection status chip */
.app-status {
  background: var(--header-bg);
  border-top: 1px solid var(--border);
}

.app-status__bar {
  display: flex;
  align-items: center;
  min-height: 34px;
  padding-block: 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 12px;
  border-radius: 999px;
  background: var(--success-bg);
  color: var(--success);
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.5;
}

/* A dot (shape) next to the text: state is never conveyed by color alone. */
.chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.chip[data-estado="sin-conexion"],
.chip[data-estado="pendientes"] {
  background: var(--warning-bg);
  color: var(--warning);
}

.chip[data-estado="sincronizando"] {
  background: var(--info-bg);
  color: var(--info);
}

.chip[data-estado="sesion"] {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ----------------------------------------------------------------- cards */
.card {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0 0 12px;
  font-size: 1.125rem;
}

.tile-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tile {
  display: block;
  min-height: 88px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 6px solid var(--brand-accent);
  border-radius: 12px;
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
}

.tile:hover {
  border-color: var(--brand-ink);
}

.tile__title {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--brand-ink);
}

.tile__text {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 2px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
  background: var(--brand-button);
  color: var(--on-brand);
}

.btn-primary:hover {
  background: var(--brand-dark);
}

.btn-secondary {
  background: transparent;
  border-color: var(--brand-ink);
  color: var(--brand-ink);
}

.btn-secondary:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
  color: var(--on-brand);
}

.btn-danger {
  background: var(--danger-solid);
  color: var(--on-brand);
}

.btn-danger:hover {
  background: var(--danger-solid-hover);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-lg {
  min-height: 56px;
  font-size: 1.125rem;
}

.btn-sm {
  padding: 0 12px;
  font-size: 0.875rem;
}

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.inline-form {
  display: inline;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
}

/* ----------------------------------------------------------------- forms */
.field {
  margin-bottom: 16px;
}

.label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
}

.hint {
  margin: 4px 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.input,
.select,
.textarea {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  background: var(--input-bg);
  border: 2px solid var(--field-border);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
}

.textarea {
  min-height: 96px;
}

.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

.field-error {
  margin: 6px 0 0;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--danger);
}

.check {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.check input {
  flex: none;
  width: 24px;
  height: 24px;
  accent-color: var(--brand-accent);
}

/* ---------------------------------------------------------------- alerts */
.alert {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid;
  border-radius: 10px;
}

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

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

.alert-warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning);
}

.alert-info {
  background: var(--info-bg);
  border-color: var(--info-border);
  color: var(--info);
}

/* ---------------------------------------------------------------- tables */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.table {
  width: 100%;
  min-width: 36rem;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

.table th {
  background: var(--brand-dark);
  color: var(--on-brand);
  font-size: 0.875rem;
  white-space: nowrap;
}

.table td {
  border-top: 1px solid var(--border);
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--neutral-bg);
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-brand {
  background: var(--info-bg);
  color: var(--info);
}

.badge-success {
  background: var(--success-bg);
  color: var(--success);
}

.badge-danger {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ------------------------------------------------------- details / reset */
.reset-details > summary {
  list-style: none;
}

.reset-details > summary::-webkit-details-marker {
  display: none;
}

.reset-form {
  display: grid;
  gap: 8px;
  min-width: 14rem;
  margin-top: 8px;
}

/* ----------------------------------------------------------------- guest */
.guest-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

.guest-card {
  width: 100%;
  max-width: 26rem;
  padding: 24px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--brand-accent);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.guest-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.guest-title {
  margin: 0 0 16px;
  font-size: 1.25rem;
  text-align: center;
}

/* ----------------------------------------------------------- error pages */
.error-page {
  text-align: center;
}

.error-code {
  margin: 0 0 4px;
  color: var(--brand-accent);
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
}

.error-text {
  margin: 0 0 20px;
  color: var(--muted);
}

/* ----------------------------------------------------------- breakpoints */
@media (min-width: 40rem) {
  .brand-logo {
    height: 40px;
  }

  .user-box {
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }

  .user-name {
    max-width: 16rem;
    font-size: 0.875rem;
  }

  .tile-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .page-title {
    font-size: 1.75rem;
  }

  .guest-card {
    padding: 32px;
  }
}

@media (min-width: 64rem) {
  .tile-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

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