/* ═══════════════════════════════════════════
   TechSup v2 - Gestão MEI | Stylesheet
   ═══════════════════════════════════════════ */

:root {
  --bg: #0f0f1a;
  --bg-card: #16162a;
  --bg-sidebar: #12121f;
  --border: rgba(255,255,255,0.06);
  --border-hover: rgba(245,158,11,0.3);
  --text: #E0E0E0;
  --text-muted: #6B7280;
  --text-dim: #4B5563;
  --accent: #F59E0B;
  --accent-dark: #D97706;
  --blue: #3B82F6;
  --green: #10B981;
  --red: #EF4444;
  --purple: #8B5CF6;
  --radius: 10px;
  --font: 'DM Sans', -apple-system, sans-serif;
  --font-display: 'Space Grotesk', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

/* ─── Login Screen ─── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 20% 50%, rgba(245,158,11,0.06) 0%, transparent 60%),
              radial-gradient(ellipse at 80% 20%, rgba(59,130,246,0.06) 0%, transparent 60%),
              var(--bg);
  padding: 20px;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 32px 80px rgba(0,0,0,0.4);
}
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo h1 {
  font-family: var(--font-display);
  font-size: 28px; font-weight: 800;
  color: #fff; margin: 12px 0 4px;
}
.login-logo p { color: var(--text-muted); font-size: 14px; }
.brand-icon { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), var(--accent-dark)); display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; color: #000; }
.brand-icon.large { width: 60px; height: 60px; font-size: 28px; border-radius: 16px; margin: 0 auto; }
.login-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 8px; padding: 10px 14px;
  color: #F87171; font-size: 14px; margin-bottom: 12px;
}
.login-hint { text-align: center; margin-top: 16px; font-size: 12px; color: var(--text-dim); }
.login-hint code { background: rgba(255,255,255,0.06); padding: 2px 6px; border-radius: 4px; color: var(--accent); font-family: monospace; }

/* ─── App Layout ─── */
#app { display: flex; height: 100vh; overflow: hidden; }
#app.hidden { display: none !important; }

/* ─── Sidebar ─── */
#sidebar {
  width: 220px; background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 22px 18px; border-bottom: 1px solid var(--border); }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 15px; color: #fff; }
.brand-sub { font-size: 10px; color: var(--text-muted); font-weight: 500; }
.sidebar-nav { padding: 16px 12px; flex: 1; overflow-y: auto; }
.nav-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: none; border-radius: 8px; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 14px; font-weight: 500; font-family: var(--font); transition: all 0.2s; margin-bottom: 4px; text-align: left; }
.nav-btn:hover { background: rgba(255,255,255,0.04); }
.nav-btn.active { background: rgba(245,158,11,0.12); color: var(--accent); font-weight: 600; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-divider { border-top: 1px solid var(--border); margin: 8px 0; }
.sidebar-user { padding: 14px; border-top: 1px solid var(--border); }
.sidebar-user-info { display: flex; align-items: center; gap: 10px; }
.sidebar-user-avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--purple)); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; color: #000; flex-shrink: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role { font-size: 11px; color: var(--text-muted); }
.btn-logout { width: 100%; margin-top: 8px; }

/* ─── Main Content ─── */
#content { flex: 1; overflow-y: auto; padding: 28px 32px; }
.page { display: none; }
.page.active { display: block; }

/* ─── Page Header ─── */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.page-header h1 { font-family: var(--font-display); font-size: 26px; font-weight: 700; color: #fff; margin-bottom: 4px; }
.page-header p { font-size: 14px; color: var(--text-muted); }

/* ─── Stats Grid ─── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.stat-card { background: var(--bg-card); border-radius: 12px; padding: 20px 22px; border: 1px solid var(--border); position: relative; overflow: hidden; }
.stat-card .glow { position: absolute; top: -10px; right: -10px; width: 60px; height: 60px; border-radius: 50%; opacity: 0.06; }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; font-family: var(--font-display); }

/* ─── Buttons ─── */
.btn { padding: 10px 22px; border-radius: 8px; font-weight: 700; font-size: 14px; cursor: pointer; font-family: var(--font); transition: all 0.2s; border: none; letter-spacing: 0.02em; white-space: nowrap; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); color: #000; }
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-secondary { background: rgba(255,255,255,0.06); color: var(--text-muted); border: 1px solid rgba(255,255,255,0.1); }
.btn-secondary:hover { background: rgba(255,255,255,0.1); color: var(--text); }
.btn-danger { background: rgba(239,68,68,0.12); color: #F87171; border: 1px solid rgba(239,68,68,0.2); }
.btn-success { background: rgba(16,185,129,0.12); color: #34D399; border: 1px solid rgba(16,185,129,0.2); }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.quick-actions { display: flex; gap: 12px; margin-bottom: 28px; flex-wrap: wrap; }

/* ─── Card ─── */
.card { background: var(--bg-card); border-radius: 12px; border: 1px solid var(--border); overflow: hidden; margin-bottom: 20px; }
.card-header { padding: 16px 22px; border-bottom: 1px solid var(--border); }
.card-header h3 { font-family: var(--font-display); font-size: 16px; font-weight: 600; color: #fff; }
.card-body { padding: 0; }

/* ─── Toolbar ─── */
.toolbar { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

/* ─── Input ─── */
.input { width: 100%; padding: 10px 14px; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: var(--text); font-size: 14px; font-family: var(--font); outline: none; transition: border-color 0.2s; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(245,158,11,0.15); }
.input.mono { font-family: 'SF Mono', 'Cascadia Code', monospace; }
select.input { cursor: pointer; }
select.input option { background: #1a1a2e; color: var(--text); }
textarea.input { resize: vertical; }
.input-group { display: flex; gap: 8px; }
.field { margin-bottom: 16px; }
.field label, .field-label { display: block; font-size: 12px; font-weight: 600; color: #9CA3AF; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.05em; }
.req { color: var(--accent); }
.hint { display: block; margin-top: 4px; font-size: 11px; color: var(--text-dim); }
.row-2 { display: flex; gap: 16px; }
.row-2 > .field, .row-2 > div { flex: 1; }
.row-3 { display: flex; gap: 16px; }
.row-3 > .field, .row-3 > div { flex: 1; }
.section-divider { border-top: 1px solid var(--border); margin: 16px 0; padding-top: 16px; }
.section-divider h4 { font-size: 13px; font-weight: 700; color: #9CA3AF; text-transform: uppercase; letter-spacing: 0.05em; }

/* ─── Tipo Toggle ─── */
.tipo-toggle { display: flex; gap: 10px; margin-bottom: 20px; }
.tipo-btn { flex: 1; padding: 10px; border-radius: 8px; background: rgba(255,255,255,0.04); color: var(--text-muted); border: 1px solid rgba(255,255,255,0.1); cursor: pointer; font-size: 14px; font-weight: 600; font-family: var(--font); transition: all 0.2s; }
.tipo-btn.active { background: rgba(245,158,11,0.12); color: var(--accent); border-color: var(--border-hover); }

/* ─── Clients Grid ─── */
.clients-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.client-card { background: var(--bg-card); border-radius: 12px; padding: 18px 20px; border: 1px solid var(--border); cursor: pointer; transition: all 0.2s; }
.client-card:hover { border-color: var(--border-hover); }
.client-top { display: flex; justify-content: space-between; align-items: flex-start; }
.client-badges { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.badge { padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; }
.badge-pj { background: rgba(59,130,246,0.15); color: #60A5FA; }
.badge-pf { background: rgba(139,92,246,0.15); color: #A78BFA; }
.badge-ativa { background: rgba(16,185,129,0.15); color: #34D399; }
.badge-inativa { background: rgba(239,68,68,0.15); color: #F87171; }
.badge-admin { background: rgba(245,158,11,0.15); color: #FCD34D; }
.badge-suporte { background: rgba(59,130,246,0.15); color: #93C5FD; }
.client-name { font-weight: 700; font-size: 15px; color: #fff; margin-bottom: 4px; }
.client-doc { font-size: 12px; color: var(--text-muted); font-family: monospace; }
.client-email { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.client-os-count .num { font-size: 20px; font-weight: 700; color: var(--accent); font-family: var(--font-display); }
.client-os-count .label { font-size: 10px; color: var(--text-dim); }
.client-location { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,0.04); font-size: 12px; color: var(--text-dim); }

/* ─── Order Rows ─── */
.order-row { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; border-bottom: 1px solid rgba(255,255,255,0.03); transition: background 0.15s; }
.order-row:hover { background: rgba(255,255,255,0.02); }
.order-info { flex: 1; min-width: 0; }
.order-title { font-weight: 600; font-size: 14px; color: var(--text); margin-bottom: 3px; }
.order-meta { font-size: 12px; color: var(--text-muted); }
.order-desc { font-size: 12px; color: var(--text-dim); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 400px; }
.order-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; margin-left: 16px; }
.order-value { font-size: 14px; font-weight: 700; color: var(--green); font-family: var(--font-display); }
.status-badge { padding: 4px 12px; border-radius: 6px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.status-aberta        { background: #FEF3C7; color: #92400E; border: 1px solid #F59E0B; }
.status-em_andamento  { background: #DBEAFE; color: #1E40AF; border: 1px solid #3B82F6; }
.status-concluida     { background: #D1FAE5; color: #065F46; border: 1px solid #10B981; }
.status-cancelada     { background: #FEE2E2; color: #991B1B; border: 1px solid #EF4444; }
.status-rascunho      { background: rgba(107,114,128,0.15); color: #9CA3AF; border: 1px solid rgba(107,114,128,0.3); }
.status-enviada       { background: #DBEAFE; color: #1E40AF; border: 1px solid #3B82F6; }
.status-visualizada   { background: rgba(139,92,246,0.15); color: #A78BFA; border: 1px solid rgba(139,92,246,0.3); }
.status-paga          { background: #D1FAE5; color: #065F46; border: 1px solid #10B981; }
.status-vencida       { background: #FEE2E2; color: #991B1B; border: 1px solid #EF4444; }

.icon-btn { background: rgba(255,255,255,0.06); border: none; color: #9CA3AF; width: 32px; height: 32px; border-radius: 6px; cursor: pointer; font-size: 13px; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.icon-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }
.icon-btn.danger { background: rgba(239,68,68,0.1); color: #F87171; }
.icon-btn.danger:hover { background: rgba(239,68,68,0.2); }

/* ─── Faturas ─── */
.fatura-item-header { display: flex; gap: 8px; padding: 8px 10px; background: rgba(255,255,255,0.02); border-radius: 6px; font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; margin-bottom: 4px; }
.fatura-item-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.fatura-item-row input { padding: 8px 10px; font-size: 13px; }
.fatura-item-desc { flex: 3; }
.fatura-item-qtd { flex: 1; }
.fatura-item-unit { flex: 1.5; }
.fatura-item-total { flex: 1.5; text-align: right; font-weight: 600; color: var(--green); font-family: var(--font-display); font-size: 13px; padding-right: 8px; }
.fatura-totais { background: rgba(255,255,255,0.02); border-radius: 10px; padding: 16px; margin: 16px 0; border: 1px solid var(--border); }
.fatura-total-row { display: flex; gap: 24px; align-items: center; justify-content: flex-end; padding-top: 12px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.fatura-total-row strong { font-family: var(--font-display); }
.os-faturavel-list { display: flex; flex-direction: column; gap: 6px; max-height: 200px; overflow-y: auto; }
.os-faturavel-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: rgba(255,255,255,0.02); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; transition: all 0.15s; }
.os-faturavel-item:hover { border-color: var(--border-hover); background: rgba(245,158,11,0.04); }
.os-faturavel-item.selected { border-color: var(--accent); background: rgba(245,158,11,0.08); }
.os-fat-title { font-size: 13px; font-weight: 600; color: var(--text); flex: 1; }
.os-fat-valor { font-size: 13px; color: var(--green); font-weight: 700; }

/* ─── Fatura Detalhe ─── */
.fatura-detalhe-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.fatura-detalhe-numero { font-family: var(--font-display); font-size: 22px; font-weight: 700; color: #fff; }
.fatura-detalhe-cliente { font-size: 14px; color: var(--text-muted); margin-top: 4px; }
.fatura-detalhe-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.fatura-detalhe-item label { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; display: block; margin-bottom: 4px; }
.fatura-detalhe-item span { font-size: 14px; color: var(--text); }
.fatura-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.fatura-table th { text-align: left; font-size: 11px; color: var(--text-muted); text-transform: uppercase; padding: 8px 12px; background: rgba(255,255,255,0.03); border-bottom: 1px solid var(--border); }
.fatura-table td { padding: 10px 12px; border-bottom: 1px solid rgba(255,255,255,0.03); font-size: 13px; color: var(--text); }
.fatura-table tr:last-child td { border-bottom: none; }
.fatura-actions-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }

/* ─── Usuários ─── */
.usuario-row { display: flex; align-items: center; gap: 16px; padding: 14px 22px; border-bottom: 1px solid rgba(255,255,255,0.03); }
.usuario-avatar { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; color: #000; flex-shrink: 0; }
.usuario-info { flex: 1; }
.usuario-nome { font-weight: 600; font-size: 14px; color: var(--text); }
.usuario-email { font-size: 12px; color: var(--text-muted); }
.usuario-grupo { font-size: 11px; }
.usuario-status-ativo   { color: var(--green); }
.usuario-status-inativo { color: var(--red); }

/* ─── Configs ─── */
.configs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 1100px) { .configs-grid { grid-template-columns: 1fr; } }

/* ─── Modal ─── */
.modal-overlay { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; animation: fadeIn 0.2s ease-out; }
.modal { background: #1a1a2e; border-radius: 16px; width: 100%; max-width: 780px; max-height: 90vh; overflow-y: auto; border: 1px solid rgba(255,255,255,0.08); box-shadow: 0 24px 80px rgba(0,0,0,0.5); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 28px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #1a1a2e; z-index: 1; }
.modal-header h2 { font-size: 20px; font-weight: 700; color: var(--text); font-family: var(--font-display); }
.modal-close { background: rgba(255,255,255,0.06); border: none; color: #888; width: 36px; height: 36px; border-radius: 8px; cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.modal-close:hover { background: rgba(255,255,255,0.12); color: #fff; }
.modal-body { padding: 24px 28px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 20px; }

/* ─── Detail Modal ─── */
.detail-header { background: rgba(245,158,11,0.06); border-radius: 10px; padding: 16px 20px; border: 1px solid rgba(245,158,11,0.12); margin-bottom: 20px; }
.detail-name { font-size: 20px; font-weight: 700; color: #fff; font-family: var(--font-display); }
.detail-razao { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.detail-doc { font-size: 13px; color: #9CA3AF; margin-top: 4px; font-family: monospace; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.detail-item label { font-size: 11px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; margin-bottom: 2px; display: block; }
.detail-item span { font-size: 14px; color: var(--text); }
.detail-os-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-radius: 8px; margin-bottom: 6px; background: rgba(255,255,255,0.02); }
.detail-os-title { font-size: 13px; font-weight: 600; color: var(--text); }
.detail-os-date { font-size: 11px; color: var(--text-muted); }
.detail-os-right { display: flex; align-items: center; gap: 8px; }

/* ─── Toast ─── */
.toast { position: fixed; top: 24px; right: 24px; z-index: 9999; padding: 14px 22px; border-radius: 8px; box-shadow: 0 8px 32px rgba(0,0,0,0.3); max-width: 380px; font-size: 14px; color: #fff; animation: slideIn 0.3s ease-out; }
.toast.hidden { display: none; }
.toast.success { background: #065F46; border-left: 4px solid var(--green); }
.toast.error   { background: #991B1B; border-left: 4px solid var(--red); }
.toast.info    { background: #1E40AF; border-left: 4px solid var(--blue); }

/* ─── Loading ─── */
.loading { animation: pulse 1.5s infinite; }
.empty-state { padding: 48px; text-align: center; color: var(--text-dim); font-size: 14px; }

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes pulse   { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ─── Responsive ─── */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .clients-grid { grid-template-columns: 1fr; }
  .row-3 { flex-direction: column; }
  .fatura-detalhe-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  #sidebar { width: 60px; }
  .sidebar-brand div:last-child, .sidebar-user-info > div, .nav-btn span:not(.nav-icon), .nav-divider + .nav-btn .nav-btn { display: none; }
  .nav-btn { justify-content: center; padding: 12px; }
  #content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr; }
  .row-2 { flex-direction: column; }
  .fatura-item-row { flex-wrap: wrap; }
  .order-actions { flex-wrap: wrap; gap: 6px; }
}
