:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --border: #e8e8ea;
  --accent: #2563eb;
  --accent-fg: #fff;
  --accent-soft: #eff4ff;
  --danger: #c0322a;
  --danger-soft: #fdeceb;
  --success: #15803d;
  --success-soft: #e8f7ee;
  --warning: #92660a;
  --warning-soft: #fef6e0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.04), 0 1px 12px rgba(20, 20, 30, 0.03);
  --sidebar-width: 252px;
  --sidebar-bg: #ffffff;
}

html[data-theme='dark'] {
  --bg: #15161a;
  --surface: #1d1f24;
  --fg: #eceef1;
  --muted: #9aa0ac;
  --border: #2c2e35;
  --accent: #4d7cf5;
  --accent-fg: #fff;
  --accent-soft: #1d2640;
  --danger: #ef6b62;
  --danger-soft: #38201f;
  --success: #4ade80;
  --success-soft: #163422;
  --warning: #f5c460;
  --warning-soft: #3a2c0f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 16px rgba(0, 0, 0, 0.25);
  --sidebar-bg: #1a1b20;
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', -apple-system, system-ui, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  margin: 0;
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.15s ease, color 0.15s ease;
}

a {
  color: var(--accent);
  text-decoration: none;
}

/* ===== Layout com sidebar fixa ===== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding-bottom: 1rem;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.98rem;
  padding: 1.4rem 1.25rem 1.1rem;
  letter-spacing: -0.01em;
  color: var(--fg);
  white-space: nowrap;
}

.sidebar-brand:hover {
  color: var(--accent);
}

.sidebar-brand svg {
  flex-shrink: 0;
  color: var(--accent);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 0 0.75rem;
  gap: 0.1rem;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--fg);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
}

.sidebar-nav a svg {
  flex-shrink: 0;
  opacity: 0.75;
}

.sidebar-nav a:hover {
  background: var(--bg);
}

.sidebar-nav a.active {
  background: var(--accent);
  color: var(--accent-fg);
}

.sidebar-nav a.active svg {
  opacity: 1;
}

.app-content {
  flex: 1;
  min-width: 0;
}

header.topbar-light {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-user {
  font-size: 0.85rem;
  color: var(--muted);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--accent-soft);
}

main {
  max-width: 1020px;
  margin: 0 auto;
  padding: 2rem 1.75rem 3rem;
}

h1 {
  font-size: 1.55rem;
  font-weight: 650;
  margin-bottom: 1.1rem;
  letter-spacing: -0.015em;
}

h2 {
  font-size: 1.08rem;
  font-weight: 600;
  margin-top: 1.75rem;
  letter-spacing: -0.01em;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.1rem;
}

.grid {
  display: grid;
  gap: 1.1rem;
}

.grid-2 {
  grid-template-columns: 1fr 1fr;
}

.grid-sidebar {
  grid-template-columns: 280px 1fr;
  align-items: start;
}

label {
  display: block;
  font-size: 0.83rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
  font-weight: 500;
}

input[type='text'],
input[type='email'],
input[type='password'],
input[type='number'],
input[type='date'],
input[type='datetime-local'],
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--fg);
  font-size: 0.95rem;
  margin-bottom: 0.85rem;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}

textarea {
  min-height: 5rem;
}

button,
.btn {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: opacity 0.15s ease;
}

button:hover,
.btn:hover {
  opacity: 0.9;
}

button.secondary,
.btn.secondary {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
}

button.danger,
.btn.danger {
  background: var(--danger);
}

/* ===== Toolbar de acoes compacta (ex: cards de turma) ===== */
.action-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.btn-sm,
.action-toolbar button,
.action-toolbar .btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.7rem;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
}

.action-toolbar .btn-divider {
  width: 1px;
  height: 1.3rem;
  background: var(--border);
  margin: 0 0.15rem;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}

th,
td {
  text-align: left;
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

tbody tr:hover {
  background: var(--bg);
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--bg);
  border: 1px solid var(--border);
}

.badge.success {
  background: var(--success-soft);
  color: var(--success);
  border-color: transparent;
}

.badge.error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}

.badge.pending {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: transparent;
}

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

.error-box {
  background: var(--danger-soft);
  color: var(--danger);
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.tag-list {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.steps-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.steps-bar .steps {
  flex: 1;
  margin-bottom: 0;
}

.step-action-btn {
  flex-shrink: 0;
  white-space: nowrap;
  font-size: 0.85rem;
  padding: 0.45rem 1rem;
}

.steps {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.steps .step {
  flex: 1;
  text-align: center;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  cursor: pointer;
}

.steps .step.active {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

iframe.pdf-preview {
  width: 100%;
  height: 70vh;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ===== Menu dropdown simples ===== */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  min-width: 11rem;
  z-index: 20;
  overflow: hidden;
}

.dropdown-menu.open {
  display: block;
}

.dropdown-menu a {
  display: block;
  padding: 0.6rem 0.9rem;
  color: var(--fg);
  font-size: 0.9rem;
}

.dropdown-menu a:hover {
  background: var(--bg);
}

/* ===== Arvore de pastas (estilo navegador lateral) ===== */
.folder-tree {
  background: var(--surface);
  border-radius: var(--radius);
}

.folder-tree-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.folder-tree-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.folder-tree-list ul {
  list-style: none;
  margin: 0;
}

.folder-tree-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.15rem;
}

.folder-tree-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--fg);
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
}

.folder-tree-btn:hover {
  background: var(--bg);
}

.folder-tree-btn.selected {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.folder-tree-btn svg {
  flex-shrink: 0;
  opacity: 0.8;
}

.folder-tree-del {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.folder-tree-del:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ===== Flash messages (toast) - tematizadas, ao contrario do alert() nativo ===== */
#toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 320px;
}

.toast {
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  background: var(--success-soft);
  color: var(--success);
  animation: toast-in 0.18s ease;
}

.toast-error {
  background: var(--danger-soft);
  color: var(--danger);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== Responsivo (celulares/telas estreitas) ===== */
.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  margin-right: auto;
  position: relative;
  z-index: 60;
}

@media (max-width: 860px) {
  .menu-toggle {
    display: inline-flex;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 30% 0 0;
    height: 100vh;
    width: auto;
    max-width: 280px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow);
  }

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

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 40;
  }

  .sidebar-backdrop.open {
    display: block;
  }

  .app-content {
    width: 100%;
  }

  header.topbar-light {
    justify-content: flex-start;
    padding: 0.7rem 1rem;
  }

  .topbar-user {
    margin-left: auto;
    text-align: right;
  }

  main {
    padding: 1.1rem 1rem 2rem;
  }

  h1 {
    font-size: 1.3rem;
  }

  .grid-2,
  .grid-sidebar {
    grid-template-columns: 1fr;
  }

  .steps {
    flex-direction: column;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .row {
    flex-wrap: wrap;
  }

  .action-toolbar {
    width: 100%;
  }
}

/* ============================
   FOOTER
   ============================ */
.app-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: auto;
}

.app-footer a {
  color: var(--muted);
  text-decoration: none;
}

.app-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

@media print {
  .app-footer {
    display: none;
  }
}
