@import url("./tokens.css");

/* ============================================================================
 * main.css — ContaAutónomo GitHub Pages site
 * ----------------------------------------------------------------------------
 * Mobile-first. Loads tokens.css first for design-token custom properties.
 *
 * Layout strategy:
 *   - <main id="main"> from default.html is the page content container.
 *     We constrain its width and apply horizontal padding directly here
 *     instead of introducing a wrapping .container class.
 *   - Site nav is a single-row flex container at >= 768px and a stacked
 *     menu controlled by a hamburger button on smaller screens.
 *   - Active menu item is styled via the [aria-current="page"] selector
 *     emitted by _includes/nav.html.
 *
 * Accessibility:
 *   - body font-size is 1rem (>= 16px) per Requirement 1.3.
 *   - :focus-visible draws a 2px outline using --color-focus-ring.
 *   - .skip-link is offscreen until focused, then anchored top-left.
 *   - .visually-hidden hides text from sighted users while keeping it in
 *     the accessibility tree (used inside the nav toggle button).
 *
 * Tokens used in this file are defined in tokens.css.
 * ========================================================================= */

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

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

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--color-fg);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
h4,
h5,
h6,
p,
figure,
blockquote,
dl,
dd {
  margin: 0;
}

ul,
ol {
  margin: 0;
  padding: 0;
}

img,
picture,
svg,
video {
  max-width: 100%;
  height: auto;
  display: block;
}

hr {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin: var(--space-6) 0;
}

/* ---------------------------------------------------------------------------
 * 2. Page container — applied directly to <main>
 * ------------------------------------------------------------------------ */
main {
  display: block; /* legacy fallback */
  max-width: 72rem;
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2rem);
  padding-block: var(--space-6);
}

.container {
  max-width: 72rem;
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2rem);
}

/* ---------------------------------------------------------------------------
 * 3. Skip link
 * ------------------------------------------------------------------------ */
.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
  z-index: 1000;
}

.skip-link:focus,
.skip-link:focus-visible {
  position: absolute;
  left: var(--space-3);
  top: var(--space-3);
  width: auto;
  height: auto;
  padding: var(--space-2) var(--space-4);
  background: var(--color-accent);
  color: var(--color-accent-fg);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

/* ---------------------------------------------------------------------------
 * 4. Focus indicators
 * ------------------------------------------------------------------------ */
:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Make <main> focus invisible — it is only used as a skip-link target. */
main:focus,
main:focus-visible {
  outline: none;
}

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

/* ---------------------------------------------------------------------------
 * 6. Links
 * ------------------------------------------------------------------------ */
a {
  color: var(--color-link);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

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

a:visited {
  color: var(--color-link);
}

/* ---------------------------------------------------------------------------
 * 7. Typography — headings, paragraphs, lists
 * ------------------------------------------------------------------------ */
h1,
h2,
h3,
h4,
h5,
h6 {
  line-height: 1.25;
  font-weight: 700;
}

h1 {
  font-size: 2rem;
  margin-top: var(--space-2);
  margin-bottom: var(--space-5);
}

h2 {
  font-size: 1.5rem;
  margin-top: var(--space-7);
  margin-bottom: var(--space-4);
}

h3 {
  font-size: 1.25rem;
  margin-top: var(--space-6);
  margin-bottom: var(--space-3);
}

h4 {
  font-size: 1.125rem;
  margin-top: var(--space-5);
  margin-bottom: var(--space-2);
}

p {
  margin-bottom: var(--space-4);
}

main ul,
main ol {
  margin-bottom: var(--space-4);
  padding-left: var(--space-5);
}

main li + li {
  margin-top: var(--space-1);
}

small {
  color: var(--color-fg-muted);
}

/* ---------------------------------------------------------------------------
 * 8. Site header & nav (mobile-first)
 * ------------------------------------------------------------------------ */
.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  max-width: 72rem;
  margin-inline: auto;
  padding: var(--space-3) clamp(1rem, 4vw, 2rem);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
}

.site-brand {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--color-fg);
  text-decoration: none;
}

.site-brand:hover {
  color: var(--color-link-hover);
}

.nav-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  min-width: 2.5rem;
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-size: 1.25rem;
  line-height: 1;
  background: transparent;
  color: var(--color-fg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.nav-toggle:hover {
  background: var(--color-surface);
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  /* On mobile the menu spans full width below brand+toggle. */
  flex-basis: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-2);
}

/* When the nav.js script collapses the menu, the [hidden] attribute hides it. */
.nav-list[hidden] {
  display: none;
}

.nav-item {
  margin: 0;
}

.nav-link {
  display: block;
  padding: var(--space-2) var(--space-3);
  color: var(--color-fg);
  text-decoration: none;
  border-radius: var(--radius-sm);
}

.nav-link:hover {
  background: var(--color-surface);
  color: var(--color-link-hover);
}

/* Active page indicator — works with either aria-current or .is-active. */
.nav-link[aria-current="page"],
.nav-link.is-active {
  font-weight: 700;
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

/* ---------------------------------------------------------------------------
 * 9. Site nav — tablet/desktop (>= 768px)
 * ------------------------------------------------------------------------ */
@media (min-width: 768px) {
  .site-nav {
    flex-wrap: nowrap;
  }

  .nav-toggle {
    display: none;
  }

  /* Always show the menu, even when nav.js left [hidden] in place
     (e.g. resize from mobile to desktop without re-running script). */
  .nav-list,
  .nav-list[hidden] {
    display: flex;
    flex-direction: row;
    flex-basis: auto;
    gap: var(--space-2);
    border-top: 0;
    padding-top: 0;
  }

  .nav-link {
    padding: var(--space-2) var(--space-3);
  }
}

/* ---------------------------------------------------------------------------
 * 10. Footer
 * ------------------------------------------------------------------------ */
.site-footer-inner {
  max-width: 72rem;
  margin-inline: auto;
  padding: var(--space-6) clamp(1rem, 4vw, 2rem);
  border-top: 1px solid var(--color-border);
  color: var(--color-fg-muted);
  font-size: 0.9375rem;
}

.footer-nav {
  margin-bottom: var(--space-3);
}

.footer-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.footer-copyright {
  margin: 0;
}

/* ---------------------------------------------------------------------------
 * 11. Hero / CTA (used on landing page)
 * ------------------------------------------------------------------------ */
.hero {
  padding: var(--space-7) 0 var(--space-6);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-6);
}

.hero h1 {
  margin-top: 0;
}

.hero .hero-tagline {
  font-size: 1.125rem;
  color: var(--color-fg-muted);
  margin-bottom: var(--space-5);
  max-width: 48rem;
}

.cta-button {
  display: inline-block;
  padding: var(--space-3) var(--space-5);
  background: var(--color-accent);
  color: var(--color-accent-fg);
  text-decoration: none;
  border-radius: var(--radius-md);
  font-weight: 600;
  border: 1px solid transparent;
}

.cta-button:hover {
  background: var(--color-link-hover);
  color: var(--color-accent-fg);
}

/* ---------------------------------------------------------------------------
 * 12. Module cards & feature lists (features page, landing page)
 * ------------------------------------------------------------------------ */
.module-card {
  padding: var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  margin-bottom: var(--space-5);
}

.module-card h3 {
  margin-top: 0;
}

.feature-list {
  list-style: disc;
  padding-left: var(--space-5);
  margin-bottom: var(--space-4);
}

.feature-list li {
  margin-top: var(--space-1);
}

.optional-badge {
  display: inline-block;
  margin-left: var(--space-2);
  padding: 0.125rem var(--space-2);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-accent-fg);
  background: var(--color-accent);
  border-radius: var(--radius-sm);
  vertical-align: middle;
}

/* Generic active-state utility used by other widgets (e.g. tabs). */
.is-active {
  font-weight: 600;
}

/* ---------------------------------------------------------------------------
 * 13. Screenshot grid + thumbnails
 * ------------------------------------------------------------------------ */
.screenshot-grid {
  list-style: none;
  margin: 0 0 var(--space-6);
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}

.screenshot-grid > li {
  margin: 0;
}

.screenshot-grid figure {
  margin: 0;
}

.screenshot-grid button {
  display: block;
  width: 100%;
  padding: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  overflow: hidden;
}

.screenshot-grid button:hover {
  border-color: var(--color-accent);
}

.screenshot-grid img {
  width: 100%;
  height: auto;
  display: block;
}

.screenshot-grid figcaption {
  margin-top: var(--space-2);
  font-size: 0.9375rem;
  color: var(--color-fg-muted);
  line-height: 1.4;
}

.screenshot-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 6rem;
  padding: var(--space-4);
  background: var(--color-surface);
  color: var(--color-fg-muted);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.875rem;
}

/* ---------------------------------------------------------------------------
 * 14. Tables
 * ------------------------------------------------------------------------ */
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--space-5);
  font-size: 0.9375rem;
}

caption {
  caption-side: top;
  text-align: left;
  font-weight: 600;
  padding-bottom: var(--space-2);
  color: var(--color-fg);
}

th,
td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: top;
}

th {
  font-weight: 600;
  background: var(--color-surface);
}

/* Allow tables to scroll horizontally inside a wrapper if needed. */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

/* ---------------------------------------------------------------------------
 * 15. Code blocks
 * ------------------------------------------------------------------------ */
pre,
code,
kbd,
samp {
  font-family: var(--font-mono);
}

code {
  background: var(--color-surface);
  padding: 0.125rem 0.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
}

pre {
  background: var(--color-surface);
  color: var(--color-fg);
  padding: var(--space-4);
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  font-size: 0.875rem;
  line-height: 1.45;
  margin: 0 0 var(--space-5);
}

pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  border-radius: 0;
}

/* ---------------------------------------------------------------------------
 * 16. Lightbox dialog
 * ------------------------------------------------------------------------ */
dialog {
  border: none;
  padding: 0;
  max-width: 90vw;
  max-height: 90vh;
  background: var(--color-bg);
  color: var(--color-fg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

dialog img {
  display: block;
  max-width: 90vw;
  max-height: 90vh;
  width: auto;
  height: auto;
}

dialog figcaption {
  padding: var(--space-3) var(--space-4);
  font-size: 0.9375rem;
  color: var(--color-fg-muted);
  border-top: 1px solid var(--color-border);
}

dialog [data-lightbox-close] {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: var(--space-1) var(--space-3);
  background: var(--color-bg);
  color: var(--color-fg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font: inherit;
  cursor: pointer;
}

dialog [data-lightbox-close]:hover {
  background: var(--color-surface);
}

/* ---------------------------------------------------------------------------
 * 17. Mermaid + details fallback
 * ------------------------------------------------------------------------ */
pre.mermaid {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}

details {
  margin-bottom: var(--space-4);
}

details summary {
  cursor: pointer;
  font-weight: 600;
  padding: var(--space-2) 0;
}

/* ---------------------------------------------------------------------------
 * 18. Forms (sparse — primarily for completeness)
 * ------------------------------------------------------------------------ */
button,
[role="button"] {
  font: inherit;
}

button {
  cursor: pointer;
}

button[disabled] {
  cursor: not-allowed;
  opacity: 0.6;
}
