:root {
  --font-display: "Sora", "Segoe UI", system-ui, sans-serif;
  --font-body: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --ink: #1e1e1e;
  --muted: #4c575f;
  --accent: #2f9e41;
  --accent-soft: #e6f4e9;
  --accent-warm: #c90c0f;
  --surface: #ffffff;
  --surface-muted: #f4f6f8;
  --border: #dfe3ea;
  --shadow: 0 18px 60px rgba(17, 24, 39, 0.12);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: #f2f1ea;
  min-height: 100vh;
}

.ambient {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at top left, rgba(47, 158, 65, 0.16), transparent 45%),
    radial-gradient(circle at 70% 20%, rgba(201, 12, 15, 0.12), transparent 40%),
    radial-gradient(circle at bottom right, rgba(47, 158, 65, 0.1), transparent 48%),
    linear-gradient(120deg, #f2f6f1 0%, #f7faf6 55%, #f1f7f2 100%);
  z-index: 0;
  pointer-events: none;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

body.sidebar-collapsed .app-shell {
  grid-template-columns: 0 1fr;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.8rem 1.5rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: 10px 0 35px rgba(30, 41, 59, 0.04);
  position: relative;
  z-index: 10;
}

body.sidebar-collapsed .sidebar {
  width: 0;
  padding: 0;
  border-right: none;
  overflow: hidden;
  box-shadow: none;
}

body.sidebar-collapsed .sidebar > * {
  opacity: 0;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  margin: 0 0 0.2rem;
  font-weight: 700;
}

.brand-subtitle {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}


.menu {
  flex: 1;
  overflow-y: auto;
  padding-right: 0.3rem;
}

.menu-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.4rem;
}

.menu-item {
  margin: 0;
}

.menu-link {
  width: 100%;
  border: none;
  background: transparent;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 0.95rem;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.menu-link:hover,
.menu-link:focus {
  background: rgba(15, 107, 91, 0.08);
  color: var(--accent);
  transform: translateX(2px);
  outline: none;
}

.menu-link.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.menu-group {
  margin-bottom: 0.6rem;
}

.menu-folder summary {
  cursor: pointer;
  list-style: none;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.2s ease, color 0.2s ease;
}

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

.menu-folder summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 0.4rem;
  transition: transform 0.2s ease;
}

.menu-folder[open] summary::before {
  transform: rotate(90deg);
}

.menu-folder[open] summary {
  color: var(--accent);
  background: rgba(15, 107, 91, 0.08);
}

.menu-folder > ul {
  margin-top: 0.5rem;
  padding-left: 0.6rem;
  border-left: 2px solid rgba(15, 107, 91, 0.15);
}

.sidebar-footer {
  display: grid;
  gap: 0.6rem;
}

.ghost-button,
.accent-button,
.icon-button {
  border: none;
  cursor: pointer;
  border-radius: 999px;
  font-family: var(--font-body);
}

.ghost-button {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.55rem 1.1rem;
  font-size: 0.9rem;
  color: var(--ink);
  transition: border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.ghost-button:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 8px 16px rgba(47, 158, 65, 0.12);
  transform: translateY(-1px);
}

.accent-button {
  background: var(--accent);
  color: #fff;
  padding: 0.6rem 1.4rem;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 12px 20px rgba(15, 107, 91, 0.2);
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: rgba(15, 107, 91, 0.08);
  color: var(--accent);
  font-size: 1.2rem;
}

.main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1.5rem 2.4rem;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-text h1 {
  margin: 0 0 0.3rem;
  font-family: var(--font-display);
  font-size: 1.4rem;
}

.header-text p {
  margin: 0;
  color: var(--muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.content {
  padding: 2rem 2.4rem 3rem;
}

.controls-area {
  display: grid;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.zoom-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

@media (max-width: 1024px) {
  .topbar {
    flex-wrap: wrap;
    gap: 1rem;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}

.zoom-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.zoom-button {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
  min-width: 42px;
}

.zoom-value {
  font-weight: 600;
  min-width: 48px;
  text-align: center;
}

.loading {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-radius: 999px;
  border: 1px solid var(--border);
  margin-bottom: 1rem;
  font-weight: 600;
  color: var(--muted);
}

.loading[hidden],
[hidden] {
  display: none !important;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid rgba(15, 107, 91, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.quadro {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  min-height: 60vh;
  overflow-x: auto;
  --table-scale: 1;
}

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--muted);
}

.empty-state h2 {
  font-family: var(--font-display);
  color: var(--ink);
  margin-bottom: 0.6rem;
}

.empty-state.error {
  color: #b42318;
}

.quadro table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem auto;
  font-size: calc(0.85rem * var(--table-scale));
}

.quadro th,
.quadro td {
  padding: calc(0.45rem * var(--table-scale)) calc(0.4rem * var(--table-scale));
  border: 1px solid rgba(148, 163, 184, 0.35);
  position: relative;
  z-index: 1;
}

.quadro table thead th {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 3;
  box-shadow: 0 2px 0 rgba(148, 163, 184, 0.2);
}

.quadro table th.yAxis {
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 4;
}

.quadro table thead th:first-child {
  left: 0;
  z-index: 5;
}

.quadro th.yAxis {
  height: calc(8ex * var(--table-scale));
}

.quadro caption {
  margin-bottom: 0.6rem;
  font-weight: 600;
  color: var(--ink);
}

.form-group {
  margin: 1rem 0 1.5rem;
  clear: both;
  width: 100%;
}

.schedule-search {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.8rem;
  width: 100%;
}

.schedule-search label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.schedule-search input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.95rem;
  background: var(--surface-muted);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.schedule-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 158, 65, 0.18);
}

.quadro .wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin: 0.6rem 0 1rem;
  float: none;
}

.quadro .wrapper > div {
  display: flex;
}

.quadro .wrapper .button {
  margin: 0;
}


.selection-summary {
  font-size: 0.85rem;
  color: var(--muted);
}

.form-group select {
  width: 100%;
  min-height: 160px;
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-family: var(--font-body);
  background: var(--surface-muted);
}

.tables-area {
  position: relative;
  margin-top: 1.2rem;
}

#tablesPool {
  display: none;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 1000;
  pointer-events: none;
}

.open-sidebar,
.close-sidebar {
  display: none;
}

@media (max-width: 980px) {
  #toggleSidebar {
    display: none;
  }

  body.sidebar-collapsed .app-shell {
    grid-template-columns: 1fr;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100%;
    width: 85%;
    max-width: 340px;
    transition: left 0.25s ease;
    z-index: 1001;
    pointer-events: auto;
    -webkit-overflow-scrolling: touch;
    will-change: left;
  }

  body.sidebar-open .sidebar {
    left: 0;
  }


  .open-sidebar,
  .close-sidebar {
    display: grid;
  }

  .topbar {
    padding: 1.2rem 1.4rem;
  }

  .content {
    padding: 1.6rem 1.4rem 2.5rem;
  }

  .controls-area {
    gap: 0.7rem;
  }

  .zoom-controls {
    justify-content: flex-start;
  }

  .quadro {
    padding: 1.1rem;
  }
}

@media (max-width: 640px) {
  .header-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .header-text h1 {
    font-size: 1.2rem;
  }

  .header-actions .ghost-button,
  .header-actions .accent-button {
    width: 100%;
    justify-content: center;
  }

  .zoom-controls {
    width: 100%;
    justify-content: space-between;
  }

  .zoom-button {
    flex: 1 1 auto;
    min-width: 44px;
  }

  .schedule-search input {
    font-size: 1rem;
  }

  .form-group select {
    min-height: 220px;
  }

  .quadro table {
    font-size: calc(0.8rem * var(--table-scale));
  }
}

@media (max-width: 420px) {
  .sidebar {
    width: 92%;
  }

  .quadro {
    padding: 0.9rem;
  }

  .brand-title {
    font-size: 1rem;
  }
}
