:root {
  --bg: #060811;
  --bg-2: #0b1020;
  --surface: #101526;
  --surface-2: #161d33;
  --border: #212a42;
  --border-light: #2c3654;
  --text: #edf0f8;
  --text-muted: #8b93ab;
  --text-faint: #565f7c;
  --accent: #3d6cf0;
  --accent-2: #142766;
  --accent-soft: rgba(61, 108, 240, 0.14);
  --accent-glow: rgba(61, 108, 240, 0.28);
  --success: #2fb571;
  --warning: #d9a441;
  --danger: #e2586b;

  --sidebar-w: 232px;
  --sidebar-w-collapsed: 72px;
}

* { box-sizing: border-box; }

html.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }

body {
  margin: 0;
  background:
    radial-gradient(1100px 640px at 20% -12%, rgba(61, 108, 240, 0.16), transparent 60%),
    radial-gradient(900px 560px at 100% 10%, rgba(20, 39, 102, 0.35), transparent 55%),
    radial-gradient(700px 500px at 50% 100%, rgba(61, 108, 240, 0.06), transparent 60%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Inter, Arial, sans-serif;
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #6b93f5; }

h1 {
  font-size: 1.5rem;
  margin: 0 0 1.5rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

h2 {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 2.25rem 0 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(190deg, #0d1224 0%, #080b16 100%);
  border-right: 1px solid var(--border);
  padding: 1.4rem 0.9rem;
  display: flex;
  flex-direction: column;
  transition: width 0.32s cubic-bezier(0.65, 0, 0.35, 1);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}

nav a .label, .logout-link .label, .brand-name {
  transition: opacity 0.15s ease 0.08s, max-width 0.32s cubic-bezier(0.65, 0, 0.35, 1);
  max-width: 160px;
  overflow: hidden;
}

.sidebar-collapsed nav a .label,
.sidebar-collapsed .logout-link .label {
  opacity: 0;
  max-width: 0;
  transition: opacity 0.05s ease, max-width 0.32s cubic-bezier(0.65, 0, 0.35, 1);
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.35rem 1.5rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
}

.brand-logo {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(61, 108, 240, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.sidebar-collapsed .brand-logo { transform: scale(1.08); }

.brand-mark {
  background: linear-gradient(120deg, #7ea3ff, #3d6cf0 70%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: 0.02em;
}
.brand-name {
  color: var(--text);
  opacity: 1;
  transition: opacity 0.15s ease;
}
.sidebar-collapsed .brand-name { display: none; }

.sidebar-toggle {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}

.sidebar-toggle:hover { background: var(--surface-2); color: var(--text); }
.sidebar-toggle .chevron { display: inline-block; transition: transform 0.32s cubic-bezier(0.65, 0, 0.35, 1); }
.sidebar-collapsed .sidebar-toggle .chevron { transform: rotate(180deg); }
.sidebar-collapsed .sidebar-top { justify-content: center; padding: 0 0 1.5rem; }
.sidebar-collapsed .brand { display: none; }

nav { display: flex; flex-direction: column; gap: 0.2rem; margin-top: 0.25rem; }
nav.nav-secondary {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

nav a, .logout-link {
  color: var(--text-muted);
  padding: 0.6rem 0.65rem;
  border-radius: 9px;
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  white-space: nowrap;
  position: relative;
}

nav a .icon, .logout-link .icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}

nav a .icon svg, .logout-link .icon svg {
  width: 18px;
  height: 18px;
}

nav a:hover, .logout-link:hover {
  background: var(--surface-2);
  color: var(--text);
}

nav a.active {
  background: linear-gradient(90deg, var(--accent-soft), transparent);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--accent);
}

nav a.nav-cta,
nav a.nav-cta.active {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(61, 108, 240, 0.3);
}

nav a.nav-cta:hover {
  background: #3d6ce0;
  color: #fff;
}

nav a.nav-cta .icon {
  color: #fff;
  opacity: 1;
  font-weight: 700;
  font-size: 1.15rem;
}

.sidebar-collapsed nav a,
.sidebar-collapsed .logout-link {
  justify-content: center;
  padding: 0.6rem 0;
}

/* tooltip quando colapsada */
.sidebar-collapsed nav a::after,
.sidebar-collapsed .logout-link::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  color: var(--text);
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  font-size: 0.78rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s ease;
  z-index: 20;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.sidebar-collapsed nav a:hover::after,
.sidebar-collapsed .logout-link:hover::after {
  opacity: 1;
}

.main {
  flex: 1;
  padding: 2.5rem 3.5rem 3rem;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  animation: page-fade-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes page-fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.stat-card, table, .card {
  animation: page-fade-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.stat-card { transition: transform 0.2s ease, box-shadow 0.2s ease; }
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 14px 30px rgba(0, 0, 0, 0.25); }

.anniversary-banner {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(160deg, var(--surface) 0%, #0c1120 100%);
  padding: 1.1rem 1.4rem;
  margin: 1.1rem 0 0.5rem;
  animation: page-fade-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.anniversary-banner.has-events {
  border-color: rgba(217, 164, 65, 0.45);
  background: linear-gradient(160deg, rgba(217, 164, 65, 0.12), var(--surface) 55%);
  box-shadow: 0 0 0 1px rgba(217, 164, 65, 0.15), 0 14px 30px rgba(217, 164, 65, 0.08);
}

.anniversary-line {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text);
}

.anniversary-line + .anniversary-line { margin-top: 0.5rem; }
.anniversary-line strong { color: var(--warning); }
.anniversary-line.muted {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.9rem;
}

.flashes { list-style: none; padding: 0; margin: 0 0 1.25rem; }
.flashes li {
  background: var(--accent-soft);
  border: 1px solid var(--border-light);
  color: var(--text);
  padding: 0.65rem 1rem;
  border-radius: 9px;
  margin-bottom: 0.5rem;
  font-size: 0.88rem;
}

/* ---- cards de indicador ---- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.1rem;
  margin-bottom: 0.5rem;
}

.stat-card {
  position: relative;
  background: linear-gradient(160deg, var(--surface) 0%, #0c1120 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.3rem 1.4rem;
  overflow: hidden;
}

.stat-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(140px 90px at 100% 0%, var(--accent-glow), transparent 70%);
  opacity: 0.55;
  pointer-events: none;
}

.stat-card .stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.stat-card .label {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.stat-card .icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent-soft);
  border: 1px solid rgba(61, 108, 240, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.stat-card .value {
  font-size: 1.85rem;
  font-weight: 800;
  margin-top: 0.45rem;
  letter-spacing: -0.015em;
  position: relative;
}

/* mini sparkline decorativo */
.sparkline {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 24px;
  margin-top: 0.95rem;
  position: relative;
}

.sparkline .bar {
  flex: 1;
  border-radius: 2px 2px 0 0;
  background: var(--border-light);
}

.sparkline .bar:last-child {
  background: linear-gradient(180deg, #7ea3ff, var(--accent));
}

/* ---- tabelas ---- */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: linear-gradient(160deg, var(--surface) 0%, #0c1120 100%);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

th, td {
  text-align: left;
  padding: 0.7rem 1.1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}

th {
  color: var(--text-faint);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.015);
}

tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

.empty-row td { color: var(--text-faint); text-align: center; padding: 1.6rem; font-size: 0.85rem; }

/* ---- badges (ponto + texto) ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
}

.badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge-success .dot { background: var(--success); box-shadow: 0 0 6px rgba(47, 181, 113, 0.6); }
.badge-warning .dot { background: var(--warning); box-shadow: 0 0 6px rgba(217, 164, 65, 0.6); }
.badge-danger .dot { background: var(--danger); box-shadow: 0 0 6px rgba(226, 88, 107, 0.6); }
.badge-neutral .dot { background: var(--text-faint); }

/* ---- botões ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: linear-gradient(135deg, #5686f5, var(--accent));
  color: #fff;
  border: none;
  padding: 0.6rem 1.15rem;
  border-radius: 9px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
  box-shadow: 0 6px 16px rgba(61, 108, 240, 0.25);
}

.btn:hover { color: #fff; transform: translateY(-1px); box-shadow: 0 8px 20px rgba(61, 108, 240, 0.35); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  box-shadow: none;
}

.btn-ghost:hover { background: var(--surface-2); color: var(--text); transform: none; box-shadow: none; }

.actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.4rem;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ---- filtros de busca ---- */
.filter-bar {
  display: flex;
  gap: 0.6rem;
  flex: 1;
}

.filter-bar input[type="text"],
.filter-bar select {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  color: var(--text);
  padding: 0.5rem 0.75rem;
  font-size: 0.86rem;
}

.filter-bar input[type="text"] {
  flex: 1;
  min-width: 180px;
  max-width: 280px;
}

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

/* ---- formulários ---- */
.card {
  background: linear-gradient(160deg, var(--surface) 0%, #0c1120 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.85rem;
  max-width: 460px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.field { margin-bottom: 1rem; }

.field label {
  display: block;
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-bottom: 0.35rem;
  font-weight: 500;
}

.field input,
.field select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  color: var(--text);
  padding: 0.6rem 0.75rem;
  font-size: 0.88rem;
  font-family: inherit;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61, 108, 240, 0.15);
}

/* ---- login ---- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(900px 560px at 20% 10%, rgba(61, 108, 240, 0.14), transparent 60%),
    radial-gradient(700px 500px at 85% 90%, rgba(20, 39, 102, 0.3), transparent 60%);
}

@keyframes login-rise {
  from { opacity: 0; transform: translateY(18px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes login-glow {
  from { box-shadow: 0 0 0 rgba(61, 108, 240, 0); }
  to { box-shadow: 0 30px 70px rgba(61, 108, 240, 0.18); }
}

.login-card {
  width: 100%;
  max-width: 350px;
  animation: login-rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) both,
             login-glow 0.9s ease-out 0.2s both;
}

.login-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 1.1rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 26px rgba(61, 108, 240, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  animation: login-rise 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
  overflow: hidden;
}

.login-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.login-card h1 {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
}

.login-card .brand-accent {
  background: linear-gradient(120deg, #7ea3ff, #3d6cf0 70%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.login-card .btn { width: 100%; justify-content: center; margin-top: 0.25rem; }

/* ---- layout mobile ---- */
@media (max-width: 768px) {
  body { font-size: 15px; }

  .app-shell { flex-direction: column; }

  /* menu lateral vira barra fixa embaixo, só com ícones */
  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    padding: 0.5rem 0.6rem;
    border-right: none;
    border-top: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    z-index: 40;
    transition: none;
  }

  html.sidebar-collapsed .sidebar { width: 100%; }

  .sidebar-top,
  .brand-name,
  nav a .label,
  .logout-link .label,
  .sidebar-collapsed nav a .label,
  .sidebar-collapsed .logout-link .label {
    display: none;
  }

  .sidebar nav {
    flex-direction: row;
    gap: 0.35rem;
    margin: 0;
  }

  nav.nav-secondary {
    margin: 0;
    padding: 0;
    border-top: none;
  }

  .sidebar-bottom {
    margin: 0;
    padding: 0;
    border-top: none;
  }

  nav a, .logout-link {
    padding: 0.55rem;
    justify-content: center;
  }

  /* tooltips de label não funcionam bem no toque, desliga */
  .sidebar nav a::after,
  .sidebar .logout-link::after {
    display: none;
  }

  .main {
    padding: 1.1rem 1rem 5.5rem;
    max-width: 100%;
  }

  /* logo ao lado do título da página, já que a sidebar vira menu inferior */
  .main h1 {
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
  }

  .main h1::before {
    content: "";
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    border-radius: 50%;
    background: url("/static/img/logo.png") center / cover no-repeat;
    box-shadow: 0 2px 8px rgba(61, 108, 240, 0.35);
  }

  .stat-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
  }

  /* card sozinho numa linha ímpar ocupa a largura toda, sem ficar torto */
  .stat-grid > .stat-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .stat-card {
    padding: 0.85rem 0.9rem;
    border-radius: 12px;
  }

  .stat-card .label { font-size: 0.68rem; }
  .stat-card .value { font-size: 1.3rem; margin-top: 0.3rem; }
  .stat-card .icon { width: 26px; height: 26px; font-size: 0.8rem; }
  .stat-card .sparkline { display: none; }

  .actions-bar { flex-direction: column; align-items: stretch; }

  .filter-bar { flex-wrap: wrap; }
  .filter-bar input[type="text"] { max-width: 100%; }

  .card { max-width: 100%; }

  th, td { padding: 0.6rem 0.8rem; font-size: 0.84rem; }

  /* ---- tabelas viram lista de cards no mobile ---- */
  .table-scroll { overflow-x: visible; }

  .table-scroll table.responsive-cards,
  .table-scroll table.responsive-cards thead,
  .table-scroll table.responsive-cards tbody,
  .table-scroll table.responsive-cards tr,
  .table-scroll table.responsive-cards td {
    display: block;
    width: 100%;
  }

  table.responsive-cards thead { display: none; }

  table.responsive-cards tr {
    padding: 0.9rem 1rem;
    margin-bottom: 0.7rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: linear-gradient(160deg, var(--surface) 0%, #0c1120 100%);
  }

  table.responsive-cards tr:last-child { margin-bottom: 0; }

  table.responsive-cards td {
    border-bottom: none;
    padding: 0.3rem 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    text-align: right;
  }

  table.responsive-cards td::before {
    content: attr(data-label);
    color: var(--text-faint);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    text-align: left;
  }

  table.responsive-cards td[data-label="Cliente"] {
    font-weight: 700;
    font-size: 0.98rem;
    padding-bottom: 0.5rem;
    margin-bottom: 0.3rem;
    border-bottom: 1px solid var(--border);
  }

  table.responsive-cards td[data-label="Cliente"]::before { display: none; }

  table.responsive-cards .empty-row td {
    display: block;
    text-align: center;
  }

  table.responsive-cards .empty-row td::before { display: none; }
}

@media (max-width: 420px) {
  .stat-grid { gap: 0.5rem; }
  .stat-card .value { font-size: 1.15rem; }
}
