:root {
  --bg: #f3f7f7;
  --ink: #122127;
  --muted: #5d6b70;
  --brand: #0e8f83;
  --brand-strong: #096b62;
  --line: rgba(18, 33, 39, 0.1);
  --shadow: 0 20px 45px rgba(9, 41, 49, 0.12);
  --card: #ffffff;
  --danger: #c0392b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Manrope', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 5%, rgba(14, 143, 131, 0.15), transparent 28%),
    radial-gradient(circle at 95% 10%, rgba(238, 127, 59, 0.12), transparent 24%),
    linear-gradient(180deg, #f8fbfb 0%, var(--bg) 75%);
  min-height: 100vh;
  overflow-x: hidden;
}

.shell { width: min(1200px, 96%); margin: 0 auto; }

header {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(10px);
  background: rgba(248, 251, 251, 0.85);
  border-bottom: 1px solid var(--line);
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 14px 0;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: start;
  text-decoration: none;
  color: var(--ink);
  font-family: 'Sora', sans-serif;
  font-weight: 700;
}

.brand-badge {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--brand), #0fb8a9);
  color: #fff;
  font-weight: 800;
  font-size: 0.88rem;
}

nav {
  display: flex;
  align-items: center;
  justify-self: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: hidden;
}

nav a {
  text-decoration: none;
  color: var(--muted);
  padding: 8px 13px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.2s, color 0.2s;
}

nav a:hover,
nav a.active {
  background: rgba(14, 143, 131, 0.13);
  color: var(--brand-strong);
}

.user-area {
  display: flex;
  justify-self: end;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  position: relative;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px 7px 9px;
  background: var(--card);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  max-width: 280px;
  display: inline-flex;
  align-items: baseline;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip span strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.user-chip span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-trigger {
  border: 1px solid var(--line);
  cursor: pointer;
  font-family: 'Manrope', sans-serif;
  text-align: left;
}

.user-menu-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 48px;
  width: min(420px, calc(100vw - 26px));
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
  padding: 14px;
  box-shadow: 0 20px 48px rgba(8, 37, 44, 0.18);
  z-index: 70;
  display: none;
}

.user-menu-panel.open {
  display: block;
}

.subscription-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.subscription-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.4px;
}

.subscription-top h2 {
  font-family: 'Sora', sans-serif;
  font-size: 1.05rem;
}

.subscription-status {
  background: rgba(238, 127, 59, 0.16);
  color: #8b3a18;
  font-size: 0.76rem;
  font-weight: 800;
  border-radius: 999px;
  padding: 5px 10px;
}

.subscription-status.is-active {
  background: rgba(14, 143, 131, 0.16);
  color: #0a6a5f;
}

.subscription-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.sub-item {
  background: rgba(14, 143, 131, 0.06);
  border: 1px solid rgba(14, 143, 131, 0.16);
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 4px;
}

.sub-item span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.35px;
}

.sub-item strong {
  color: #173a42;
  font-size: 0.93rem;
}

.sub-item-name-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.sub-item-name-wrapper strong {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-edit-name {
  background: none;
  border: none;
  padding: 2px 4px;
  cursor: pointer;
  font-size: 0.9rem;
  opacity: 0.7;
  transition: opacity 0.2s;
  min-width: auto;
  min-height: auto;
  flex-shrink: 0;
}

.sub-item:hover .btn-edit-name {
  opacity: 1;
}

.btn-edit-name:hover {
  filter: brightness(1.2);
}

.subscription-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 12px;
}

.subscription-actions select,
.subscription-actions input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-family: 'Manrope', sans-serif;
  outline: none;
  background: #fafcfc;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.subscription-actions select:focus,
.subscription-actions input:focus {
  border-color: rgba(14, 143, 131, 0.55);
  box-shadow: 0 0 0 4px rgba(14, 143, 131, 0.12);
}

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--brand), #0fb8a9);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
}

.btn-logout {
  border: 1px solid rgba(192, 57, 43, 0.55);
  background: rgba(192, 57, 43, 0.13);
  color: var(--danger);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.btn-logout:hover { background: rgba(192, 57, 43, 0.22); border-color: rgba(192, 57, 43, 0.8); }

main { padding: 36px 0 64px; }

.hero {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 800;
  font-size: 0.75rem;
  color: var(--brand-strong);
  background: rgba(14, 143, 131, 0.14);
  margin-bottom: 8px;
}

.hero h1 {
  font-family: 'Sora', sans-serif;
  font-size: 1.62rem;
  margin-bottom: 8px;
}

.hero p {
  color: var(--muted);
  max-width: 760px;
  line-height: 1.55;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.kpi {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  padding: 16px;
  box-shadow: 0 4px 14px rgba(8, 37, 44, 0.06);
  position: relative;
  overflow: hidden;
}

.kpi::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand), #0fb8a9);
}

.kpi-label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 8px;
}

.kpi-value {
  font-family: 'Sora', sans-serif;
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--ink);
  line-height: 1;
  margin-bottom: 4px;
}

.kpi-sub {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.search-wrap {
  flex: 1;
  min-width: 220px;
  position: relative;
}

.search-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px 10px 38px;
  font-size: 0.92rem;
  font-family: 'Manrope', sans-serif;
  background: var(--card);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-wrap input:focus {
  border-color: rgba(14, 143, 131, 0.55);
  box-shadow: 0 0 0 4px rgba(14, 143, 131, 0.12);
}

.btn {
  border: 0;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-soft {
  background: rgba(14, 143, 131, 0.1);
  color: var(--brand-strong);
  border: 1px solid rgba(14, 143, 131, 0.25);
}

.btn-main {
  background: linear-gradient(135deg, var(--brand), #0cac9c);
  color: #fff;
  box-shadow: 0 10px 22px rgba(14, 143, 131, 0.28);
}

/* Modal de editar nome (menu de assinatura) */
#editNameModal.modal-overlay:not(.is-hidden) {
  display: flex;
}

#editNameModal .modal {
  background: var(--card);
  border-radius: 22px;
  padding: 28px;
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.22);
  animation: popIn 0.25s ease;
}

#editNameModal .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  font-size: inherit;
  font-weight: inherit;
}

#editNameModal .modal-header h3 {
  font-family: 'Sora', sans-serif;
  font-size: 1.18rem;
  font-weight: 700;
  color: var(--ink);
}

#editNameModal .modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--muted);
  min-width: auto;
  min-height: auto;
}

#editNameModal .modal-body {
  margin-bottom: 20px;
}

#editNameModal .field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

#editNameModal .field label {
  font-size: 0.88rem;
  font-weight: 700;
  color: #1f3840;
}

#editNameModal .field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 0.92rem;
  font-family: 'Manrope', sans-serif;
  outline: none;
  background: #fafcfc;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#editNameModal .field input:focus {
  border-color: rgba(14, 143, 131, 0.55);
  box-shadow: 0 0 0 4px rgba(14, 143, 131, 0.12);
}

#editNameModal .modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

#editNameModal .modal-actions .btn {
  flex: 1;
  min-height: 42px;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.96) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.table-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  min-width: 880px;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.35px;
  color: #1b3d45;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(14, 143, 131, 0.08);
  white-space: nowrap;
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  vertical-align: middle;
}

.td-fornecedor strong,
.td-contato a,
.td-contato span {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.td-contato a,
.td-contato span {
  font-size: 0.86rem;
}

tbody tr:hover { background: rgba(14, 143, 131, 0.05); }
tbody tr:last-child td { border-bottom: 0; }

.empty-state {
  text-align: center;
  padding: 42px 10px;
  color: var(--muted);
  font-size: 0.94rem;
}

.reveal-section {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.55s ease, transform 0.55s ease;
}

.reveal-section.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
  }

  .brand {
    min-width: 0;
  }

  nav {
    justify-self: stretch;
    justify-content: flex-start;
  }

  .user-area {
    gap: 6px;
  }

  .user-chip {
    max-width: 155px;
    padding: 6px 10px 6px 8px;
  }

  .btn-logout {
    padding: 6px 10px;
  }

  .toolbar .toolbar-btn {
    min-width: 126px;
  }
}

@media (max-width: 920px) {
  .topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
  }

  .brand {
    order: 1;
  }

  .user-area {
    order: 2;
    margin-left: auto;
  }

  nav {
    order: 3;
    width: 100%;
    padding-bottom: 2px;
  }

  .toolbar .toolbar-btn {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
  }
}

@media (max-width: 1200px) {
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chip-greeting { display: none; }
  .user-chip { max-width: 180px; }
}

@media (max-width: 768px) {
  .topbar { display: flex; align-items: flex-start; flex-direction: column; }
  .brand {
    width: 100%;
  }
  nav {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  nav a {
    white-space: nowrap;
    flex: 0 0 auto;
  }
  .user-area {
    width: 100%;
    justify-content: space-between;
    margin-left: 0;
  }
  .user-chip {
    max-width: 65vw;
  }
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .toolbar > div {
    width: 100%;
  }
  .toolbar .btn,
  .toolbar .btn-new {
    width: 100%;
  }
  .kpi-row { grid-template-columns: 1fr; }

  .user-menu-panel {
    right: 0;
  }
}

@media (max-width: 560px) {
  main { padding: 24px 0 48px; }

  .shell { width: 94%; }

  .hero,
  .kpi,
  .table-card {
    border-radius: 14px;
  }
  .user-chip span {
    display: none;
  }

  .table-wrap {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  table {
    min-width: 760px;
  }

  .modal-content {
    width: min(100%, 420px);
    padding: 18px;
    max-height: calc(100dvh - 20px);
    overflow-y: auto;
  }

  .modal-content input,
  .modal-content select,
  .modal-content textarea {
    font-size: 16px;
  }

  .btn,
  .toolbar .btn,
  .toolbar .btn-new,
  .modal-actions button {
    min-height: 44px;
  }

  .modal-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }

  #editNameModal .modal {
    width: min(100%, 420px);
    padding: 18px;
    max-height: calc(100dvh - 20px);
  }

  #editNameModal .field input {
    font-size: 16px;
  }

  #editNameModal .modal-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }

  #editNameModal .modal-actions .btn {
    width: 100%;
    min-height: 44px;
  }
  .table-actions {
    flex-wrap: wrap;
  }
  .btn-edit,
  .btn-delete {
    flex: 1 1 120px;
  }
}
