@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=DM+Sans:wght@400;500;600;700&display=swap');

:root {
  --color-bg: #F1F5F9;
  --color-surface: #FFFFFF;
  --color-text: #0F172A;
  --color-text-muted: #475569;
  --color-border: #CBD5E1;
  --color-accent: #F97316;
  --color-accent-hover: #EA580C;
  --color-accent-contrast: #FFFFFF;
  --color-success: #16A34A;
  --color-danger: #DC2626;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-heading: 'Space Grotesk', 'DM Sans', sans-serif;
  --font-body: 'DM Sans', sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

.app {
  height: 100dvh;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------------- Tabbar ---------------- */

.tabbar {
  flex: 0 0 auto;
  height: clamp(56px, 8dvh, 72px);
  display: flex;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: clamp(0.95rem, 2vw, 1.15rem);
  color: var(--color-text-muted);
  border-bottom: 3px solid transparent;
  transition: color 200ms ease, border-color 200ms ease;
}

.tab.is-active {
  color: var(--color-text);
  border-bottom-color: var(--color-accent);
}

/* ---------------- Screens ---------------- */

.screens {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  padding: clamp(14px, 2.5dvh, 28px);
  overflow: hidden;
}

.screen.is-active {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---------------- Pantalla Registro ---------------- */

.registro-layout {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 2dvh, 22px);
}

.field-group {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: clamp(4px, 1dvh, 8px);
}

.field-label {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: clamp(0.85rem, 1.6vw, 1rem);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.autocomplete-wrap {
  position: relative;
}

.input-patente {
  width: 100%;
  height: clamp(52px, 8dvh, 68px);
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--color-text);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0 clamp(14px, 2vw, 20px);
}

.input-patente:focus {
  border-color: var(--color-accent);
}

.autocomplete-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
  max-height: 40dvh;
  overflow-y: auto;
}

.autocomplete-item {
  padding: 12px 14px;
  font-size: clamp(1rem, 2.4vw, 1.2rem);
  font-weight: 600;
  border-radius: var(--radius-sm);
  min-height: 44px;
  display: flex;
  align-items: center;
}

.autocomplete-item:hover,
.autocomplete-item.is-focused {
  background: var(--color-bg);
  color: var(--color-accent-hover);
}

.anchos-group {
  flex: 1;
  min-height: 0;
}

.anchos-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(84px, 20vw, 150px), 1fr));
  grid-auto-rows: minmax(56px, 1fr);
  gap: clamp(8px, 1.6dvh, 16px);
  overflow-y: auto;
}

.ancho-btn {
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  color: var(--color-text);
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.ancho-btn.is-selected {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-accent-contrast);
}

.ancho-btn.is-add {
  color: var(--color-accent);
  border-style: dashed;
  font-size: clamp(1.4rem, 4vw, 2rem);
}

.btn-registrar {
  flex: 0 0 auto;
  height: clamp(56px, 10dvh, 84px);
  border: none;
  border-radius: var(--radius-lg);
  background: var(--color-accent);
  color: var(--color-accent-contrast);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: clamp(1.15rem, 3.2vw, 1.6rem);
  letter-spacing: 0.03em;
  transition: background 150ms ease, transform 150ms ease, opacity 150ms ease;
}

.btn-registrar:active {
  transform: scale(0.98);
}

.btn-registrar:hover {
  background: var(--color-accent-hover);
}

.btn-registrar:disabled {
  background: var(--color-border);
  color: var(--color-text-muted);
  cursor: not-allowed;
}

/* ---------------- Pantalla Historial ---------------- */

.historial-layout {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 2dvh, 18px);
}

.historial-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.historial-title {
  font-family: var(--font-heading);
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  font-weight: 700;
  margin: 0;
}

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

.btn-secondary,
.btn-primary {
  min-height: 44px;
  padding: 0 clamp(12px, 2vw, 20px);
  border-radius: var(--radius-sm);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: clamp(0.85rem, 1.8vw, 1rem);
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.btn-secondary:hover {
  border-color: var(--color-accent);
  color: var(--color-accent-hover);
}

.btn-primary {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: var(--color-accent-contrast);
}

.btn-primary:hover {
  background: var(--color-accent-hover);
}

.tabla-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.tabla-historial {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(0.85rem, 1.8vw, 1.05rem);
}

.tabla-historial thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--color-text);
  color: #FFFFFF;
  text-align: left;
  padding: 12px 14px;
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: 0.03em;
}

.tabla-historial tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
}

.tabla-historial tbody tr:nth-child(even) {
  background: var(--color-bg);
}

.tabla-vacia {
  text-align: center;
  color: var(--color-text-muted);
  padding: 24px;
  margin: 0;
}

/* ---------------- Modal ---------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  width: min(420px, 100%);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: clamp(18px, 3dvh, 28px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.3);
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  margin: 0;
}

.modal-text {
  color: var(--color-text-muted);
  margin: 0;
  line-height: 1.6;
}

.modal-input {
  height: 52px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  font-size: 1.1rem;
  font-family: var(--font-heading);
  font-weight: 600;
}

.modal-input:focus {
  border-color: var(--color-accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ---------------- Toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: clamp(16px, 4dvh, 32px);
  transform: translateX(-50%) translateY(20px);
  background: var(--color-success);
  color: #FFFFFF;
  font-family: var(--font-heading);
  font-weight: 600;
  padding: 14px 22px;
  border-radius: var(--radius-md);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.25);
  z-index: 60;
  opacity: 0;
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.is-error {
  background: var(--color-danger);
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
