:root {
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --text: #1c2733;
  --text-muted: #6b7a8d;
  --border: #e1e6ec;
  --primary: #2f5fdb;
  --primary-dark: #1f47b0;
  --danger: #d1453b;
  --success: #1f9d55;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.08);
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

/* --- Auth / login --- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  background: var(--card-bg);
  padding: 2.5rem 2.5rem 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 360px;
}

.auth-card h1 { margin: 0 0 .25rem; font-size: 1.4rem; }
.auth-card p.subtitle { margin: 0 0 1.5rem; color: var(--text-muted); font-size: .9rem; }

.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .85rem; margin-bottom: .3rem; color: var(--text-muted); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .95rem;
  font-family: inherit;
}
.field textarea { resize: vertical; min-height: 4.5rem; }

button, .btn {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: .6rem 1rem;
  font-size: .9rem;
  background: var(--primary);
  color: #fff;
  transition: background .15s;
}
button:hover, .btn:hover { background: var(--primary-dark); }
button.secondary, .btn.secondary { background: #eef1f6; color: var(--text); }
button.secondary:hover { background: #e2e7ef; }
button.danger { background: var(--danger); }
button:disabled { opacity: .55; cursor: not-allowed; }

.error-msg { color: var(--danger); font-size: .85rem; margin-top: .75rem; min-height: 1.1em; }
.success-msg { color: var(--success); font-size: .85rem; margin-top: .75rem; min-height: 1.1em; }

/* --- App shell --- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 1.5rem;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}
.app-header .brand { font-weight: 700; font-size: 1.15rem; }
.app-header .user-info { display: flex; align-items: center; gap: .9rem; font-size: .85rem; color: var(--text-muted); }
.app-header .role-badge {
  background: #eaf0ff;
  color: var(--primary-dark);
  padding: .15rem .55rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}

main { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card h2 { margin-top: 0; font-size: 1.05rem; }
.inline-form { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.inline-form .field { margin-bottom: 0; }
.muted { color: var(--text-muted); font-size: .85rem; }

/* --- Tabs --- */
.tabs { display: flex; gap: .4rem; margin-bottom: 1.25rem; }
.tab-btn {
  background: none;
  color: var(--text-muted);
  padding: .55rem 1.1rem;
  border-radius: 8px 8px 0 0;
  font-weight: 600;
  font-size: .9rem;
}
.tab-btn:hover { background: #eef1f6; color: var(--text); }
.tab-btn--active, .tab-btn--active:hover {
  background: var(--card-bg);
  color: var(--primary-dark);
  box-shadow: var(--shadow);
}
.tab-panel { display: none; }
.tab-panel--active { display: block; }

/* --- Tables --- */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; }

/* --- Categorias / documentos --- */
.categoria-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.categoria-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .15s;
}
.categoria-card:hover { border-color: var(--primary); }
.categoria-card.selecionada { border-color: var(--primary); }
.categoria-card h3 { margin: 0 0 .35rem; font-size: 1rem; }
.categoria-card p { margin: 0; color: var(--text-muted); font-size: .82rem; }

.doc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .9rem 0;
  border-bottom: 1px solid var(--border);
}
.doc-row:last-child { border-bottom: none; }
.doc-info h4 { margin: 0 0 .2rem; font-size: .95rem; }
.doc-info .doc-meta { color: var(--text-muted); font-size: .78rem; }
.doc-actions { display: flex; gap: .5rem; flex-shrink: 0; }

.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
}
.badge--atual { background: #e6f7ec; color: var(--success); }
.badge--obsoleta { background: #f1f1f1; color: var(--text-muted); }
.badge--inativo { background: #fde8e6; color: var(--danger); }

.version-history { margin-top: .5rem; }
.version-history table { font-size: .85rem; }

.empty-state { color: var(--text-muted); font-size: .9rem; padding: 1.5rem 0; text-align: center; }
