/* ========================================
   MS NEXUS - Design System
   ======================================== */

:root {
  /* Paleta */
  --primary: #D97904;
  --primary-hover: #B86503;
  --primary-light: #FCE7CD;
  --black: #0D0D0D;
  --dark-gray: #404040;
  --medium-gray: #8C8C8C;
  --light-bg: #F2F2F2;
  --white: #FFFFFF;
  --border: #E5E7EB;
  --border-input: #CBD5E1;
  --success: #27AE60;
  --success-light: #D4F4DF;
  --danger: #C0392B;
  --danger-light: #FBDDD9;
  --warning: #F39C12;
  --warning-light: #FDEBD0;

  /* Espaçamentos */
  --radius: 6px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.12);

  /* Layout */
  --sidebar-w: 240px;
  --header-h: 64px;
}

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

html, body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--dark-gray);
  background: var(--light-bg);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: inherit; text-decoration: none; }

/* ===== Typography ===== */
.h1 { font-size: 28px; font-weight: 700; color: var(--black); letter-spacing: -0.02em; }
.h2 { font-size: 20px; font-weight: 600; color: var(--black); }
.h3 { font-size: 16px; font-weight: 600; color: var(--black); }
.caption { font-size: 11px; color: var(--medium-gray); }
.muted { color: var(--medium-gray); }

/* ===== Layout principal ===== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--black);
  color: var(--white);
  display: flex; flex-direction: column;
  position: fixed; left: 0; top: 0; bottom: 0;
  z-index: 50;
}

.sidebar__brand {
  height: var(--header-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 24px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.sidebar__logo {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 8px;
  display: grid; place-items: center;
  color: white; font-weight: 800; font-size: 16px;
  letter-spacing: -0.05em;
}

.sidebar__title {
  font-weight: 700; font-size: 17px;
  letter-spacing: -0.02em;
}
.sidebar__title small { display:block; font-weight:400; font-size:10px; color: var(--medium-gray); letter-spacing: 0.08em; text-transform: uppercase; }

.sidebar__nav { flex: 1; padding: 16px 12px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius);
  color: rgba(255,255,255,.65);
  font-weight: 500; font-size: 14px;
  cursor: pointer;
  transition: all .15s ease;
  margin-bottom: 2px;
}
.nav-item:hover { color: white; background: rgba(255,255,255,.05); }
.nav-item.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(217, 121, 4, .35);
}
.nav-item .icon { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar__footer {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.06);
  font-size: 12px; color: var(--medium-gray);
}
.sidebar__user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px;
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.sidebar__user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary);
  display: grid; place-items: center;
  color: white; font-weight: 600; font-size: 13px;
}
.sidebar__user-info { flex: 1; min-width: 0; }
.sidebar__user-name { color: white; font-size: 13px; font-weight: 500; }
.sidebar__user-email { color: var(--medium-gray); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn-logout {
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px solid rgba(255,255,255,.1);
  color: rgba(255,255,255,.7);
  border-radius: var(--radius);
  font-size: 12px;
  transition: all .15s;
}
.btn-logout:hover { background: rgba(255,255,255,.05); color: white; }

/* ===== Main area ===== */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex; flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--header-h);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 32px;
  position: sticky; top: 0; z-index: 40;
}
.topbar__title { font-size: 20px; font-weight: 600; color: var(--black); }
.topbar__actions { display: flex; align-items: center; gap: 12px; }

.alert-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: transform .15s;
}
.alert-badge:hover { transform: translateY(-1px); }
.alert-badge--danger { background: var(--danger-light); color: var(--danger); }
.alert-badge--warning { background: var(--warning-light); color: var(--warning); }

.content { padding: 32px; flex: 1; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-weight: 500; font-size: 14px;
  transition: all .15s ease;
  white-space: nowrap;
}
.btn--primary { background: var(--primary); color: white; }
.btn--primary:hover { background: var(--primary-hover); box-shadow: 0 4px 12px rgba(217,121,4,.3); }
.btn--secondary { background: white; color: var(--black); border: 1px solid var(--border-input); }
.btn--secondary:hover { background: var(--light-bg); border-color: var(--medium-gray); }
.btn--ghost { color: var(--dark-gray); }
.btn--ghost:hover { background: var(--light-bg); }
.btn--danger { background: var(--danger); color: white; }
.btn--danger:hover { background: #A93226; }
.btn--sm { padding: 6px 10px; font-size: 12px; }
.btn--icon { padding: 7px; }

/* ===== Inputs ===== */
.input, .select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  background: white;
  color: var(--dark-gray);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(217,121,4,.12);
}
.input--search { padding-left: 36px; background: white url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238C8C8C' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>") no-repeat 12px center; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 500; color: var(--dark-gray); }

/* ===== Cards ===== */
.card {
  background: white;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.card__header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.card__body { padding: 20px; }

/* ===== KPI ===== */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-grid--5 { grid-template-columns: repeat(5, 1fr); }
.kpi {
  background: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
  border-top: 3px solid var(--medium-gray);
  position: relative;
  transition: transform .15s, box-shadow .15s;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi--primary { border-top-color: var(--primary); }
.kpi--success { border-top-color: var(--success); }
.kpi--danger { border-top-color: var(--danger); }
.kpi__label { font-size: 12px; font-weight: 500; color: var(--medium-gray); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }
.kpi__value { font-size: 28px; font-weight: 700; color: var(--black); letter-spacing: -0.02em; }
.kpi--success .kpi__value { color: var(--success); }
.kpi--danger .kpi__value { color: var(--danger); }
.kpi--positive .kpi__value { color: var(--success); }
.kpi--negative .kpi__value { color: var(--danger); }
.kpi__sub { font-size: 12px; color: var(--medium-gray); margin-top: 4px; }

/* ===== Tabela ===== */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); background: white; }
.table { width: 100%; border-collapse: collapse; }
.table thead th {
  background: var(--light-bg);
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--dark-gray);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  color: var(--dark-gray);
}
.table tbody tr:nth-child(even) { background: rgba(242,242,242,.4); }
.table tbody tr:hover { background: var(--primary-light); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.table .num--positive { color: var(--success); }
.table .num--negative { color: var(--danger); }
.table .actions-cell { display: flex; gap: 4px; justify-content: flex-end; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--medium-gray);
}
.empty-state__icon { width: 48px; height: 48px; margin: 0 auto 12px; opacity: 0.4; }

/* ===== Badge ===== */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge--success { background: var(--success-light); color: var(--success); }
.badge--danger { background: var(--danger-light); color: var(--danger); }
.badge--neutral { background: var(--light-bg); color: var(--dark-gray); }
.badge--warning { background: var(--warning-light); color: #B8741A; }

/* ===== Filtros ===== */
.filters {
  background: white;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(13,13,13,.5);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  animation: fadeIn .15s ease;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: white;
  border-radius: var(--radius-lg);
  width: 90%; max-width: 560px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp .25s ease;
}
.modal--lg { max-width: 800px; }
.modal__header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal__body { padding: 24px; overflow-y: auto; }
.modal__footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
}
.btn-close { padding: 4px; color: var(--medium-gray); font-size: 24px; line-height: 1; }
.btn-close:hover { color: var(--black); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Tabs ===== */
.tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 12px 18px;
  font-weight: 500; font-size: 14px;
  color: var(--medium-gray);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all .15s;
}
.tab:hover { color: var(--dark-gray); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== Form grid ===== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-grid--3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }

/* ===== Charts container ===== */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 24px;
}
.chart-wrap { height: 320px; position: relative; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--black);
  color: white;
  padding: 14px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  z-index: 200;
  transform: translateY(100px);
  opacity: 0;
  transition: all .3s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast--success { background: var(--success); }
.toast--error { background: var(--danger); }

/* ===== Page sections ===== */
.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px;
}
.page-header__title h1 { font-size: 24px; font-weight: 700; color: var(--black); letter-spacing: -0.02em; }
.page-header__title p { color: var(--medium-gray); font-size: 13px; margin-top: 2px; }
.page-header__actions { display: flex; gap: 10px; }

.hidden { display: none !important; }

/* ===== Responsivo ===== */
@media (max-width: 1100px) {
  .kpi-grid, .kpi-grid--5, .charts-grid, .filters { grid-template-columns: repeat(2, 1fr); }
  .filters { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .kpi-grid, .kpi-grid--5, .charts-grid, .filters, .form-grid, .form-grid--3 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
}
