/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-width: 240px;
  --sidebar-min: 60px;
  --sidebar-max: 400px;
  --topbar-height: 56px;
  --color-bg: #f0f2f5;
  --color-surface: #ffffff;
  --color-sidebar-bg: #1e293b;
  --color-sidebar-hover: #334155;
  --color-sidebar-active: #3b82f6;
  --color-topbar-bg: #ffffff;
  --color-text: #1a1a2e;
  --color-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
  --color-badge: #ef4444;
}

body {
  font-family: var(--font-family, system-ui, -apple-system, sans-serif);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
}

/* ══════════════════════════════
   APP LAYOUT
══════════════════════════════ */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-min);
  max-width: var(--sidebar-max);
  background: var(--color-sidebar-bg);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: relative;
  transition: width 0.1s ease;
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-min) !important;
}

.sidebar-header {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}

.sidebar-logo {
  font-weight: 700;
  font-size: 1.1rem;
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.15s;
}

.sidebar.collapsed .sidebar-logo { opacity: 0; }

/* Nav items */
.sidebar-nav {
  padding: .75rem 0;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1rem;
  color: var(--color-sidebar-text, #94a3b8);
  text-decoration: none;
  font-size: .9rem;
  font-weight: var(--menu-font-weight, normal);
  font-style: var(--menu-font-style, normal);
  white-space: nowrap;
  transition: background .15s, color .15s;
  border-radius: 0;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-item:hover {
  background: var(--color-sidebar-hover);
  color: #f8fafc;
}

.nav-item.active {
  background: var(--color-sidebar-active);
  color: #fff;
}

.nav-label {
  opacity: 1;
  transition: opacity 0.15s;
  overflow: hidden;
}

.sidebar.collapsed .nav-label { opacity: 0; width: 0; }

/* Resize handle */
.sidebar-resize {
  position: absolute;
  top: 0;
  right: 0;
  width: 4px;
  height: 100%;
  cursor: col-resize;
  background: transparent;
  transition: background 0.15s;
  z-index: 10;
}

.sidebar-resize:hover,
.sidebar-resize.dragging {
  background: var(--color-primary);
}

/* ── Main area ── */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-height);
  background: var(--color-topbar-bg);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  flex-shrink: 0;
  gap: 1rem;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: .25rem;
}

.sidebar-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: .4rem;
  border-radius: 6px;
  color: var(--color-muted);
  display: flex;
  align-items: center;
  transition: background .15s, color .15s;
}

.sidebar-toggle:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.sidebar-toggle svg { width: 20px; height: 20px; }

/* Topbar icon buttons */
.topbar-icon {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  padding: .45rem;
  border-radius: 8px;
  color: var(--color-muted);
  display: flex;
  align-items: center;
  transition: background .15s, color .15s;
}

.topbar-icon:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.topbar-icon svg { width: 20px; height: 20px; }

.topbar-icon.has-badge::after {
  content: attr(data-badge);
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--color-badge);
  color: #fff;
  font-size: .6rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
  pointer-events: none;
}

/* User area */
.topbar-user {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-left: .5rem;
  padding-left: .75rem;
  border-left: 1px solid var(--color-border);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: .8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-email {
  font-size: .875rem;
  color: var(--color-text);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  background: none;
  border: none;
  cursor: pointer;
  padding: .35rem;
  border-radius: 6px;
  color: var(--color-muted);
  display: flex;
  align-items: center;
  transition: background .15s, color .15s;
}

.btn-logout:hover {
  background: #fef2f2;
  color: #b91c1c;
}

.btn-logout svg { width: 18px; height: 18px; }

/* ── Main content ── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem;
}

.main-content h2 {
  font-size: 1.4rem;
  margin-bottom: .75rem;
}

/* ══════════════════════════════
   LOGIN PAGE
══════════════════════════════ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--color-bg);
}

.login-container {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 16px rgba(0,0,0,.08);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
}

.login-container h1 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  text-align: center;
}

/* ── Forms ── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  margin-bottom: 1rem;
}

.form-group label {
  font-size: .875rem;
  font-weight: 500;
  color: #444;
}

.form-group input {
  padding: .55rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: .95rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.form-group input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

/* ── Buttons ── */
.btn {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  font-size: .95rem;
  font-weight: 500;
  padding: .6rem 1.2rem;
  transition: background .15s;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  width: 100%;
  margin-top: .5rem;
}

.btn-primary:hover { background: var(--color-primary-hover); }

/* ── Alerts ── */
.alert {
  border-radius: 6px;
  font-size: .875rem;
  padding: .65rem .9rem;
  margin-bottom: 1rem;
}

.alert-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
}

/* ══════════════════════════════
   SIDEBAR LOGO
══════════════════════════════ */
.sidebar-logo-img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex-shrink: 0;
  margin-right: .5rem;
  border-radius: 4px;
}

.sidebar.collapsed .sidebar-logo-img { margin-right: 0; }

.sidebar-section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: .5rem 1rem .25rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--color-sidebar-text, #94a3b8);
  opacity: .7;
  transition: color .15s, opacity .15s;
}

.sidebar-section-toggle:hover { opacity: 1; }

.section-chevron {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  transition: transform .2s ease;
  opacity: .6;
}

.sidebar-section-toggle.collapsed .section-chevron {
  transform: rotate(-90deg);
}

.sidebar.collapsed .section-chevron { display: none; }

.sidebar-section-items {
  overflow: hidden;
  transition: max-height .25s ease;
  max-height: 600px;
}

.sidebar-section-items.collapsed {
  max-height: 0;
}

.sidebar-admin {
  border-top: 1px solid rgba(255,255,255,.06);
  padding-top: .5rem;
}

/* ══════════════════════════════
   CARDS
══════════════════════════════ */
.card {
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  color: var(--color-text);
}

/* ══════════════════════════════
   PAGE HEADER
══════════════════════════════ */
.page-header {
  margin-bottom: 1.5rem;
}

.page-header h2 {
  font-size: 1.4rem;
}

/* ══════════════════════════════
   SETTINGS FORM
══════════════════════════════ */
.settings-form .form-group { margin-bottom: 1.1rem; }

.field-hint {
  font-size: .78rem;
  color: var(--color-muted);
  margin-top: .3rem;
  display: block;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.25rem;
}

.color-input-wrap {
  display: flex;
  align-items: center;
  gap: .6rem;
}

.color-input-wrap input[type="color"] {
  width: 40px;
  height: 38px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 2px;
  cursor: pointer;
  background: none;
  flex-shrink: 0;
}

.color-input-wrap input[type="text"] {
  width: 100px;
  padding: .45rem .6rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: .9rem;
  font-family: monospace;
}

.logo-preview {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: .75rem;
}

.logo-preview img {
  height: 48px;
  max-width: 120px;
  object-fit: contain;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 4px;
  background: #f9fafb;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
}

/* ── Font style toggles ── */
.font-toggle-group {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

.font-toggle-btn {
  padding: .4rem .85rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: #fff;
  color: #374151;
  font-size: .95rem;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  line-height: 1.4;
}

.font-toggle-btn:hover { background: #f3f4f6; }
.font-toggle-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

/* ── Alert success ── */
.alert-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #15803d;
}

/* ── Button variants ── */
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }

.btn-danger-outline {
  background: transparent;
  border: 1px solid #fca5a5;
  color: #b91c1c;
}

.btn-danger-outline:hover { background: #fef2f2; }

/* ══════════════════════════════
   DATA TABLE
══════════════════════════════ */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.data-table th {
  background: #f8fafc;
  border-bottom: 1px solid var(--color-border);
  padding: .75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: #374151;
  white-space: nowrap;
}

.data-table td {
  padding: .75rem 1rem;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fafafa; }

.text-center { text-align: center; }

/* Ações */
.actions { display: flex; gap: .4rem; align-items: center; }

.btn-action {
  font-size: .78rem;
  padding: .25rem .6rem;
  border-radius: 5px;
  border: 1px solid var(--color-border);
  background: #fff;
  color: #374151;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background .15s;
}

.btn-action:hover { background: #f3f4f6; }
.btn-action.danger { color: #b91c1c; border-color: #fca5a5; }
.btn-action.danger:hover { background: #fef2f2; }

/* Badge */
.badge {
  display: inline-block;
  padding: .2rem .55rem;
  background: #eff6ff;
  color: #1d4ed8;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .03em;
}

/* Select */
select {
  padding: .55rem .75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: .95rem;
  outline: none;
  background: #fff;
  width: 100%;
  transition: border-color .15s;
}

select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

/* btn-outline */
.btn-outline {
  background: transparent;
  border: 1px solid var(--color-border);
  color: #374151;
  padding: .55rem 1.2rem;
  border-radius: 6px;
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-block;
  transition: background .15s;
}

.btn-outline:hover { background: #f3f4f6; }

/* ══════════════════════════════
   MATRIX TABLE (menus & perfis)
══════════════════════════════ */
.matrix-table th,
.matrix-table td { padding: .65rem .9rem; }

.matrix-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--color-primary);
}

/* ══════════════════════════════
   NESTED NAV (menus pai/filho)
══════════════════════════════ */
.nav-parent { display: flex; flex-direction: column; }

.nav-parent-toggle {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1rem;
  color: var(--color-sidebar-text, #94a3b8);
  background: none;
  border: none;
  cursor: pointer;
  font-size: .9rem;
  font-weight: var(--menu-font-weight, normal);
  font-style: var(--menu-font-style, normal);
  white-space: nowrap;
  width: 100%;
  text-align: left;
  transition: background .15s, color .15s;
}

.nav-parent-toggle:hover {
  background: var(--color-sidebar-hover);
  color: #f8fafc;
}

.nav-parent-toggle.open {
  color: #f8fafc;
}

.nav-parent-toggle svg:first-child {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-parent-toggle .chevron {
  width: 16px;
  height: 16px;
  margin-left: auto;
  flex-shrink: 0;
  transition: transform .2s ease;
}

.nav-parent-toggle.open .chevron {
  transform: rotate(90deg);
}

.sidebar.collapsed .nav-parent-toggle .chevron { display: none; }

.nav-children {
  display: none;
  flex-direction: column;
  background: rgba(0,0,0,.15);
}

.nav-children.open { display: flex; }

.nav-item-child {
  padding-left: 2.75rem;
  font-size: .85rem;
}

/* ══════════════════════════════
   SIDEBAR SCROLL
══════════════════════════════ */
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

.sidebar-section {
  border-top: 1px solid rgba(255,255,255,.06);
  padding-top: .5rem;
  margin-top: .25rem;
}

/* ══════════════════════════════
   PLACEHOLDER PAGE
══════════════════════════════ */
.placeholder-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 4rem 2rem;
  color: #9ca3af;
}

.placeholder-page svg {
  width: 56px;
  height: 56px;
  opacity: .4;
}

.placeholder-page p {
  font-size: 1rem;
  font-weight: 500;
}
