:root {
  --bg: #f5f7fa;
  --surface: #fff;
  --ink: #1f2933;
  --muted: #667085;
  --line: #dce3ea;
  --brand: #176b5b;
  --blue: #2f6f9f;
  --amber: #b7791f;
  --red: #b54747;
  --shadow: 0 16px 38px rgba(31,41,51,.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px 1fr; transition: grid-template-columns .2s ease; }
.sidebar { background: #132321; color: #fff; padding: 22px; display: flex; flex-direction: column; gap: 22px; transition: width .2s ease, padding .2s ease; }
.sidebar-toggle {
  position: fixed;
  left: 236px;
  top: 16px;
  z-index: 60;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--brand);
  box-shadow: 0 12px 30px rgba(31,41,51,.16);
  display: grid;
  place-items: center;
  transition: left .2s ease;
}
.sidebar-close, .sidebar-backdrop { display: none; }
body.sidebar-collapsed .app-shell { grid-template-columns: 78px 1fr; }
body.sidebar-collapsed .sidebar { padding: 18px 10px; align-items: center; }
body.sidebar-collapsed .sidebar-toggle { left: 92px; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-logo {
  width: 58px;
  height: 46px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #fff;
  overflow: hidden;
  padding: 3px;
}
.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.brand strong { display: block; line-height: 1.1; }
.brand span { display: block; color: #b8cac5; font-size: .82rem; margin-top: 3px; }
body.sidebar-collapsed .brand { justify-content: center; }
body.sidebar-collapsed .brand-logo { width: 48px; height: 42px; }
body.sidebar-collapsed .brand > div:not(.brand-logo), body.sidebar-collapsed .tenant-card { display: none; }
.sidebar-close {
  margin-left: auto;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px;
  background: rgba(255,255,255,.08);
  color: #fff;
}

.nav { display: grid; gap: 4px; }
.nav button {
  border: 0;
  background: transparent;
  color: #cfdbd8;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  border-radius: 8px;
  text-align: left;
}
.nav button i { width: 20px; text-align: center; color: #90aaa4; }
.nav button.active, .nav button:hover { background: rgba(255,255,255,.11); color: #fff; }
.nav button.active i, .nav button:hover i { color: #fff; }
body.sidebar-collapsed .nav button {
  width: 48px;
  height: 46px;
  justify-content: center;
  padding: 0;
  overflow: hidden;
  color: transparent;
  gap: 0;
}
body.sidebar-collapsed .nav button i { color: #cfdbd8; font-size: 1rem; }

.tenant-card { margin-top: auto; border: 1px solid rgba(255,255,255,.14); border-radius: 8px; padding: 14px; background: rgba(255,255,255,.06); }
.tenant-card span, .tenant-card small { display: block; color: #b8cac5; }
.tenant-card strong { display: block; margin: 4px 0; }

.main { padding: 24px; overflow: auto; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.topbar h1 { margin: 0; font-size: 1.75rem; letter-spacing: 0; }
.topbar p { margin: 6px 0 0; color: var(--muted); max-width: 760px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-actions .form-select { min-width: 240px; }
.alert-button {
  position: relative;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--brand);
}
.alert-button span {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--red);
  color: #fff;
  border-radius: 999px;
  min-width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  font-size: .72rem;
  font-weight: 800;
}

.ai-command {
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr minmax(280px, 460px);
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}
.ai-command strong, .ai-command span { display: block; }
.ai-command span { color: var(--muted); margin-top: 3px; }
.command-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 0 11px;
  background: #f8fafc;
}
.command-box input {
  border: 0;
  outline: 0;
  background: transparent;
  width: 100%;
  min-height: 42px;
}
.alerts-popover {
  display: none;
  position: absolute;
  right: 14px;
  top: 62px;
  width: min(360px, calc(100vw - 32px));
  z-index: 20;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(31,41,51,.22);
  padding: 10px;
}
.alerts-popover.active { display: grid; gap: 8px; }
.alerts-popover article {
  border-bottom: 1px solid var(--line);
  padding: 8px 4px;
}
.alerts-popover article:last-child { border-bottom: 0; }
.alerts-popover strong, .alerts-popover span, .alerts-popover small { display: block; }
.alerts-popover span, .alerts-popover small { color: var(--muted); }

.view { display: none; }
.view.active { display: block; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  border-top: 4px solid var(--brand);
}
.kpi span { display: block; color: var(--muted); font-size: .86rem; }
.kpi strong { display: block; margin-top: 7px; font-size: 1.5rem; letter-spacing: 0; }
.kpi.info { border-top-color: var(--blue); }
.kpi.warning { border-top-color: var(--amber); }
.kpi.danger { border-top-color: var(--red); }
.kpi.money { border-top-color: #2f9f87; }

.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.panel, .company-workspace { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 16px; }
.panel-head, .workspace-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.panel h2, .workspace-head h2 { margin: 0; font-size: 1.05rem; letter-spacing: 0; }
.chart-panel { min-height: 310px; }
.ai-panel { grid-column: 1 / -1; }

.list-stack { display: grid; gap: 10px; }
.list-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #fff;
}
.list-row strong { display: block; }
.list-row small { display: block; color: var(--muted); margin-top: 3px; }
.empty { border: 1px dashed var(--line); color: var(--muted); border-radius: 8px; padding: 14px; }
.week-calendar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}
.day-column {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 10px;
  min-height: 120px;
}
.day-column strong { display: block; margin-bottom: 8px; }
.day-column span {
  display: block;
  background: #fff;
  border-left: 3px solid var(--brand);
  border-radius: 6px;
  padding: 7px;
  margin-bottom: 6px;
  font-size: .86rem;
}
.day-column small, .day-column em { display: block; color: var(--muted); font-style: normal; }

.badge { border-radius: 999px; padding: 5px 9px; font-size: .78rem; font-weight: 700; background: #eef2f6; color: #52606d; }
.badge.ativa, .badge.concluida, .badge.recebido, .badge.recebida, .badge.paga, .badge.assinado, .badge.respondido, .badge.resolvido { background: #dff5ed; color: #176b5b; }
.badge.aberta, .badge.aberto, .badge.emitida, .badge.guia_emitida, .badge.onboarding, .badge.em_andamento { background: #e7f0fb; color: #2f5f9f; }
.badge.alta, .badge.atrasada, .badge.atrasado, .badge.rejeitado, .badge.suspensa { background: #fde5e2; color: #a33f3f; }
.badge.normal, .badge.pendente, .badge.aguardando_cliente { background: #fbefd8; color: #8c6316; }

.ai-prompts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.ai-prompts button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 12px; text-align: left; color: var(--ink); }

.company-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.company-item { border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 13px; display: grid; gap: 12px; cursor: pointer; }
.company-item:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.company-item strong { display: block; }
.company-item small { display: block; color: var(--muted); margin-top: 3px; }
.company-item footer { display: flex; justify-content: space-between; align-items: center; }

.company-workspace { margin-top: 16px; }
.eyebrow { color: var(--muted); text-transform: uppercase; font-size: .72rem; font-weight: 800; letter-spacing: .04em; }
.tabs { list-style: none; padding: 0; margin: 0 0 14px; display: flex; gap: 6px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: transparent; padding: 10px 8px; white-space: nowrap; color: var(--muted); font-weight: 700; border-bottom: 3px solid transparent; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-content-box { min-height: 260px; }

.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.summary-card { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.summary-card span { display: block; color: var(--muted); font-size: .82rem; }
.summary-card strong { display: block; margin-top: 4px; }

.table-wrap { overflow-x: auto; }
.table-wrap h3 { margin: 0 0 10px; font-size: 1rem; }
.modern-table { width: 100%; border-collapse: separate; border-spacing: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; }
.modern-table th, .modern-table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.modern-table th { background: #f2f6f8; color: var(--muted); font-size: .82rem; font-weight: 800; }
.modern-table tr:last-child td { border-bottom: 0; }

.module-header { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow); }
.module-header h2 { margin: 0; }
.module-header p { margin: 6px 0 0; color: var(--muted); }
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.module-card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 16px; box-shadow: var(--shadow); }
.module-card i { color: var(--brand); font-size: 1.3rem; }
.module-card strong { display: block; margin-top: 10px; }
.module-card small { display: block; color: var(--muted); margin-top: 4px; }
.module-activities { grid-column: 1 / -1; }
.operational-workspace { grid-column: 1 / -1; }
.workspace-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}
.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.module-search {
  min-width: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 0 10px;
  background: #f8fafc;
}
.module-search input {
  border: 0;
  outline: 0;
  background: transparent;
  min-height: 38px;
  width: 100%;
}
.xml-pipeline { grid-column: 1 / -1; border-left: 4px solid var(--brand); }
.xml-pipeline .panel-head small { color: var(--muted); display: block; margin-top: 4px; }
.drop-zone {
  border: 2px dashed var(--line);
  border-radius: 8px;
  padding: 28px;
  display: grid;
  place-items: center;
  text-align: center;
  gap: 8px;
  background: #f8fafc;
  cursor: pointer;
}
.drop-zone i { font-size: 2rem; color: var(--brand); }
.drop-zone span { color: var(--muted); }
.drop-zone input { display: none; }
.drop-zone.dragging { border-color: var(--brand); background: #eefaf6; }
.xml-preview { margin-top: 14px; }
.pipeline-flow {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 9px;
}
.pipeline-step {
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 8px;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 58px;
}
.pipeline-step span {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  font-size: .8rem;
  flex: 0 0 auto;
}
.pipeline-step strong { font-size: .86rem; line-height: 1.15; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  body.sidebar-collapsed .app-shell { grid-template-columns: 1fr; }
  .sidebar-toggle {
    left: 14px;
    top: 14px;
    width: 44px;
    height: 44px;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    z-index: 70;
    transform: translateX(-105%);
    transition: transform .22s ease;
    overflow-y: auto;
    box-shadow: 20px 0 70px rgba(31,41,51,.34);
  }
  body.sidebar-collapsed .sidebar {
    padding: 22px;
    align-items: stretch;
  }
  body.sidebar-collapsed .brand { justify-content: flex-start; }
  body.sidebar-collapsed .brand-logo { width: 58px; height: 46px; }
  body.sidebar-collapsed .brand > div:not(.brand-logo), body.sidebar-collapsed .tenant-card { display: block; }
  body.sidebar-collapsed .nav button {
    width: auto;
    height: auto;
    justify-content: flex-start;
    padding: 10px 11px;
    overflow: visible;
    color: #cfdbd8;
    gap: 10px;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(15,23,42,.46);
  }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .sidebar-close { display: grid; place-items: center; }
  .main { padding-top: 72px; }
  .topbar { align-items: stretch; }
  .topbar > div:first-child { padding-left: 48px; min-height: 44px; }
  .nav { grid-template-columns: 1fr; }
  .kpi-grid, .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .main { padding: 72px 14px 18px; }
  .sidebar { padding: 18px; }
  .brand-logo { width: 64px; height: 50px; }
  .brand strong { font-size: 1.08rem; }
  .brand span { font-size: .78rem; }
  .nav, .kpi-grid, .dashboard-grid { grid-template-columns: 1fr; }
  .nav button { min-height: 44px; font-size: .95rem; }
  .topbar { flex-direction: column; }
  .topbar > div:first-child { padding-left: 48px; }
  .topbar h1 { font-size: 1.45rem; }
  .topbar p { font-size: .9rem; }
  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 44px 1fr;
  }
  .topbar-actions .alert-button { width: 44px; }
  .topbar-actions .form-select,
  .topbar-actions .form-control,
  .topbar-actions .btn {
    width: 100%;
    min-width: 0;
  }
  .topbar-actions .form-select,
  .topbar-actions .form-control,
  .topbar-actions .btn {
    grid-column: 1 / -1;
  }
  .topbar-actions .alert-button {
    grid-column: 1;
    grid-row: 1;
  }
  .ai-command, .workspace-toolbar { grid-template-columns: 1fr; flex-direction: column; }
  .ai-command { padding: 12px; }
  .module-search { width: 100%; min-width: 0; }
  .list-row { align-items: flex-start; flex-direction: column; }
  .panel, .company-workspace, .module-header { padding: 14px; }
  .modern-table th, .modern-table td { padding: 9px; font-size: .86rem; }
}
