/* ================================================================
   Painel Master — Dark Theme
   ================================================================ */
:root {
  --bg:         #0f172a;
  --bg2:        #1e293b;
  --bg3:        #334155;
  --border:     #334155;
  --border2:    #475569;
  --text:       #f1f5f9;
  --text2:      #cbd5e1;
  --muted:      #94a3b8;
  --blue:       #3b82f6;
  --blue-h:     #2563eb;
  --green:      #10b981;
  --green-h:    #059669;
  --yellow:     #f59e0b;
  --red:        #ef4444;
  --red-h:      #dc2626;
  --purple:     #8b5cf6;
  --teal:       #14b8a6;
  --sidebar-w:  260px;
  --topbar-h:   60px;
  --radius:     10px;
  --radius-sm:  6px;
  --shadow:     0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-md:  0 4px 6px rgba(0,0,0,.4), 0 2px 4px rgba(0,0,0,.3);
}

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

html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  position: fixed; left: 0; top: 0;
  width: var(--sidebar-w); height: 100vh;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 200;
  transition: transform .25s ease;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 20px 16px;
  font-size: 1.1rem; font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  user-select: none;
}
.sidebar-nav {
  flex: 1; padding: 12px 10px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--muted); font-size: .9rem; font-weight: 500;
  transition: background .15s, color .15s;
  cursor: pointer;
}
.nav-item:hover { background: var(--bg3); color: var(--text); text-decoration: none; }
.nav-item.active { background: rgba(59,130,246,.15); color: var(--blue); }
.nav-item.active .nav-icon { stroke: var(--blue); }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; }
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.user-info { flex: 1; display: flex; align-items: center; gap: 10px; overflow: hidden; }
.user-name { font-size: .85rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .75rem; color: var(--muted); text-transform: capitalize; }
.avatar-sm {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; flex-shrink: 0;
}
.btn-logout {
  background: none; border: none; cursor: pointer; color: var(--muted);
  padding: 6px; border-radius: var(--radius-sm); transition: color .15s, background .15s;
  display: flex; align-items: center;
}
.btn-logout:hover { color: var(--red); background: rgba(239,68,68,.1); }

/* ── Topbar ───────────────────────────────────────────────── */
.main-wrap {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
}
.topbar {
  position: sticky; top: 0; z-index: 100;
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
}
.topbar-title { font-size: 1rem; font-weight: 600; flex: 1; }
.topbar-date { font-size: .8rem; color: var(--muted); }
.sidebar-toggle {
  display: none;
  background: none; border: none; color: var(--text);
  cursor: pointer; padding: 4px; border-radius: var(--radius-sm);
}
.main-content { flex: 1; padding: 24px; }

/* ── Flash messages ───────────────────────────────────────── */
.flash {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-radius: var(--radius-sm);
  margin-bottom: 16px; font-size: .9rem; font-weight: 500;
  animation: slideIn .2s ease;
}
@keyframes slideIn { from { opacity:0; transform:translateY(-8px); } to { opacity:1; transform:none; } }
.flash-success { background: rgba(16,185,129,.15); border: 1px solid rgba(16,185,129,.3); color: #6ee7b7; }
.flash-error   { background: rgba(239,68,68,.15);  border: 1px solid rgba(239,68,68,.3);  color: #fca5a5; }
.flash-warning { background: rgba(245,158,11,.15); border: 1px solid rgba(245,158,11,.3); color: #fcd34d; }
.flash-info    { background: rgba(59,130,246,.15); border: 1px solid rgba(59,130,246,.3); color: #93c5fd; }
.flash-close { background: none; border: none; cursor: pointer; color: inherit; font-size: 1.2rem; opacity: .7; line-height: 1; padding: 0 4px; }
.flash-close:hover { opacity: 1; }
.flash-top { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 999; min-width: 320px; box-shadow: var(--shadow-md); }

/* ── Page header ──────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h2 { font-size: 1.3rem; font-weight: 700; }
.page-header-left { display: flex; align-items: center; gap: 14px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 1rem; font-weight: 600; }
.card-footer { padding-top: 12px; border-top: 1px solid var(--border); margin-top: 8px; }
.link-all { font-size: .85rem; color: var(--blue); }
.link-all:hover { text-decoration: underline; }

/* ── Stat cards ───────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow);
}
.stat-icon {
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-blue   { background: rgba(59,130,246,.15); } .stat-blue svg   { stroke: var(--blue); }
.stat-green  { background: rgba(16,185,129,.15); } .stat-green svg  { stroke: var(--green); }
.stat-purple { background: rgba(139,92,246,.15); } .stat-purple svg { stroke: var(--purple); }
.stat-yellow { background: rgba(245,158,11,.15); } .stat-yellow svg { stroke: var(--yellow); }
.stat-red    { background: rgba(239,68,68,.15);  } .stat-red svg    { stroke: var(--red); }
.stat-teal   { background: rgba(20,184,166,.15); } .stat-teal svg   { stroke: var(--teal); }
.stat-value { font-size: 1.5rem; font-weight: 800; color: var(--text); line-height: 1.2; }
.stat-label { font-size: .78rem; color: var(--muted); margin-top: 2px; }

/* ── Dashboard grid ───────────────────────────────────────── */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.quick-actions { margin-bottom: 0; }
.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.quick-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 16px; border-radius: var(--radius-sm);
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text2); font-size: .85rem; font-weight: 500;
  cursor: pointer; transition: background .15s, color .15s;
  text-decoration: none;
}
.quick-btn:hover { background: var(--blue); color: #fff; border-color: var(--blue); text-decoration: none; }
.quick-btn svg { width: 22px; height: 22px; }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th {
  text-align: left; padding: 10px 12px;
  font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: rgba(255,255,255,.02); }
.table .row-link { cursor: pointer; }
.table .text-center { text-align: center; }
.table .text-right  { text-align: right; }
.row-title { color: var(--text); font-weight: 600; }
.row-title:hover { color: var(--blue); text-decoration: none; }

/* ── Forms ────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.form-card { }
.form-card-single { max-width: 800px; }
.section-title { font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 14px; }
.form-row { display: flex; gap: 14px; }
.form-row .form-group { flex: 1; }
.form-group { margin-bottom: 14px; }
.form-group.required .form-label::after { content: ' *'; color: var(--red); }
.form-label { display: block; font-size: .82rem; font-weight: 600; color: var(--text2); margin-bottom: 5px; }
.form-control {
  width: 100%; padding: 8px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: .88rem; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59,130,246,.2); }
.form-control::placeholder { color: var(--bg3); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; }
.input-icon-wrap { position: relative; }
.input-icon-wrap .form-control { padding-right: 40px; }
.input-icon-btn {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px;
}
.input-icon-btn:hover { color: var(--text); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 16px; border-top: 1px solid var(--border); }

/* Filter bar */
.filter-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.filter-search { flex: 1; min-width: 200px; }
.filter-select { width: auto; }
.filter-bar-wide .filter-select { min-width: 140px; }

/* Services list in client form */
.services-list { display: flex; flex-direction: column; gap: 8px; }
.service-toggle { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; display: flex; align-items: center; gap: 10px; transition: border-color .15s; }
.service-toggle:hover { border-color: var(--blue); }
.service-check { display: flex; align-items: center; gap: 10px; flex: 1; cursor: pointer; }
.service-check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--blue); flex-shrink: 0; }
.service-info { flex: 1; }
.service-name { font-size: .88rem; font-weight: 500; color: var(--text); }
.service-cat  { font-size: .75rem; color: var(--muted); margin-left: 8px; }
.service-price { font-size: .82rem; color: var(--muted); white-space: nowrap; }
.svc-price-input { width: 130px; flex-shrink: 0; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm); font-size: .88rem;
  font-weight: 600; cursor: pointer; border: 1px solid transparent;
  transition: background .15s, opacity .15s, box-shadow .15s;
  text-decoration: none; white-space: nowrap; font-family: inherit;
}
.btn:hover { text-decoration: none; opacity: .92; }
.btn:active { transform: translateY(1px); }
.btn-primary   { background: var(--blue);  color: #fff; border-color: var(--blue); }
.btn-primary:hover   { background: var(--blue-h); }
.btn-secondary { background: var(--bg3);   color: var(--text2); border-color: var(--border2); }
.btn-secondary:hover { background: var(--bg2); }
.btn-success   { background: var(--green); color: #fff; border-color: var(--green); }
.btn-success:hover   { background: var(--green-h); }
.btn-danger    { background: var(--red);   color: #fff; border-color: var(--red); }
.btn-danger:hover    { background: var(--red-h); }
.btn-ghost     { background: transparent; color: var(--text2); border-color: var(--border); }
.btn-ghost:hover     { background: var(--bg3); }
.btn-sm        { padding: 5px 10px; font-size: .8rem; }
.btn-block     { width: 100%; }
.btn-danger-ghost  { background: none; border: none; cursor: pointer; color: var(--muted); padding: 5px 8px; border-radius: var(--radius-sm); transition: color .15s, background .15s; font-family: inherit; }
.btn-danger-ghost:hover  { color: var(--red); background: rgba(239,68,68,.1); }
.btn-success-ghost { background: none; border: none; cursor: pointer; color: var(--green); padding: 5px 8px; border-radius: var(--radius-sm); transition: background .15s; font-family: inherit; font-size: .88rem; font-weight: 600; }
.btn-success-ghost:hover { background: rgba(16,185,129,.1); }
.btn-inline-icon { background: none; border: none; cursor: pointer; color: var(--muted); padding: 2px 4px; }
.btn-inline-icon:hover { color: var(--text); }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: .73rem; font-weight: 600; text-transform: capitalize; letter-spacing: .02em;
}
.badge-lg { padding: 4px 14px; font-size: .85rem; }
.badge-ativo     { background: rgba(16,185,129,.15); color: #6ee7b7; }
.badge-inativo   { background: rgba(148,163,184,.12); color: var(--muted); }
.badge-suspenso  { background: rgba(245,158,11,.15);  color: #fcd34d; }
.badge-pendente  { background: rgba(59,130,246,.15);  color: #93c5fd; }
.badge-pago      { background: rgba(16,185,129,.15);  color: #6ee7b7; }
.badge-atrasado  { background: rgba(239,68,68,.15);   color: #fca5a5; }
.badge-cancelado { background: rgba(100,116,139,.15); color: var(--muted); }
.badge-neutral   { background: var(--bg3); color: var(--text2); }

/* ── Client cell ──────────────────────────────────────────── */
.client-cell { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-size: .82rem; font-weight: 800; color: #fff;
}
.avatar-lg { width: 52px; height: 52px; font-size: 1.2rem; }
.action-btns { display: flex; gap: 4px; align-items: center; }
.link-external { color: var(--blue); font-size: .85rem; }

/* ── Show page grid ───────────────────────────────────────── */
.show-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: .88rem; align-items: start; }
.info-list dt { color: var(--muted); font-weight: 500; white-space: nowrap; padding-top: 2px; }
.info-list dd { color: var(--text); }
.modules-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { background: var(--bg3); color: var(--text2); padding: 3px 10px; border-radius: 20px; font-size: .8rem; }
.pass-mask { font-family: monospace; letter-spacing: 3px; }
.empty-state-sm { padding: 16px; color: var(--muted); font-size: .88rem; text-align: center; }

/* ── Empty state ──────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty-state svg { margin-bottom: 12px; display: block; margin-left: auto; margin-right: auto; }
.empty-state p { margin-bottom: 16px; }

/* ── Invoice ──────────────────────────────────────────────── */
.invoice-doc { max-width: 800px; }
.invoice-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.invoice-brand { display: flex; align-items: center; gap: 10px; font-size: 1.1rem; font-weight: 700; }
.invoice-meta { text-align: right; }
.invoice-number { font-size: 1.2rem; font-weight: 800; color: var(--text); }
.invoice-client { padding: 16px; background: var(--bg); border-radius: var(--radius-sm); }
.invoice-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.invoice-total { display: flex; align-items: center; gap: 12px; }
.invoice-total strong { font-size: 1.1rem; }
.invoice-total-row { display: flex; justify-content: flex-end; margin-top: 16px; }
.total-box { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px 24px; text-align: right; min-width: 200px; }
.total-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }
.total-value { font-size: 1.6rem; font-weight: 800; color: var(--text); }
.invoice-notes { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.invoice-table td { font-size: .9rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Modal ────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); width: min(480px, 90vw);
  box-shadow: var(--shadow-md);
  animation: popIn .2s ease;
}
@keyframes popIn { from { opacity:0; transform:scale(.95); } to { opacity:1; transform:scale(1); } }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 1.4rem; cursor: pointer; padding: 0 4px; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Auth ─────────────────────────────────────────────────── */
.auth-body { display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--bg); }
.auth-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.auth-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 40px; width: min(400px, 100%); box-shadow: var(--shadow-md); }
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo h1 { font-size: 1.4rem; font-weight: 800; margin-top: 10px; }
.auth-logo p { color: var(--muted); font-size: .88rem; }
.auth-form .form-group { margin-bottom: 18px; }
.auth-hint { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 16px; }

/* ── Utilities ────────────────────────────────────────────── */
.fw-medium { font-weight: 600; }
.text-sm    { font-size: .82rem; }
.text-muted { color: var(--muted); }
.text-danger { color: #fca5a5; }
.text-success { color: #6ee7b7; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 150; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .show-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  :root { --sidebar-w: 260px; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .main-wrap { margin-left: 0; }
  .sidebar-toggle { display: flex; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .main-content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .form-row { flex-direction: column; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-search { min-width: unset; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
}
