:root{
  --bg:#071019;
  --bg-2:#0b1620;
  --sidebar:#0a131d;
  --card:#101b26;
  --card-2:#14212e;
  --border:rgba(255,255,255,.08);
  --border-strong:rgba(255,255,255,.14);

  --text:#edf4f9;
  --text-soft:#c7d5e1;
  --muted:#90a4b5;

  --green:#22c55e;
  --green-2:#16a34a;
  --blue:#38bdf8;
  --blue-2:#0ea5e9;
  --orange:#f59e0b;
  --red:#ef4444;

  --green-soft:rgba(34,197,94,.14);
  --blue-soft:rgba(56,189,248,.14);
  --orange-soft:rgba(245,158,11,.14);
  --red-soft:rgba(239,68,68,.14);

  --radius-sm:12px;
  --radius-md:16px;
  --radius-lg:22px;
  --radius-xl:28px;

  --shadow-lg:0 26px 60px rgba(0,0,0,.26);
  --shadow-md:0 14px 34px rgba(0,0,0,.18);
  --shadow-sm:0 8px 20px rgba(0,0,0,.14);
}

*,
*::before,
*::after{
  box-sizing:border-box;
}

html,
body{
  margin:0;
  padding:0;
  max-width:100%;
  overflow-x:hidden;
}

body{
  font-family:Inter, Arial, sans-serif;
  color:var(--text);
  background:
    radial-gradient(circle at top left, rgba(34,197,94,.06), transparent 20%),
    radial-gradient(circle at top right, rgba(56,189,248,.06), transparent 18%),
    linear-gradient(180deg,#071019 0%, #0b1520 50%, #0d1823 100%);
}

a{
  text-decoration:none;
  color:inherit;
}

img,
svg{
  display:block;
  max-width:100%;
}

button,
input,
select,
textarea{
  font:inherit;
}

/* ===== APP ===== */
.app-shell{
  display:grid;
  grid-template-columns:270px minmax(0,1fr);
  min-height:100vh;
  width:100%;
  overflow-x:hidden;
}

/* ===== SIDEBAR ===== */
.sidebar{
  position:sticky;
  top:0;
  height:100vh;
  padding:20px 16px;
  background:linear-gradient(180deg,#09121b 0%, #0b141d 100%);
  border-right:1px solid var(--border);
  overflow-y:auto;
  overflow-x:hidden;
}

.sidebar-brand{
  padding:10px 10px 18px;
  border-bottom:1px solid var(--border);
  margin-bottom:18px;
}

.brand-mark{
  width:42px;
  height:42px;
  border-radius:14px;
  display:grid;
  place-items:center;
  background:linear-gradient(135deg,var(--green),#0ea5e9);
  color:#fff;
  font-weight:900;
  font-size:16px;
  margin-bottom:12px;
  box-shadow:var(--shadow-sm);
}

.brand-title{
  font-size:28px;
  font-weight:900;
  letter-spacing:-.04em;
  line-height:1;
}

.brand-sub{
  margin-top:6px;
  font-size:13px;
  color:var(--muted);
  line-height:1.5;
}

.sidebar-section{
  margin:18px 10px 10px;
  color:#6f8697;
  font-size:12px;
  font-weight:800;
  text-transform:uppercase;
  letter-spacing:.08em;
}

.sidebar nav{
  display:grid;
  gap:8px;
}

.sidebar nav a{
  display:flex;
  align-items:center;
  gap:12px;
  min-height:48px;
  padding:12px 14px;
  border-radius:14px;
  color:#dce8f1;
  background:rgba(255,255,255,.02);
  border:1px solid transparent;
  transition:.18s ease;
  font-weight:700;
  min-width:0;
}

.sidebar nav a:hover{
  background:rgba(255,255,255,.05);
  border-color:var(--border);
  transform:translateX(2px);
}

.sidebar nav a.active{
  color:#fff;
  background:linear-gradient(135deg, rgba(34,197,94,.16), rgba(34,197,94,.08));
  border-color:rgba(34,197,94,.18);
}

.sidebar .nav-icon{
  width:18px !important;
  height:18px !important;
  min-width:18px !important;
  min-height:18px !important;
  flex:0 0 18px !important;
  opacity:.95;
}

.sidebar-footer{
  margin-top:18px;
  padding-top:18px;
  border-top:1px solid var(--border);
}

.sidebar-user{
  margin-top:14px;
  padding:14px;
  border-radius:16px;
  background:rgba(255,255,255,.03);
  border:1px solid var(--border);
}

.sidebar-user small{
  display:block;
  color:var(--muted);
  margin-bottom:4px;
}

.sidebar-user strong{
  display:block;
  font-size:14px;
}

/* ===== MAIN ===== */
.main-content{
  padding:24px;
  min-width:0;
  width:100%;
  overflow-x:hidden;
}

.topbar{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:16px;
  margin-bottom:20px;
  min-width:0;
}

.topbar-left{
  display:grid;
  gap:8px;
}

.topbar h1{
  margin:0;
  font-size:34px;
  line-height:1.05;
  letter-spacing:-.04em;
}

.topbar small{
  color:var(--muted);
  font-size:14px;
}

.topbar-right{
  display:flex;
  align-items:center;
  gap:12px;
  flex-wrap:wrap;
  justify-content:flex-end;
}

.top-chip{
  padding:10px 12px;
  border-radius:12px;
  background:rgba(255,255,255,.04);
  border:1px solid var(--border);
  color:var(--text-soft);
  font-weight:700;
  font-size:13px;
}

.user-pill{
  display:flex;
  align-items:center;
  gap:12px;
  padding:10px 14px;
  border-radius:16px;
  background:rgba(255,255,255,.04);
  border:1px solid var(--border);
}

.user-avatar{
  width:38px;
  height:38px;
  border-radius:12px;
  display:grid;
  place-items:center;
  background:linear-gradient(135deg,var(--green),#0ea5e9);
  font-weight:900;
  color:#fff;
  flex:0 0 38px;
}

.user-pill strong{
  display:block;
  font-size:14px;
}

.user-pill span{
  display:block;
  font-size:12px;
  color:var(--muted);
}

/* ===== ALERT ===== */
.alert{
  padding:14px 16px;
  border-radius:14px;
  margin-bottom:18px;
  font-weight:600;
}

.alert.success{
  background:rgba(34,197,94,.12);
  border:1px solid rgba(34,197,94,.22);
  color:#dbffe7;
}

.alert.error{
  background:rgba(239,68,68,.12);
  border:1px solid rgba(239,68,68,.22);
  color:#ffd8d8;
}

/* ===== LAYOUT GRID ===== */
.dashboard-grid,
.content-grid,
.stats-grid,
.hero-card,
.panel-card,
.stat-card,
.table-wrap,
.quick-actions,
.finance-stack,
.hero-side{
  min-width:0;
}

.dashboard-grid{
  display:grid;
  gap:18px;
  width:100%;
}

.stats-grid{
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:16px;
  width:100%;
}

.content-grid{
  display:grid;
  gap:18px;
  width:100%;
}

.content-grid.two{
  grid-template-columns:minmax(0,1.18fr) minmax(320px,.82fr);
  align-items:start;
}

.content-grid.equal{
  grid-template-columns:minmax(0,1fr) minmax(0,1fr);
}

/* ===== CARDS ===== */
.panel-card,
.stat-card,
.hero-card{
  background:
    linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.025));
  border:1px solid var(--border);
  border-radius:22px;
  box-shadow:var(--shadow-md);
  width:100%;
  max-width:100%;
}

.panel-card{
  padding:24px;
}

.stat-card{
  padding:22px;
}

.hero-card{
  padding:24px;
  display:grid;
  grid-template-columns:minmax(0,1.2fr) minmax(240px,.8fr);
  gap:18px;
  align-items:start;
}

.panel-head{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:12px;
  margin-bottom:18px;
}

.panel-head h3{
  margin:0;
  font-size:22px;
  line-height:1.08;
  letter-spacing:-.03em;
}

.panel-head p{
  margin:6px 0 0;
  color:var(--muted);
  font-size:14px;
  line-height:1.6;
}

/* ===== BUTTONS ===== */
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:46px;
  padding:12px 16px;
  border-radius:14px;
  border:none;
  cursor:pointer;
  font-weight:800;
  transition:.18s ease;
  max-width:100%;
  text-align:center;
}

.btn:hover{
  transform:translateY(-1px);
}

.btn-primary{
  background:linear-gradient(135deg,var(--green),var(--green-2));
  color:#fff;
  box-shadow:0 10px 24px rgba(34,197,94,.22);
}

.btn-secondary{
  background:linear-gradient(135deg,var(--blue),var(--blue-2));
  color:#fff;
  box-shadow:0 10px 24px rgba(56,189,248,.20);
}

.btn-outline{
  background:rgba(255,255,255,.03);
  border:1px solid var(--border);
  color:#fff;
}

.btn-ghost{
  background:rgba(255,255,255,.03);
  border:1px solid var(--border);
  color:var(--text-soft);
}

/* ===== TABLE ===== */
.table-wrap{
  width:100%;
  max-width:100%;
  overflow-x:auto;
  overflow-y:hidden;
  border:1px solid var(--border);
  border-radius:18px;
  background:rgba(255,255,255,.02);
}

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

th,
td{
  padding:14px;
  border-bottom:1px solid var(--border);
  text-align:left;
  vertical-align:middle;
}

th{
  color:#d3e1eb;
  font-size:12px;
  text-transform:uppercase;
  letter-spacing:.04em;
  white-space:nowrap;
  background:rgba(255,255,255,.02);
}

tbody tr:hover{
  background:rgba(255,255,255,.03);
}

.table-main{
  display:grid;
  gap:4px;
}

.table-main strong{
  font-size:14px;
}

.table-main span{
  font-size:12px;
  color:var(--muted);
}

.table-empty{
  text-align:center;
  color:var(--muted);
  padding:26px 16px !important;
}

/* ===== BADGES ===== */
.badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:90px;
  padding:8px 12px;
  border-radius:999px;
  font-size:12px;
  font-weight:900;
  text-transform:capitalize;
}

.badge.active,
.badge.paid{
  background:var(--green-soft);
  border:1px solid rgba(34,197,94,.18);
  color:#d6ffe1;
}

.badge.blocked,
.badge.overdue,
.badge.inactive{
  background:var(--red-soft);
  border:1px solid rgba(239,68,68,.18);
  color:#ffd4d4;
}

.badge.pending,
.badge.trial{
  background:var(--orange-soft);
  border:1px solid rgba(245,158,11,.18);
  color:#ffe4b7;
}

/* ===== STATUS LIST ===== */
.status-list{
  display:grid;
  gap:12px;
}

.status-item{
  padding:16px 18px;
  border-radius:16px;
  border:1px solid var(--border);
  background:rgba(255,255,255,.03);
}

.status-item b{
  display:block;
  margin-bottom:6px;
  font-size:15px;
}

.status-item span{
  color:var(--muted);
  font-size:14px;
  line-height:1.6;
}

/* ===== FORM BASE ===== */
.form-grid{
  display:grid;
  gap:16px;
  width:100%;
}

.client-form-grid{
  gap:16px;
}

/* Compatível com o HTML antigo e com o novo */
.form-grid > label{
  display:block;
  margin:0 0 -6px;
  font-size:13px;
  font-weight:800;
  color:var(--text-soft);
  line-height:1.3;
}

.form-grid > input,
.form-grid > select,
.form-grid > textarea,
.field-group input,
.field-group select,
.field-group textarea{
  width:100%;
  min-height:48px;
  padding:12px 14px;
  border-radius:14px;
  border:1px solid var(--border);
  background:#0e1822;
  color:var(--text);
  outline:none;
  transition:.18s ease;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.02);
  -webkit-appearance:none;
  appearance:none;
}

.form-grid > textarea,
.field-group textarea{
  min-height:120px;
  resize:vertical;
}

.form-grid > input:focus,
.form-grid > select:focus,
.form-grid > textarea:focus,
.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus{
  border-color:rgba(56,189,248,.38);
  box-shadow:0 0 0 4px rgba(56,189,248,.08);
}

.form-grid > select,
.field-group select{
  background-image:
    linear-gradient(45deg, transparent 50%, #a8bbca 50%),
    linear-gradient(135deg, #a8bbca 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px);
  background-size:6px 6px, 6px 6px;
  background-repeat:no-repeat;
  padding-right:38px;
}

/* ===== FORM NOVO ===== */
.field-group{
  display:grid;
  gap:8px;
  min-width:0;
}

.field-group label{
  display:block;
  font-size:13px;
  font-weight:800;
  color:var(--text-soft);
}

.form-row{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:14px;
  width:100%;
}

.form-row-3{
  grid-template-columns:180px minmax(0,1fr);
}

.field-span-2{
  min-width:0;
}

/* ===== FORM ANTIGO MELHORADO ===== */
/* Se o form for o antigo, deixa elegante e bem distribuído */
.panel-card .form-grid:not(.client-form-grid){
  grid-template-columns:repeat(2,minmax(0,1fr));
  column-gap:16px;
  row-gap:12px;
  align-items:start;
}

.panel-card .form-grid:not(.client-form-grid) > label{
  margin-bottom:-2px;
}

.panel-card .form-grid:not(.client-form-grid) > textarea{
  grid-column:1 / -1;
}

.panel-card .form-grid:not(.client-form-grid) > .inline-actions{
  grid-column:1 / -1;
}

/* ===== ACTIONS ===== */
.inline-actions{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
}

.small-link{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:38px;
  padding:8px 12px;
  border-radius:12px;
  background:rgba(255,255,255,.03);
  border:1px solid var(--border);
  color:var(--text-soft);
  font-weight:700;
}

.muted{
  color:var(--muted);
}

/* ===== RESPONSIVE ===== */
@media (max-width:1400px){
  .stats-grid{
    grid-template-columns:repeat(2,minmax(0,1fr));
  }

  .hero-card{
    grid-template-columns:1fr;
  }

  .content-grid.two,
  .content-grid.equal{
    grid-template-columns:1fr;
  }
}

@media (max-width:1080px){
  .app-shell{
    grid-template-columns:1fr;
  }

  .sidebar{
    display:none;
  }

  .main-content{
    padding:16px;
  }

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

@media (max-width:900px){
  table{
    min-width:620px;
  }

  .form-row,
  .form-row-3,
  .panel-card .form-grid:not(.client-form-grid){
    grid-template-columns:1fr;
  }

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

  .inline-actions .btn,
  .inline-actions a{
    width:100%;
  }
}

@media (max-width:720px){
  .stats-grid{
    grid-template-columns:1fr;
  }

  .topbar h1{
    font-size:28px;
  }

  .panel-card,
  .stat-card,
  .hero-card{
    padding:18px;
  }
}