:root {
  /* Emerald Luxury Theme - Dark Mode */
  --bg-top: #0a0f0e;
  --bg-bottom: #0f1614;
  --panel: rgba(15, 22, 20, 0.95);
  --panel-border: rgba(0, 105, 62, 0.25);
  --ink: #f0f4f3;
  --muted: #a0aaa7;
  --accent: #00693E;
  --accent-strong: #004d2e;
  --warn: #ff6b6b;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  --accent-light: #099268;
  --bg-tertiary: #14231f;
  --text-secondary: #a0aaa7;
  --text-muted: #74817d;
  --sidebar-bg: #1a2623;
  --sidebar-border: rgba(0, 105, 62, 0.3);
  --sidebar-width: 240px;
}

* {
  box-sizing: border-box;
}

/* ── Auth gate (overlay mostrado enquanto validamos a sessão) ───────────────── */

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--ink, #f0f4f3);
  background:
    radial-gradient(circle at top left, rgba(0, 105, 62, 0.08), transparent 40%),
    linear-gradient(145deg, #0a0f0e, #0f1614);
  font-family: "Franklin Gothic Medium", "Trebuchet MS", sans-serif;
}

.auth-gate[hidden] {
  display: none;
}

.auth-gate__message {
  max-width: 420px;
  text-align: center;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  opacity: 0.85;
}

/* Wrapper transparente para o body grid; esconde tudo enquanto auth não completa. */
#appRoot {
  display: contents;
}

#appRoot[hidden] {
  display: none;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Franklin Gothic Medium", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(0, 105, 62, 0.08), transparent 40%),
    linear-gradient(145deg, var(--bg-top), var(--bg-bottom));
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
}

/* ── Sidebar Layout ─────────────────────────────────────────────────────────────── */

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 24px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  grid-column: 1;
  grid-row: 1;
}

.page-shell {
  grid-column: 2;
  grid-row: 1;
}

.sidebar-header {
  padding: 0 16px 20px;
  border-bottom: 1px solid var(--sidebar-border);
  margin-bottom: 20px;
}

.sidebar-header h2 {
  font-size: 0.9rem;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 0;
  font-weight: 600;
}

.nav-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 12px 20px;
  margin-bottom: 12px;
}

.nav-item {
  padding: 12px 16px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  border-radius: 12px;
  font-size: 0.9rem;
  transition: background-color 160ms ease, border-color 160ms ease;
  font-family: inherit;
}

.nav-item:hover {
  background: rgba(0, 105, 62, 0.08);
}

.nav-item.active {
  background: rgba(0, 105, 62, 0.15);
  border-color: rgba(0, 105, 62, 0.4);
  color: var(--accent-light);
  font-weight: 600;
}

.status-widget {
  background: rgba(15, 22, 20, 0.6);
  border: 1px solid var(--sidebar-border);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 0 12px;
  font-size: 0.85rem;
}

.status-widget h3 {
  margin: 0 0 10px;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
}

.status-widget-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent-light);
  margin-bottom: 8px;
  word-break: break-all;
}

.status-widget-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Hamburger (hidden on desktop) ───────────────────────────────────────────────── */

.hamburger-toggle {
  display: none;
}

/* ── Main content ────────────────────────────────────────────────────────────────── */

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 48px;
}

.hero {
  display: grid;
  grid-template-columns: 1.6fr 0.9fr;
  gap: 24px;
  margin-bottom: 24px;
}

.hero-copy,
.hero-card,
.panel {
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.hero-copy {
  padding: 32px;
}

.hero-card {
  padding: 28px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  position: relative;
  overflow: hidden;
}

.status-glow::after {
  content: "";
  position: absolute;
  inset: auto -20% -20% auto;
  width: 220px;
  height: 220px;
  background: radial-gradient(circle, rgba(0, 105, 62, 0.3), transparent 65%);
}

.eyebrow,
.hero-kicker,
.metric-label {
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.76rem;
  color: var(--muted);
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Rockwell", "Georgia", serif;
}

h1 {
  font-size: clamp(2.3rem, 5vw, 4.1rem);
  line-height: 0.98;
  margin-top: 10px;
}

.hero-text,
.panel-heading p,
.status-message,
.result-empty,
.event-feed,
.warnings-list,
.sections-list {
  color: var(--muted);
}

.grid-layout {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 24px;
}

.form-panel {
  grid-row: span 2;
}

.panel {
  padding: 24px;
}

.panel-heading {
  margin-bottom: 20px;
}

.form-grid {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
}

input,
select,
textarea,
button,
.download-link {
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  color: var(--ink);
}

textarea {
  resize: vertical;
  min-height: 108px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.toggle-row input {
  width: 18px;
  height: 18px;
}

button {
  padding: 16px 20px;
  border: none;
  font-weight: 700;
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease;
  box-shadow: 0 12px 24px rgba(0, 105, 62, 0.3);
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.65;
  cursor: wait;
}

.meter {
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: rgba(0, 105, 62, 0.1);
  overflow: hidden;
}

.meter-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-light), var(--accent));
  transition: width 220ms ease;
}

.status-row,
.job-meta,
.result-summary {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.job-meta,
.status-row {
  margin-top: 14px;
}

.event-feed,
.warnings-list,
.sections-list {
  margin: 18px 0 0;
  padding-left: 18px;
}

.event-feed li,
.warnings-list li,
.sections-list li {
  margin-bottom: 10px;
}

.result-summary {
  margin-bottom: 18px;
  padding: 16px;
  border-radius: 20px;
  background: var(--bg-tertiary);
  border: 1px solid var(--panel-border);
}

.result-actions {
  margin-bottom: 18px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  padding: 12px 16px;
  text-decoration: none;
  color: var(--accent-light);
  background: rgba(0, 105, 62, 0.15);
}

.hidden {
  display: none;
}

.error-text {
  color: var(--warn);
}

@media (max-width: 980px) {
  .hero,
  .grid-layout {
    grid-template-columns: 1fr;
  }

  .form-panel {
    grid-row: auto;
  }
}

@media (max-width: 1200px) {
  body {
    grid-template-columns: 200px 1fr;
  }

  .sidebar {
    padding: 20px 0;
  }

  .nav-item {
    padding: 10px 12px;
    font-size: 0.85rem;
  }

  .status-widget {
    padding: 12px;
    margin: 0 8px;
  }

  .page-shell {
    width: min(100%, calc(100% - 20px));
  }
}

@media (max-width: 800px) {
  body {
    grid-template-columns: 1fr;
  }

  .page-shell {
    grid-column: 1;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform 300ms ease;
    max-width: var(--sidebar-width);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .hamburger-toggle {
    display: none;
  }

  body > .hamburger-toggle {
    display: flex;
  }

  .hamburger-toggle {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 1000;
    background: rgba(0, 105, 62, 0.15);
    border: 1px solid rgba(0, 105, 62, 0.3);
    color: var(--accent-light);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
  }

  .hamburger-toggle:hover {
    background: rgba(0, 105, 62, 0.25);
  }

  .page-shell {
    padding-top: 60px;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 20px, 100%);
    padding-top: 60px;
    padding-bottom: 32px;
  }

  .hero-copy,
  .hero-card,
  .panel {
    border-radius: 22px;
  }

  h1 {
    font-size: 2.2rem;
  }

  .sidebar {
    max-width: 100%;
  }

  .sidebar-header {
    padding: 0 16px 16px;
  }

  .nav-item {
    padding: 12px 14px;
    font-size: 0.9rem;
  }
}

/* ── Authenticated user badge ───────────────────────────────────────────────── */
.auth-user-box {
  position: fixed;
  top: 16px;
  right: 20px;
  z-index: 1200;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: rgba(15, 22, 20, 0.92);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  color: var(--ink);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
}

.auth-user-name {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-logout-button {
  border: 0;
  background: transparent;
  color: var(--accent-light);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 6px;
}

.auth-logout-button:hover {
  text-decoration: underline;
}