:root {
  --brand: #d71920;
  --brand-dark: #9f1117;
  --ink: #171a1f;
  --muted: #5c6470;
  --line: #dfe3e8;
  --surface: #ffffff;
  --soft: #f5f7fa;
  --accent: #0f766e;
  --warning: #b7791f;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --ink: #f5f7fa;
  --muted: #b4bdc9;
  --line: #303741;
  --surface: #171a1f;
  --soft: #0f1217;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--soft);
  color: var(--ink);
  overflow-x: hidden;
}

a {
  color: inherit;
}

.site-header,
.app-header {
  align-items: center;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  padding: 16px clamp(18px, 4vw, 56px);
  position: sticky;
  top: 0;
  z-index: 20;
}

:root[data-theme="dark"] .site-header,
:root[data-theme="dark"] .app-header {
  background: rgba(15, 18, 23, 0.88);
}

.brand {
  align-items: center;
  display: inline-flex;
  font-weight: 800;
  gap: 10px;
  text-decoration: none;
}

.brand-mark {
  align-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  border-radius: 8px;
  color: #fff;
  display: inline-flex;
  font-size: 13px;
  height: 36px;
  justify-content: center;
  width: 36px;
}

.brand-mark,
.button,
.card,
.hero-panel {
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.brand:hover .brand-mark,
.button:hover {
  transform: translateY(-2px);
}

.button:hover {
  box-shadow: 0 14px 30px rgba(215, 25, 32, 0.26);
}

.nav {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.nav a {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.nav a.button {
  color: #fff;
}

.nav a.button.secondary {
  color: var(--ink);
}

.menu-toggle {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: none;
  flex: 0 0 42px;
  height: 42px;
  justify-content: center;
  min-height: 42px;
  padding: 0;
  position: relative;
  width: 42px;
}

.menu-toggle span {
  background: currentColor;
  border-radius: 999px;
  display: block;
  height: 2px;
  position: absolute;
  transition: transform 160ms ease, opacity 160ms ease;
  width: 18px;
}

.menu-toggle span:nth-child(1) {
  transform: translateY(-6px);
}

.menu-toggle span:nth-child(3) {
  transform: translateY(6px);
}

.nav-open .menu-toggle span:nth-child(1) {
  transform: rotate(45deg);
}

.nav-open .menu-toggle span:nth-child(2) {
  opacity: 0;
}

.nav-open .menu-toggle span:nth-child(3) {
  transform: rotate(-45deg);
}

.button,
button {
  align-items: center;
  background: var(--brand);
  border: 0;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-weight: 800;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  text-decoration: none;
}

.button.secondary {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
}

:root[data-theme="dark"] .button.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.lang-menu {
  flex: 0 0 76px;
  position: relative;
  width: 76px;
}

.lang-menu summary {
  align-items: center;
  background: rgba(23, 26, 31, 0.04);
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-flex;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  list-style: none;
  min-height: 36px;
  padding: 0 12px;
  width: 76px;
}

.lang-menu summary::-webkit-details-marker {
  display: none;
}

.lang-menu[open] summary {
  border-color: rgba(215, 25, 32, 0.38);
}

.lang-options {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 42px rgba(23, 26, 31, 0.16);
  display: grid;
  gap: 4px;
  min-width: 92px;
  opacity: 0;
  padding: 6px;
  pointer-events: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  transform: translateY(-4px);
  transition: opacity 140ms ease, transform 140ms ease;
  z-index: 60;
}

.lang-menu[open] .lang-options {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.lang-menu a {
  background: var(--surface);
  border-radius: 6px;
  color: var(--muted);
  display: block;
  font-size: 12px;
  padding: 8px 12px;
  white-space: nowrap;
}

.lang-menu a.active {
  background: rgba(215, 25, 32, 0.08);
  box-shadow: none;
  color: var(--ink);
}

.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  min-height: 36px;
  padding: 0;
  position: relative;
  width: 44px;
}

.theme-icon {
  inset: 0;
  line-height: 34px;
  position: absolute;
  text-align: center;
  transition: opacity 160ms ease, transform 160ms ease;
}

.theme-icon-dark,
:root[data-theme="dark"] .theme-icon-light {
  opacity: 0;
  transform: scale(0.7);
}

:root[data-theme="dark"] .theme-icon-dark {
  opacity: 1;
  transform: scale(1);
}

.hero {
  background:
    linear-gradient(110deg, rgba(23, 26, 31, 0.9), rgba(159, 17, 23, 0.78)),
    url("hero-pattern.svg");
  color: #fff;
  display: grid;
  gap: 28px;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  isolation: isolate;
  min-height: 620px;
  padding: clamp(52px, 8vw, 92px) clamp(18px, 4vw, 56px);
  position: relative;
  overflow: hidden;
  --mx: 0;
  --my: 0;
}

.hero::before {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.09) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.08) 1px, transparent 1px);
  background-size: 72px 72px;
  content: "";
  inset: -80px;
  opacity: 0.34;
  position: absolute;
  transform: translate(calc(var(--mx) * -10px), calc(var(--my) * -10px));
  z-index: -2;
}

.hero::after {
  background:
    radial-gradient(circle at calc(52% + var(--mx) * 14%) calc(38% + var(--my) * 10%), rgba(255, 255, 255, 0.16), transparent 28%),
    linear-gradient(135deg, transparent 54%, rgba(255, 255, 255, 0.12) 54%, rgba(255, 255, 255, 0.12) 58%, transparent 58%);
  content: "";
  inset: 0;
  position: absolute;
  z-index: -1;
}

.hero-copy {
  position: relative;
  z-index: 2;
}

.hero h1 {
  font-size: clamp(42px, 7vw, 88px);
  line-height: 0.95;
  margin: 0 0 20px;
  max-width: 880px;
}

.hero p {
  color: rgba(255, 255, 255, 0.86);
  font-size: clamp(17px, 2vw, 22px);
  line-height: 1.55;
  max-width: 720px;
}

.hero-panel {
  align-self: end;
  background: rgba(255, 255, 255, 0.93);
  backdrop-filter: blur(16px);
  border-radius: 8px;
  color: var(--ink);
  padding: 24px;
  position: relative;
  transform: translate(calc(var(--mx) * -8px), calc(var(--my) * -8px));
  z-index: 2;
}

:root[data-theme="dark"] .hero-panel {
  background: rgba(23, 26, 31, 0.88);
  color: var(--ink);
}

.hero-panel:hover,
.card:hover {
  box-shadow: 0 18px 42px rgba(23, 26, 31, 0.12);
  transform: translateY(-3px);
}

.motion-field {
  inset: 0;
  pointer-events: none;
  position: absolute;
  transform: translate(calc(var(--mx) * 18px), calc(var(--my) * 18px));
  z-index: 1;
}

.float-item {
  animation: drift 12s ease-in-out infinite;
  animation-delay: var(--d);
  left: var(--x);
  opacity: 0.72;
  position: absolute;
  top: var(--y);
  transform: scale(var(--s));
}

.float-item.doc {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.18);
  height: 92px;
  width: 72px;
}

.float-item.doc::before,
.float-item.doc::after {
  content: "";
  left: 14px;
  position: absolute;
}

.float-item.doc::before {
  background: var(--brand);
  border-radius: 999px;
  height: 9px;
  top: 24px;
  width: 42px;
}

.float-item.doc::after {
  background:
    linear-gradient(var(--ink), var(--ink)) 0 0 / 38px 5px no-repeat,
    linear-gradient(var(--line), var(--line)) 0 18px / 44px 5px no-repeat,
    linear-gradient(var(--brand), var(--brand)) 0 36px / 30px 5px no-repeat;
  height: 46px;
  top: 44px;
  width: 48px;
}

.float-item.doc.mini {
  opacity: 0.45;
}

.float-item.line {
  background: linear-gradient(90deg, rgba(255,255,255,0), rgba(255,255,255,.82), rgba(255,255,255,0));
  height: 2px;
  width: 180px;
}

.float-item.gridbit {
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 8px;
  height: 84px;
  width: 140px;
}

.float-item.gridbit::before {
  background:
    linear-gradient(rgba(255,255,255,.24), rgba(255,255,255,.24)) 0 28px / 100% 1px no-repeat,
    linear-gradient(rgba(255,255,255,.24), rgba(255,255,255,.24)) 0 56px / 100% 1px no-repeat,
    linear-gradient(90deg, rgba(255,255,255,.24), rgba(255,255,255,.24)) 46px 0 / 1px 100% no-repeat,
    linear-gradient(90deg, rgba(255,255,255,.24), rgba(255,255,255,.24)) 92px 0 / 1px 100% no-repeat;
  content: "";
  inset: 0;
  position: absolute;
}

.float-item.tag {
  background: rgba(215, 25, 32, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  padding: 9px 14px;
}

.float-item.tag.ghost {
  background: rgba(15, 118, 110, 0.74);
}

.hero-panel ul {
  display: grid;
  gap: 12px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.hero-panel li::before {
  color: var(--accent);
  content: "✓ ";
  font-weight: 900;
}

.section {
  padding: 58px clamp(18px, 4vw, 56px);
}

.section h2 {
  font-size: clamp(28px, 4vw, 44px);
  margin: 0 0 14px;
}

.lead {
  color: var(--muted);
  font-size: 18px;
  line-height: 1.6;
  max-width: 820px;
}

.grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 28px;
}

.pricing-grid {
  align-items: stretch;
}

.plan-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.plan-card .button {
  justify-content: center;
  margin-top: auto;
  width: 100%;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
  padding: 22px;
}

:root[data-theme="dark"] .card,
:root[data-theme="dark"] .auth-card {
  background: #171a1f;
}

.card:hover {
  border-color: rgba(215, 25, 32, 0.28);
}

@keyframes drift {
  0%, 100% {
    translate: 0 0;
    rotate: -2deg;
  }
  50% {
    translate: 18px -22px;
    rotate: 3deg;
  }
}

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

  .hero,
  .hero::before,
  .hero-panel,
  .motion-field {
    transform: none !important;
  }
}

.card h3 {
  margin: 0 0 8px;
}

.price {
  font-size: 34px;
  font-weight: 900;
  margin: 18px 0 8px;
}

.price small {
  color: var(--muted);
  font-size: 14px;
}

.features {
  color: var(--muted);
  line-height: 1.7;
  padding-left: 18px;
}

.workflow {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 26px;
}

.auth-wrap,
.dashboard {
  margin: 0 auto;
  max-width: 1180px;
  padding: 34px 18px;
}

.auth-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 32px auto;
  max-width: 520px;
  padding: 28px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 14px;
  font-weight: 700;
  gap: 8px;
  margin: 16px 0;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  min-height: 42px;
  padding: 10px 12px;
  width: 100%;
}

.stats {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat strong {
  display: block;
  font-size: 28px;
}

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

.table th,
.table td {
  border-bottom: 1px solid var(--line);
  padding: 13px 10px;
  text-align: left;
}

.table input,
.table select {
  min-width: 130px;
}

.company-table {
  table-layout: fixed;
}

.company-id {
  width: 44px;
}

.company-owner {
  width: 16%;
}

.company-name {
  width: 16%;
}

.company-rut {
  width: 116px;
}

.company-contact {
  width: 17%;
}

.company-location {
  width: 17%;
}

.company-template {
  width: 92px;
}

.company-actions-col {
  width: 170px;
}

.company-table th,
.company-table td {
  padding-left: 8px;
  padding-right: 8px;
}

.company-table .button,
.company-table button {
  min-height: 38px;
  padding: 0 12px;
}

.summary-cell {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.table-actions form {
  margin: 0;
}

.settings-form {
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-form button {
  justify-self: start;
}

.auth-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: space-between;
  margin-top: 18px;
}

.auth-actions a {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.modal-dialog {
  background: transparent;
  border: 0;
  max-width: min(560px, calc(100vw - 28px));
  padding: 0;
  width: 100%;
}

.modal-dialog.modal-wide {
  max-width: min(780px, calc(100vw - 28px));
}

.modal-dialog::backdrop {
  background: rgba(15, 18, 23, 0.62);
  backdrop-filter: blur(6px);
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(23, 26, 31, 0.28);
  color: var(--ink);
  padding: 22px;
}

.modal-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.modal-head h2 {
  margin: 0;
}

.modal-form-grid {
  display: grid;
  gap: 0 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.modal-form-grid label {
  min-width: 0;
}

.modal-full {
  grid-column: 1 / -1;
}

.modal-actions {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 10px;
}

.modal-form-grid label:has(input[type="checkbox"]) {
  align-items: center;
  display: flex;
  gap: 10px;
}

.modal-form-grid label:has(input[type="checkbox"]) input {
  min-height: auto;
  width: auto;
}

.icon-button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  font-size: 22px;
  height: 36px;
  justify-content: center;
  min-height: 36px;
  padding: 0;
  width: 36px;
}

.editor-preview {
  display: grid;
  gap: 22px;
  grid-template-columns: minmax(280px, 0.8fr) minmax(320px, 1.2fr);
}

.invoice-preview {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 42px rgba(23, 26, 31, 0.1);
  color: var(--ink);
  padding: clamp(18px, 4vw, 34px);
}

.invoice-preview header {
  align-items: flex-start;
  border-bottom: 2px solid var(--brand);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  padding-bottom: 18px;
}

.invoice-preview img {
  max-height: 76px;
  max-width: 180px;
  object-fit: contain;
}

.invoice-preview h2 {
  margin: 10px 0 8px;
}

.invoice-preview p {
  color: var(--muted);
  margin: 4px 0;
}

.invoice-stamp {
  border: 2px solid var(--brand);
  border-radius: 8px;
  color: var(--brand);
  min-width: 170px;
  padding: 14px;
  text-align: center;
}

.invoice-stamp strong,
.invoice-stamp span {
  display: block;
}

.invoice-client {
  margin: 22px 0;
}

.badge {
  background: #eef7f5;
  border-radius: 999px;
  color: var(--accent);
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 9px;
}

.footer {
  align-items: center;
  background: rgba(0, 0, 0, 0.88);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  color: #d9dde3;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
  padding: 32px clamp(18px, 4vw, 56px);
}

.footer a {
  color: #fff;
}

.copyright {
  color: #aeb6c2;
  font-size: 14px;
}

.social-icons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.social-icons a {
  align-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 900;
  height: 36px;
  justify-content: center;
  text-decoration: none;
  text-transform: uppercase;
  width: 36px;
}

@media (max-width: 1100px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 920px) {
  .site-header,
  .app-header {
    gap: 12px;
    padding: 12px 16px;
  }

  .brand {
    flex: 1 1 auto;
    min-width: 0;
  }

  .brand span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .menu-toggle {
    display: inline-flex;
    order: 2;
  }

  .nav {
    align-content: start;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 22px 60px rgba(23, 26, 31, 0.18);
    display: grid;
    gap: 10px;
    max-height: calc(100vh - 86px);
    opacity: 0;
    overflow-y: auto;
    padding: 12px;
    pointer-events: none;
    position: absolute;
    right: 16px;
    top: calc(100% + 8px);
    transform: translateY(-6px);
    transition: opacity 150ms ease, transform 150ms ease;
    width: min(320px, calc(100vw - 32px));
  }

  .nav-open .nav {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }

  .nav a,
  .nav .button,
  .nav button,
  .nav .lang-menu,
  .nav .lang-menu summary {
    justify-content: center;
    width: 100%;
  }

  .nav a {
    border-radius: 8px;
    padding: 10px 12px;
  }

  .nav a:not(.button) {
    background: rgba(23, 26, 31, 0.04);
  }

  :root[data-theme="dark"] .nav a:not(.button) {
    background: rgba(255, 255, 255, 0.06);
  }

  .nav .lang-menu {
    flex-basis: auto;
  }

  .nav .lang-options {
    position: static;
    transform: none;
    width: 100%;
  }

  .nav .lang-menu[open] .lang-options {
    margin-top: 6px;
  }

  .hero,
  .workflow,
  .stats {
    grid-template-columns: 1fr 1fr;
  }

  .hero {
    min-height: auto;
  }
}

@media (max-width: 640px) {
  .footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .hero,
  .grid,
  .workflow,
  .stats {
    grid-template-columns: 1fr;
  }

  .hero {
    gap: 20px;
    padding-bottom: 42px;
    padding-top: 42px;
  }

  .hero h1 {
    font-size: clamp(36px, 12vw, 52px);
    line-height: 1;
  }

  .hero p {
    font-size: 16px;
  }

  .hero-copy p:last-child {
    display: grid;
    gap: 10px;
  }

  .hero-copy .button {
    justify-content: center;
    width: 100%;
  }

  .float-item.line,
  .float-item.gridbit {
    display: none;
  }

  .section {
    padding-bottom: 42px;
    padding-top: 42px;
  }

  .card {
    padding: 18px;
  }

  .price {
    font-size: 30px;
  }

  .features {
    padding-left: 16px;
  }

  .settings-form,
  .modal-form-grid {
    grid-template-columns: 1fr;
  }

  .editor-preview,
  .invoice-preview header {
    grid-template-columns: 1fr;
  }

  .invoice-preview header {
    display: block;
  }

  .modal-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .modal-actions .button,
  .modal-actions button {
    justify-content: center;
    width: 100%;
  }
}
