:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #0284c7;
  --info-soft: #e0f2fe;
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.15);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--surface-2);
  color: var(--text);
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  font-size: 14px;
}
body.no-sidebar { grid-template-columns: 1fr; }

/* SIDEBAR */
.sidebar {
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: #cbd5e1;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 14px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand-logo {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 4px 10px rgba(99,102,241,0.35);
}
.brand-title { color: white; font-weight: 600; font-size: 15px; }
.brand-sub { color: #94a3b8; font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  text-align: left;
  background: transparent;
  border: none;
  color: #cbd5e1;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; gap: 10px;
  transition: all .15s;
  font-family: inherit;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: white; }
.nav-item.active {
  background: rgba(99,102,241,0.18);
  color: white;
  font-weight: 500;
}
.nav-icon { font-size: 16px; }

.sidebar-footer { display: flex; flex-direction: column; gap: 6px; }
.sidebar-footer .ghost-btn {
  background: transparent;
  color: #cbd5e1;
  border: 1px solid rgba(255,255,255,0.12);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
.sidebar-footer .ghost-btn:hover { background: rgba(255,255,255,0.06); color: white; }

/* MAIN */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-left h1 { margin: 0 0 2px 0; font-size: 20px; font-weight: 600; }
.topbar-left .muted { margin: 0; font-size: 13px; }
.topbar-right { display: flex; gap: 10px; align-items: center; }

.search-wrap input {
  width: 280px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface-2);
  transition: all .15s;
  font-family: inherit;
}
.search-wrap input:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.view { padding: 24px 28px; display: flex; flex-direction: column; gap: 20px; }
.view.hidden { display: none; }

/* BUTTONS */
.primary-btn, .ghost-btn, .danger-btn, .icon-btn, .success-btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.primary-btn { background: var(--primary); color: white; }
.primary-btn:hover { background: var(--primary-hover); }
.success-btn { background: var(--success); color: white; }
.success-btn:hover { background: #15803d; }
.ghost-btn { background: white; color: var(--text); border: 1px solid var(--border); }
.ghost-btn:hover { background: var(--surface-2); }
.danger-btn { background: var(--danger); color: white; }
.danger-btn:hover { background: #b91c1c; }
.icon-btn {
  background: transparent;
  color: var(--text-muted);
  width: 32px; height: 32px;
  display: grid; place-items: center;
  font-size: 16px;
  padding: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.muted { color: var(--text-muted); }
.hidden { display: none !important; }

/* CARDS */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
  gap: 12px;
}
.card-head h3 { margin: 0; font-size: 15px; font-weight: 600; }

/* KPIs */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}
.kpi { padding: 18px; }
.kpi-label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi-value { font-size: 26px; font-weight: 700; margin: 6px 0 4px; }
.kpi-foot { font-size: 12px; color: var(--text-muted); }
.kpi-green { border-top: 3px solid var(--success); }
.kpi-green .kpi-value { color: var(--success); }
.kpi-amber { border-top: 3px solid var(--warning); }
.kpi-amber .kpi-value { color: var(--warning); }
.kpi-blue { border-top: 3px solid var(--info); }
.kpi-blue .kpi-value { color: var(--info); }
.kpi-red { border-top: 3px solid var(--danger); }
.kpi-red .kpi-value { color: var(--danger); }
.kpi-purple { border-top: 3px solid #8b5cf6; }
.kpi-purple .kpi-value { color: #8b5cf6; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 16px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

/* TABLES */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  text-align: left;
  background: var(--surface-2);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.table tbody tr:hover { background: var(--surface-2); }
.table.compact th, .table.compact td { padding: 8px 12px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* BADGES */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.amber { background: var(--warning-soft); color: var(--warning); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.blue { background: var(--info-soft); color: var(--info); }
.badge.gray { background: var(--surface-2); color: var(--text-muted); }
.badge.purple { background: #f3e8ff; color: #7c3aed; }

/* FILTERS */
.filters {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 140px; }
.filter-group label { font-size: 11px; text-transform: uppercase; color: var(--text-muted); font-weight: 600; letter-spacing: .04em; }
.filter-group select, .filter-group input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: white;
  font-family: inherit;
}
.filter-group select:focus, .filter-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.row-action {
  background: var(--primary-soft);
  color: var(--primary);
  border: none;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-right: 4px;
}
.row-action:hover { background: var(--primary); color: white; }
.row-action.danger { background: var(--danger-soft); color: var(--danger); }
.row-action.danger:hover { background: var(--danger); color: white; }
.row-action.success { background: var(--success-soft); color: var(--success); }
.row-action.success:hover { background: var(--success); color: white; }

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}
.modal-content {
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h3 { margin: 0; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .04em;
}
.form-grid input, .form-grid select, .form-grid textarea {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
  font-weight: 400;
  background: white;
}
.form-grid textarea { min-height: 80px; resize: vertical; }
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.span-2 { grid-column: span 2; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal-actions .danger-btn { margin-right: auto; }

/* HEAD ACTIONS (botões dentro de .card-head) */
.head-actions { display: flex; align-items: center; gap: 12px; }

/* IMPORT MODAL */
.import-modal { max-width: 880px; }
.import-step { display: flex; flex-direction: column; gap: 14px; }
.file-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 16px;
  cursor: pointer;
  background: var(--surface-2);
  font-size: 14px;
  color: var(--text-muted);
  transition: border-color .15s, background .15s;
}
.file-drop:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.file-drop input[type="file"] { display: none; }
.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}
.import-summary { display: flex; gap: 8px; }
.import-preview { max-height: 280px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.import-preview table { font-size: 12px; }
.import-errors {
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  max-height: 200px;
  overflow-y: auto;
}
.import-errors ul { margin: 6px 0 0; padding-left: 18px; }
.import-errors li { margin: 2px 0; }

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 200;
  box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* SIMULADOR PÚBLICO */
.simulador-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 80px;
}
.simulador-header {
  text-align: center;
  margin-bottom: 32px;
}
.simulador-header .brand-logo {
  margin: 0 auto 12px;
  width: 56px;
  height: 56px;
  font-size: 18px;
}
.simulador-header h1 { margin: 0 0 6px; font-size: 28px; font-weight: 700; }
.simulador-header p { margin: 0; color: var(--text-muted); font-size: 15px; }

.iphone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}
.iphone-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: all .2s;
}
.iphone-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.iphone-card-emoji {
  font-size: 42px;
  text-align: center;
  padding: 16px 0;
  background: linear-gradient(135deg, var(--primary-soft), #f5f3ff);
  border-radius: var(--radius-sm);
}

.iphone-card-photo {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  display: grid;
  place-items: center;
}
.iphone-card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.iphone-card-photo.small { aspect-ratio: 1; width: 96px; }

.iphone-card-color {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}
.iphone-card-color.small { width: 96px; aspect-ratio: 1; }
.iphone-card-color::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.25), transparent 60%);
  pointer-events: none;
}
.iphone-card-emoji-overlay {
  font-size: 56px;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.25));
  position: relative;
  z-index: 1;
}
.iphone-card-color.small .iphone-card-emoji-overlay { font-size: 36px; }
.iphone-card h3 { margin: 0; font-size: 17px; font-weight: 700; }
.iphone-card .specs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.iphone-card .specs .badge { font-size: 10px; }
.iphone-card .price-vista {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}
.iphone-card .price-vista .label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 2px;
}
.iphone-card .parcel {
  font-size: 13px;
  color: var(--text-muted);
}
.iphone-card .parcel strong { color: var(--text); }
.iphone-card .cta {
  margin-top: auto;
  background: var(--success);
  color: white;
  border: none;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}
.iphone-card .cta:hover { background: #15803d; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .ico { font-size: 42px; margin-bottom: 12px; }

/* AUTH (login / signup) */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #f8fafc 0%, #eef2ff 100%);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 32px;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}
.auth-brand .brand-logo {
  width: 48px; height: 48px;
  border-radius: 12px;
  font-size: 16px;
}
.brand-title-dark { color: var(--text); font-weight: 700; font-size: 18px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; text-transform: uppercase; font-weight: 600;
  color: var(--text-muted); letter-spacing: .04em;
}
.auth-form input {
  padding: 11px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit; text-transform: none; letter-spacing: normal;
  color: var(--text); font-weight: 400; background: white;
}
.auth-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.auth-form .primary-btn { margin-top: 8px; padding: 11px; }
.auth-error {
  background: var(--danger-soft); color: var(--danger);
  border: 1px solid #fecaca; border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 13px;
}
.auth-foot {
  margin-top: 18px; padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; font-size: 13px;
}
.auth-foot a { color: var(--primary); text-decoration: none; font-weight: 500; }
.auth-foot a:hover { text-decoration: underline; }
.link-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 13px; padding: 0; font-family: inherit; }
.link-btn:hover { color: var(--primary); text-decoration: underline; }

.strength-bar { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin: -6px 0 4px; }
.strength-bar > div { height: 100%; width: 0; transition: all .2s; background: var(--danger); }
.strength-bar > div.weak { background: var(--danger); }
.strength-bar > div.medium { background: var(--warning); }
.strength-bar > div.strong { background: var(--success); }

/* USER MENU na sidebar (footer) */
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.04);
  border-radius: var(--radius-sm);
  color: #cbd5e1;
  font-size: 12px;
  margin-bottom: 6px;
}
.user-chip-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 12px;
}
.user-chip-info { line-height: 1.3; min-width: 0; flex: 1; }
.user-chip-name { color: white; font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip-role { font-size: 10px; color: #94a3b8; text-transform: uppercase; letter-spacing: .04em; }

/* LOGS */
.log-row { font-size: 13px; }
.log-row .log-meta { font-size: 11px; color: var(--text-muted); }
.log-action {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.log-action.create { background: var(--success-soft); color: var(--success); }
.log-action.update { background: var(--info-soft); color: var(--info); }
.log-action.delete { background: var(--danger-soft); color: var(--danger); }
.log-action.login  { background: var(--primary-soft); color: var(--primary); }
.log-action.logout { background: var(--surface-2); color: var(--text-muted); }
.log-action.export { background: #f3e8ff; color: #7c3aed; }
.log-action.signup { background: var(--success-soft); color: var(--success); }

/* RESPONSIVE */
@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; flex-wrap: wrap; gap: 12px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { flex-direction: row; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .search-wrap input { width: 180px; }
}
