:root {
  --primary: #2563eb;
  --primary-rgb: 37, 99, 235;
  --bg: #f0f4f8;
  --bg-accent: linear-gradient(135deg, #f0f4f8 0%, #e8eef6 50%, #f4f7fb 100%);
  --surface: #ffffff;
  --surface-2: rgba(255, 255, 255, 0.72);
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(15, 23, 42, 0.08);
  --ring: rgba(var(--primary-rgb), 0.35);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  --bg: #0c0f14;
  --bg-accent: linear-gradient(135deg, #0c0f14 0%, #12161f 40%, #0e1218 100%);
  --surface: #161b26;
  --surface-2: rgba(22, 27, 38, 0.85);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: rgba(241, 245, 249, 0.08);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  background: var(--bg-accent);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Top bar */
.topbar {
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface-2);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.brand:hover {
  text-decoration: none;
  opacity: 0.92;
}

.brand-logo {
  display: block;
  max-height: 88px;
  width: auto;
  max-width: min(320px, 55vw);
  height: auto;
  object-fit: contain;
  object-position: left center;
}

.brand-text {
  font-size: 1.15rem;
  color: var(--primary);
}

@supports (background-clip: text) or (-webkit-background-clip: text) {
  .brand-text {
    background: linear-gradient(120deg, var(--primary), color-mix(in srgb, var(--primary) 70%, #6366f1));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-name {
  font-size: 0.875rem;
  color: var(--muted);
  font-weight: 500;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-greeting {
  font-size: 0.9rem;
  color: var(--text);
  max-width: min(240px, 45vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-greeting strong {
  font-weight: 700;
  color: var(--primary);
}

.welcome-line {
  font-size: 1.15rem;
  margin: 0 0 0.35rem;
  color: var(--muted);
}

.welcome-line strong {
  color: var(--primary);
  font-weight: 700;
}

.login-card-logo-wrap {
  text-align: center;
  margin: 0 0 1.25rem;
}

.login-card-logo {
  display: inline-block;
  max-height: 160px;
  max-width: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.login-title {
  margin-top: 0;
  text-align: center;
}

.main-wrap {
  flex: 1 0 auto;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 3.5rem;
}

/* Login page */
.page-login .main-wrap {
  min-height: calc(100vh - 88px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 2rem;
  padding-bottom: 2rem;
}

.page-login .topbar {
  background: var(--surface);
}

.login-box {
  width: 100%;
  max-width: 420px;
  margin: 0;
}

body.page-login::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(var(--primary-rgb), 0.18), transparent),
    radial-gradient(ellipse 60% 40% at 100% 50%, rgba(99, 102, 241, 0.08), transparent);
  pointer-events: none;
}

html[data-theme="dark"] body.page-login::before {
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(var(--primary-rgb), 0.25), transparent),
    radial-gradient(ellipse 60% 40% at 100% 50%, rgba(99, 102, 241, 0.12), transparent);
}

/* Typography */
h1 {
  font-size: clamp(1.35rem, 2.5vw, 1.65rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0 0 0.5rem;
  line-height: 1.25;
}

h2 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 1rem;
  color: var(--text);
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-header .lead {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 52ch;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--primary);
  line-height: 1;
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.5rem 1.6rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.page-login .card {
  box-shadow: var(--shadow-lg);
  padding: 2rem 1.75rem;
}

.page-login .login-box .muted {
  text-align: center;
}

.card h2:first-child {
  margin-top: 0;
}

/* Alerts */
.alert {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.9rem;
  border: 1px solid transparent;
}

.alert-error {
  background: color-mix(in srgb, #ef4444 12%, transparent);
  color: #b91c1c;
  border-color: color-mix(in srgb, #ef4444 25%, transparent);
}

[data-theme="dark"] .alert-error {
  background: rgba(127, 29, 29, 0.35);
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.25);
}

.alert-success {
  background: color-mix(in srgb, #22c55e 12%, transparent);
  color: #166534;
  border-color: color-mix(in srgb, #22c55e 28%, transparent);
}

[data-theme="dark"] .alert-success {
  background: rgba(20, 83, 45, 0.4);
  color: #bbf7d0;
  border-color: rgba(74, 222, 128, 0.2);
}

/* Forms */
.form-group {
  margin-bottom: 1.1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="url"],
.form-group select,
.form-group input[type="file"] {
  width: 100%;
  max-width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

.form-group input[type="color"] {
  max-width: 120px;
  height: 44px;
  padding: 4px;
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.15rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.35);
  transition: transform 0.12s, filter 0.12s, box-shadow 0.12s;
}

.btn:hover {
  filter: brightness(1.06);
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(var(--primary-rgb), 0.4);
}

.btn:active {
  transform: scale(0.98);
}

.btn-sm {
  padding: 0.45rem 0.95rem;
  font-size: 0.85rem;
}

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
  box-shadow: none;
}

.btn-ghost:hover {
  background: color-mix(in srgb, var(--primary) 8%, transparent);
  box-shadow: none;
}

.btn-danger {
  background: #dc2626;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.35);
}

.btn-danger:hover {
  filter: brightness(1.08);
}

.btn-theme {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  transition: background 0.15s, transform 0.12s;
}

.btn-theme:hover {
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
}

/* Admin layout */
.layout-admin {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1.75rem;
  align-items: start;
}

@media (max-width: 900px) {
  .layout-admin {
    grid-template-columns: 1fr;
  }
}

.side-nav {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 88px;
}

@media (max-width: 900px) {
  .side-nav {
    position: static;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.35rem;
  }

  .side-nav-title {
    grid-column: 1 / -1;
  }
}

.side-nav-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0.35rem 0.65rem 0.5rem;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
  font-size: 0.92rem;
  margin-bottom: 0.2rem;
  transition: background 0.15s, color 0.15s;
}

.side-link:hover {
  text-decoration: none;
  background: color-mix(in srgb, var(--primary) 8%, transparent);
  color: var(--primary);
}

.side-link.active {
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  color: var(--primary);
  font-weight: 600;
}

.side-icon {
  flex-shrink: 0;
  opacity: 0.9;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-top: 0.5rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th,
td {
  text-align: left;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: color-mix(in srgb, var(--muted) 6%, transparent);
}

tr:last-child td {
  border-bottom: none;
}

tbody tr {
  transition: background 0.12s;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--primary) 4%, transparent);
}

td .btn {
  margin: 0.15rem 0.2rem 0.15rem 0;
}

.th-actions,
.td-actions {
  min-width: 200px;
  white-space: nowrap;
}

.td-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.form-edit-title {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
}

@media (min-width: 640px) {
  .form-edit-title {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
}

.input-inline {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}

.input-inline:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}

.form-inline-delete {
  display: inline;
}

/* Document list (member) */
.doc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.doc-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.1rem;
  margin-bottom: 0.65rem;
  background: color-mix(in srgb, var(--muted) 5%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.doc-list li:hover {
  border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
  box-shadow: var(--shadow-sm);
}

.doc-list li:last-child {
  margin-bottom: 0;
}

.doc-list strong {
  font-weight: 600;
  font-size: 1rem;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.preview-logo {
  max-height: 72px;
  width: auto;
  max-width: 100%;
  display: block;
  margin: 0.5rem 0;
  object-fit: contain;
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  background: color-mix(in srgb, var(--muted) 8%, transparent);
}

/* Rodapé */
.site-footer {
  flex-shrink: 0;
  margin-top: auto;
  padding: 1.25rem 1.5rem 1.75rem;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
}

[data-theme="dark"] .site-footer {
  background: color-mix(in srgb, var(--surface) 70%, transparent);
}

.site-footer-inner {
  max-width: 1180px;
  margin: 0 auto;
  text-align: center;
}

.site-footer-text {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.site-footer-name {
  font-weight: 600;
  color: var(--text);
}

.site-footer-sep {
  margin: 0 0.35rem;
  opacity: 0.5;
}

.site-footer-link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.site-footer-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Primary color: sync RGB for shadows when set inline on html */
html[style*="--primary"] {
  --primary-rgb: 37, 99, 235;
}
