@import "tailwindcss";

:root {
  --background: #ffffff;
  --foreground: #111111;
  --color-red: #c00021; /* Portuguese flag red (high contrast) */
  --color-green: #006a3d; /* Portuguese flag green (high contrast) */
  --color-focus: #1a73e8; /* Accessible focus color */
  --color-muted: #666666;
  --color-border: #e5e7eb;
}

@theme inline {
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --font-sans: var(--font-inter);
}

/* Force light mode; remove automatic dark scheme */

body {
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-inter), system-ui, -apple-system, Segoe UI, Roboto,
    Ubuntu, Cantarell, Noto Sans, sans-serif;
  transition: background-color 200ms ease, color 200ms ease;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Typography baseline */
h1 { font-size: 2rem; line-height: 1.25; }
h2 { font-size: 1.5rem; line-height: 1.3; }
h3 { font-size: 1.25rem; line-height: 1.3; }
p  { font-size: 1rem; line-height: 1.6; color: var(--foreground); }
.muted { color: var(--color-muted); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
}
.modal-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 201;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow: auto;
}
.modal-content {
  background: #fff;
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  text-align: center;
}
.modal-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--foreground);
}
.modal-description {
  font-size: 1rem;
  margin-bottom: 1rem;
  color: var(--foreground);
}
.modal-info {
  font-size: 0.875rem;
  color: var(--color-muted);
  margin-bottom: 1.5rem;
}
.modal-button {
  display: inline-block;
  background: var(--color-green);
  color: #fff;
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 150ms ease, transform 150ms ease;
}
.modal-button:hover,
.modal-button:focus-visible {
  opacity: 0.92;
  transform: translateY(-2px);
}

/* Language switcher button */
.lang-switcher-btn {
  background: transparent;
  border: none;
  font-weight: 700;
  color: #fff;
  padding: 0.375rem 0.625rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 150ms ease;
}
.lang-switcher-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}
.lang-switcher-btn.current {
  background: rgba(255, 255, 255, 0.2);
}

/* Markdown content */
.markdown-content {
  display: block;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
  hyphens: none;
  word-break: normal;
}

.markdown-content * {
  word-break: normal;
  hyphens: none;
  overflow-wrap: break-word;
}
.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 { 
  margin-top: 1.25rem; 
  margin-bottom: 0.75rem;
  scroll-margin-top: 110px; /* Account for header + subnav on mobile + padding */
  overflow-wrap: break-word;
  word-wrap: break-word;
  color: var(--color-green);
  font-weight: bold;
}

.markdown-content h1 a,
.markdown-content h2 a,
.markdown-content h3 a,
.markdown-content h4 a,
.markdown-content h5 a,
.markdown-content h6 a {
  color: var(--color-green);
  text-decoration: none;
}

@media (min-width: 768px) {
  .markdown-content h1,
  .markdown-content h2,
  .markdown-content h3,
  .markdown-content h4,
  .markdown-content h5,
  .markdown-content h6 {
    scroll-margin-top: 150px; /* More space on desktop + padding */
  }
}
.markdown-content p, .markdown-content ul, .markdown-content ol { 
  margin-bottom: 0.75rem;
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: normal;
  hyphens: none;
  -webkit-hyphenate-character: "";
}
.markdown-content ul { padding-left: 1.25rem; list-style: disc; }
.markdown-content ol { padding-left: 1.25rem; list-style: decimal; }
.markdown-content li {
  word-break: normal;
  hyphens: none;
  overflow-wrap: break-word;
}
.markdown-content a { 
  text-decoration: underline;
  word-break: normal;
  overflow-wrap: break-word;
  color: #0066cc;
}

/* Markdown blockquote */
.markdown-blockquote {
  border-left: 4px solid var(--color-green);
  padding: 0.75rem 1.25rem;
  margin: 1.25rem 0;
  background: rgba(0, 106, 61, 0.05);
  font-style: italic;
  color: var(--foreground);
}
.markdown-blockquote p:last-child {
  margin-bottom: 0;
}

/* Markdown code */
.markdown-code-inline {
  background: rgba(0, 0, 0, 0.06);
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9em;
  color: var(--color-red);
  word-break: break-word;
}
.markdown-pre {
  background: #f5f5f5;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
  margin: 1rem 0;
  max-width: 100%;
}
.markdown-pre code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--foreground);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Markdown table */
.markdown-table-wrapper {
  overflow-x: auto;
  margin: 1.25rem 0;
  max-width: 100%;
}
.markdown-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--color-border);
  table-layout: auto;
}
.markdown-table th,
.markdown-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border: 1px solid var(--color-border);
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.markdown-table th {
  background: rgba(0, 106, 61, 0.08);
  font-weight: 700;
  color: var(--foreground);
}
.markdown-table tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.02);
}
.markdown-table tr:hover {
  background: rgba(0, 106, 61, 0.03);
}

/* Markdown horizontal rule */
.markdown-hr {
  border: none;
  border-top: 2px solid var(--color-border);
  margin: 2rem 0;
}

/* Markdown images */
.markdown-img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 1.25rem 0;
  display: block;
}

/* Markdown iframes */
.markdown-iframe {
  max-width: 100%;
  width: 100%;
  height: 600px;
  margin: 1.5rem 0;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

/* Layout utilities */
.container {
  width: 100%;
  max-width: 72rem; /* ~1152px */
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

/* Hero */
.hero {
  padding: 3rem 0;
  animation: fade-in-up 400ms ease both;
}
.hero-overlay {
  position: relative;
  min-height: 400px;
  display: flex;
  align-items: center;
  overflow: hidden;
}
.hero-overlay .carousel {
   position: absolute;
   inset: 0;
   z-index: 1;
}
.hero-overlay .carousel-controls {
   z-index: 2;
}
.hero-overlay .carousel-viewport {
  height: 100%;
}
.hero-content {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  min-height: 400px;
  padding-left: 1.5rem;
}
.hero-overlay .title,
.hero-overlay .subtitle {
  color: #ffffff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.hero-overlay .title {
  font-size: 2.25rem;
  font-weight: 800;
}
.hero-overlay .subtitle {
  margin-top: 0.5rem;
  font-size: 1.1rem;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}
.hero-overlay .btn {
  text-shadow: none;
  border: 1px solid rgba(255, 255, 255, 0.3);
}
.hero-overlay .btn-primary {
  background-color: var(--color-green);
  color: #fff;
}
.hero-overlay .btn-outline {
  background-color: rgba(255, 255, 255, 0.95);
  color: var(--foreground);
}

/* Carousel */
.carousel {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--color-border);
  margin-bottom: 1.5rem;
}
.carousel-viewport {
  position: relative;
  width: 100%;
  height: 320px;
  background: #f8f8f8;
}
.carousel-slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 250ms ease;
}
.carousel-slide.active {
  opacity: 1;
}
.carousel-controls {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.35) 100%);
}
.carousel-btn {
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  cursor: pointer;
}
.carousel-btn:hover,
.carousel-btn:focus-visible {
  background: #fff;
  border-color: var(--color-green);
}
.carousel-dots {
  display: inline-flex;
  gap: 0.4rem;
}
.carousel-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid #fff;
  background: rgba(255,255,255,0.6);
  cursor: pointer;
}
.carousel-dot.active {
  background: #fff;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-border);
  transition: opacity 150ms ease, transform 150ms ease, background-color 150ms ease, color 150ms ease;
}
.btn-primary {
  background-color: var(--color-green);
  color: #fff;
  border-color: var(--color-green);
}
.btn-primary:hover, .btn-primary:focus-visible { opacity: 0.92; transform: translateY(-1px); }
.btn-outline { background-color: #fff; color: var(--foreground); }
.btn-outline:hover, .btn-outline:focus-visible { transform: translateY(-1px); }

/* Skip link for keyboard users */
.skip-link {
  position: absolute;
  left: -999px;
  top: -999px;
  background: #fff;
  color: #000;
  border: 2px solid var(--color-focus);
  padding: 0.5rem 0.75rem;
  z-index: 1000;
}
.skip-link:focus {
  left: 0.75rem;
  top: 0.75rem;
}

/* Header & navigation */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: #ffffff;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
}
.nav {
  position: relative;
}
.top-accent {
  height: 6px;
  background-color: var(--color-red);
}
.logo {
  display: inline-flex;
  align-items: center;
}
.nav-toggle {
  display: none;
}
.nav-list {
  display: flex;
  gap: 1rem;
  align-items: center;
}
.nav-list a,
.nav-label {
  padding: 0.5rem 0.75rem;
  border-radius: 999px;
  transition: background-color 150ms ease, transform 150ms ease;
  display: inline-flex;
  align-items: center;
}
.nav-label {
  cursor: pointer;
}
.nav-list a:hover,
.nav-list a:focus-visible,
.nav-label:hover {
  background-color: rgba(0,0,0,0.06);
  transform: translateY(-1px);
}
.nav-list a.active,
.nav-label.active {
  background-color: rgba(0,0,0,0.06);
  font-weight: 700;
}
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
}
.nav-item.has-sub > .submenu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 220px;
  background: #fff;
  border: 1px solid var(--color-border);
  box-shadow: 0 8px 20px rgba(0,0,0,0.08);
  padding: 0.5rem;
  border-radius: 10px;
  z-index: 60;
}
.nav-item.has-sub:hover > .submenu,
.nav-item.has-sub:focus-within > .submenu {
  display: block;
}
.submenu a { display: block; padding: 0.5rem 0.75rem; border-radius: 8px; }
.submenu a:hover, .submenu a:focus-visible { background: rgba(0,0,0,0.06); }
.lang-switcher {
  display: inline-flex;
  gap: 0.25rem;
  background: var(--color-red);
  color: #fff;
  border-radius: 999px;
  padding: 0.25rem;
}
.lang-switcher a {
  font-weight: 700;
  color: #fff;
  padding: 0.375rem 0.625rem;
  border-radius: 999px;
}
.lang-switcher a.current {
  background: rgba(255,255,255,0.2);
}

/* Footer */
.app-footer {
  border-top: 4px solid var(--color-red);
  margin-top: auto;
}
.footer-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}
.footer-left {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.footer-left > p {
  margin: 0;
}
.footer-links {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-left: auto;
}
.footer-links a {
  text-decoration: underline;
  font-size: 0.875rem;
  color: var(--color-muted);
}
.footer-links a:hover,
.footer-links a:focus-visible {
  color: var(--foreground);
}
.footer-attribution {
  font-size: 0.75rem;
  color: var(--color-muted);
}
.footer-attribution a {
  color: var(--color-muted);
  text-decoration: underline;
}
.footer-attribution a:hover,
.footer-attribution a:focus-visible {
  color: var(--foreground);
}

/* Subnav bar */
.subnav-bar {
  position: sticky;
  top: 66px; /* Below main header */
  z-index: 40;
  border-top: 1px solid var(--color-border);
  background: #fff;
}
.subnav {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0;
  justify-content: flex-start;
}
.subnav a {
  padding: 0.375rem 0.625rem;
  border-radius: 999px;
}
.subnav a.active,
.subnav a:hover,
.subnav a:focus-visible {
  background: rgba(0,0,0,0.06);
}

/* Table of Contents */
.toc-container {
  position: sticky;
  /* Account for header (~66px) + subnav (~50px) + padding */
  top: 160px;
  align-self: start;
  z-index: 30;
}

/* Mobile: ToC is not sticky, flows in document */
@media (max-width: 767px) {
  .toc-container {
    position: relative;
    top: 0;
    margin-bottom: 1.5rem;
  }
}

.toc-toggle {
  width: 100%;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: #f0f7ff;
  color: #1a73e8;
  border: 1px solid #c2d9f7;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background 150ms ease, border-color 150ms ease;
}

.toc-toggle:hover {
  background: #e0efff;
  border-color: #a0c4f0;
}

.toc-toggle-icon {
  font-size: 1rem;
}

.toc-nav {
  display: none;
  padding: 1rem;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  margin-bottom: 1.5rem;
}

.toc-nav--open {
  display: block;
}

@media (min-width: 768px) {
  .toc-toggle {
    display: none;
  }
  
  .toc-nav {
    display: block;
    /* Account for header + subnav + padding (120px top + some bottom margin) */
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    padding: 1rem;
    background: #fafafa;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    margin-bottom: 0;
  }
}

.toc-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-item {
  margin: 0;
}

.toc-link {
  display: block;
  padding: 0.375rem 0.625rem;
  border-radius: 6px;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--foreground);
  text-decoration: none;
  transition: background 150ms ease, color 150ms ease;
  border-left: 2px solid transparent;
  margin-left: -2px;
}

.toc-link:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--foreground);
}

.toc-link--active {
  background: rgba(26, 115, 232, 0.08);
  color: #1a73e8;
  font-weight: 600;
  border-left-color: #1a73e8;
}

/* Animations */
@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .hero, .markdown-content { animation: none; }
  .nav-list a, .btn { transition: none; }
}

/* Focus styles */
:where(a, button, input, select, textarea, summary, [role="button"]):focus,
:where(a, button, input, select, textarea, summary, [role="button"]):focus-visible,
:where(a, button, input, select, textarea, summary, [role="button"]):focus-within {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

/* Responsive navigation */
@media (max-width: 768px) {
  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 2px solid var(--foreground);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 1.25rem;
  }
  .nav-list {
    display: none;
    flex-direction: column;
    gap: 0.5rem;
    position: fixed;
    top: calc(60px + 6px);
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: calc(100vh - 60px - 6px);
    background: #ffffff;
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 8px 20px rgba(0,0,0,0.1);
    padding: 1rem;
    z-index: 100;
    overflow-y: auto;
  }
  .nav-list[data-expanded="true"] {
    display: flex;
  }
  .nav-item {
    width: 100%;
  }
  .nav-item.has-sub > .submenu {
    position: static;
    display: none;
    flex-direction: column;
    gap: 0.25rem;
    box-shadow: none;
    border: none;
    background: rgba(0,0,0,0.03);
    padding: 0.5rem 0.75rem;
    margin-top: 0.25rem;
    min-width: auto;
  }
  .nav-item.has-sub > .submenu.expanded {
    display: flex;
  }
  .nav-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
  }
  .nav-submenu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    font-size: 1rem;
  }
  .nav-submenu-toggle::after {
    content: "▼";
    font-size: 0.625rem;
    transition: transform 150ms ease;
  }
  .nav-submenu-toggle[aria-expanded="true"]::after {
    transform: rotate(180deg);
  }
  .submenu a {
    display: block;
    padding: 0.375rem 0;
  }
}
