/* ══════════════════════════════════════════════════════════════
   MAVI v3.0 Design System
   CSS Custom Properties + Shell Layout + Base Typography
   ══════════════════════════════════════════════════════════════ */

/* ── Design Tokens ── */
:root {
  /* Colors — Core (D-01) */
  --color-bg: #F8FAFC;
  --color-card: #FFFFFF;
  --color-primary: #2563EB;
  --color-primary-hover: #1D4ED8;
  --color-primary-light: #EFF6FF;
  --color-text: #1E293B;
  --color-muted: #64748B;
  --color-border: #E2E8F0;

  /* Colors — Semantic (D-03) */
  --color-success: #10B981;
  --color-success-light: #ECFDF5;
  --color-warning: #F59E0B;
  --color-warning-light: #FFFBEB;
  --color-danger: #DC2626;
  --color-danger-light: #FEF2F2;
  --color-info: #3B82F6;
  --color-info-light: #EFF6FF;

  /* Gradients (D-02) */
  --gradient-header: linear-gradient(135deg, #0F172A 0%, #1E3A5F 50%, #164E63 100%);
  --gradient-kpi: linear-gradient(135deg, #0D9488 0%, #2563EB 100%);

  /* Spacing Scale (4px base) */
  --space-4: 4px;
  --space-8: 8px;
  --space-12: 12px;
  --space-16: 16px;
  --space-24: 24px;
  --space-32: 32px;
  --space-48: 48px;
  --space-64: 64px;
  --border-offset: 2px;

  /* Typography */
  --font-heading: 'Figtree', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --text-xl: 24px;
  --text-2xl: 32px;

  /* Layout */
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --content-max-width: 1200px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --radius-pill: 20px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);

  /* Z-index */
  --z-sidebar: 50;
  --z-topbar: 100;
  --z-dropdown: 200;
  --z-modal-overlay: 1000;
  --z-modal: 1010;
  --z-toast: 9999;

  /* Safe areas (mobile) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  /* Reset legacy style.css body { padding-left: 220px } from old fixed-sidebar layout */
  padding-left: 0 !important;
  padding-right: 0 !important;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
}

h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
}

h2 {
  font-size: var(--text-xl);
  font-weight: 700;
}

h3 {
  font-size: var(--text-lg);
  font-weight: 600;
}

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

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

/* ── Shell Layout (CSS Grid) ── */
.mavi-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr;
  min-height: 100vh;
}

/* ── Top Bar ── */
.mavi-topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  height: var(--topbar-height);
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-24);
  gap: var(--space-16);
}

.mavi-topbar__logo {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-primary);
  text-decoration: none;
}

.mavi-topbar__logo:hover {
  text-decoration: none;
}

.mavi-topbar__search-wrapper {
  position: relative;
  flex: 1;
  max-width: 400px;
}

.mavi-topbar__search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-muted);
  font-size: var(--text-sm);
  pointer-events: none;
}

.mavi-topbar__search {
  width: 100%;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0 var(--space-12) 0 36px;
  font-size: var(--text-sm);
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.15s ease;
}

.mavi-topbar__search:focus {
  border-color: var(--color-primary);
}

.mavi-topbar__user {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin-left: auto;
}

.mavi-topbar__notification {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: none;
  cursor: pointer;
  font-size: var(--text-base);
  color: var(--color-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.mavi-topbar__notification:hover {
  background: var(--color-bg);
}

/* ── Sidebar ── */
.mavi-sidebar {
  grid-column: 1;
  grid-row: 2;
  overflow-y: auto;
  border-right: 1px solid var(--color-border);
  background: var(--color-card);
  padding: var(--space-16) 0;
  display: flex;
  flex-direction: column;
}

.mavi-sidebar__nav {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.mavi-sidebar__footer-items {
  margin-top: auto;
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-8);
}

.mavi-sidebar__logo {
  padding: var(--space-16) var(--space-24);
  display: flex;
  flex-direction: column;
}

.mavi-sidebar__category {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  padding: var(--space-24) var(--space-24) var(--space-8);
  line-height: 1;
}

.mavi-sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-8) var(--space-16);
  margin: 0 var(--space-8);
  min-height: 44px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
  text-decoration: none;
  transition: background 0.15s ease;
}

.mavi-sidebar__item:hover {
  background: var(--color-primary-light);
  text-decoration: none;
}

.mavi-sidebar__item--active {
  background: #EFF6FF;
  color: #2563EB;
}

.mavi-sidebar__item--active:hover {
  background: #DBEAFE;
  text-decoration: none;
}

.mavi-sidebar__item i {
  width: 20px;
  text-align: center;
  font-size: var(--text-base);
}

.mavi-sidebar__user {
  padding: var(--space-16) var(--space-24);
  margin-top: auto;
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-12);
}

.mavi-sidebar__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-primary-light);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--text-sm);
  flex-shrink: 0;
}

/* ── Content Area ── */
.mavi-content {
  grid-column: 2;
  grid-row: 2;
  overflow-y: auto;
  padding: var(--space-32);
  background: var(--color-bg);
}

/* ── Page Header (clean, discrete — matches Consultório style) ── */
.mavi-page-header {
  padding: var(--space-16) 0;
  margin-bottom: var(--space-16);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-24);
  flex-wrap: wrap;
}

.mavi-page-header__meta {
  flex: 1;
  min-width: 0;
}

.mavi-page-header__category {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  display: block;
  margin-bottom: var(--space-4);
}

.mavi-page-header__title {
  font-size: var(--text-xl);
  font-weight: 600;
  font-family: var(--font-heading);
  color: var(--color-text);
  margin: 0;
}

.mavi-page-header__subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-top: var(--space-4);
}

/* ── Sidebar Overlay (mobile) ── */
.mavi-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--topbar-height);
  background: rgba(0, 0, 0, 0.5);
  z-index: calc(var(--z-sidebar) - 1);
}

.mavi-sidebar-overlay.visible {
  display: block;
}

/* ── Hamburger Button ── */
.mavi-hamburger {
  display: none;
  width: 44px;
  height: 44px;
  padding: 8px;
  border: none;
  background: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
  font-size: var(--text-lg);
}

/* ── Accessibility ── */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-primary);
  color: #FFFFFF;
  padding: var(--space-8);
  z-index: 10000;
  transition: top 0.2s;
}

.skip-link:focus {
  top: 0;
  color: #FFFFFF;
  text-decoration: none;
}

*:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: var(--border-offset);
}

/* ── Responsive: Mobile / Tablet ── */
@media (max-width: 1023px) {
  .mavi-shell {
    grid-template-columns: 1fr;
  }

  .mavi-sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-height);
    bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.25s ease-out;
    z-index: var(--z-sidebar);
  }

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

  .mavi-content {
    grid-column: 1;
    padding: var(--space-16);
  }

  .mavi-hamburger {
    display: flex;
  }

  .mavi-topbar__search-wrapper {
    display: none;
  }
}

@media (max-width: 767px) {
  .mavi-page-header {
    padding: var(--space-16) var(--space-24);
  }

  .mavi-page-header__title {
    font-size: var(--text-xl);
  }
}

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0s !important;
    animation-duration: 0s !important;
  }
}
