:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #111827;
  --muted: #667085;
  --line: #d9deea;
  --soft: #f3f5f9;
  --primary: #071a4d;
  --primary-dark: #031034;
  --gold: #c99a2e;
  --gold-dark: #9f7419;
  --danger: #c62828;
  --warning: #b7791f;
  --ok: #15803d;
  --blue: #1d4ed8;
  --sidebar: #051746;
  --shadow: 0 10px 24px rgba(5, 23, 70, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Segoe UI, Arial, sans-serif;
  font-size: 14px;
  min-height: 100vh;
  overflow-x: hidden;
}

body.sidebar-open {
  overflow: hidden;
}

a {
  color: var(--primary-dark);
}

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 260px;
  height: 100vh;
  background: linear-gradient(180deg, #04113a 0%, #071a4d 72%, #031034 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  overflow: hidden;
  z-index: 70;
}

.mobile-topbar,
.sidebar-overlay {
  display: none;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  padding: 4px 6px;
  flex-shrink: 0;
}

.brand-logo {
  width: 64px;
  height: 38px;
  object-fit: contain;
  border-radius: 6px;
}

.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--gold);
  color: #081640;
  font-weight: 800;
}

.brand-icon.big {
  width: 58px;
  height: 58px;
  font-size: 28px;
}

.brand small {
  display: block;
  color: #b7c2d0;
  margin-top: 3px;
}

.mobile-brand {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.mobile-brand-logo {
  width: 54px;
  height: 32px;
  object-fit: contain;
  border-radius: 5px;
  flex-shrink: 0;
}

.mobile-brand strong,
.mobile-brand small {
  display: block;
}

.mobile-brand small {
  color: #b7c2d0;
  font-size: 12px;
  margin-top: 2px;
}

.menu-toggle {
  border: 1px solid rgba(201, 154, 46, 0.55);
  background: rgba(201, 154, 46, 0.15);
  color: #fff;
  border-radius: 8px;
  padding: 9px 12px;
  font-weight: 800;
  cursor: pointer;
  min-height: 40px;
}

.sidebar nav,
.sidebar-nav {
  display: grid;
  gap: 4px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 6px;
  scrollbar-color: rgba(201, 154, 46, 0.5) transparent;
  scrollbar-width: thin;
}

.sidebar-nav::-webkit-scrollbar {
  width: 6px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(201, 154, 46, 0.45);
  border-radius: 999px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar nav a {
  color: #e9edf4;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.sidebar nav a:hover,
.sidebar nav a.active {
  background: rgba(201, 154, 46, 0.13);
  border-color: rgba(201, 154, 46, 0.48);
  color: #fff;
}

.nav-group-label {
  color: #d7c28a;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .04em;
  margin: 8px 12px 2px;
  text-transform: uppercase;
}

.sidebar nav a.nav-sub {
  margin-left: 10px;
  padding-left: 18px;
  border-left: 2px solid rgba(201, 154, 46, 0.35);
}

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid #34425d;
  padding-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-footer form {
  margin: 0;
}

.sidebar-footer button,
.account-link {
  border: 0;
  background: transparent;
  color: #d7fbe8;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  padding: 0;
}

.account-link {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  margin-left: 260px;
  padding: 28px;
  min-height: 100vh;
  max-width: 100%;
  overflow-x: hidden;
}

.main-login {
  margin-left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.page-header h1 {
  margin: 0;
  font-size: 28px;
}

.page-header p,
.subtle {
  margin: 6px 0 0;
  color: var(--muted);
}

.actions,
.row-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.row-actions {
  justify-content: flex-end;
}

.row-actions form,
.actions form {
  display: inline;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
  max-width: 100%;
  overflow-x: auto;
}

.card h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.divider {
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

.login-card {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 22px;
  width: min(920px, 92vw);
}

.login-hero {
  background: radial-gradient(circle at 50% 15%, #102b73 0%, #071a4d 45%, #031034 100%);
  color: #fff;
  border-radius: 8px;
  padding: 42px;
  box-shadow: var(--shadow);
}

.login-logo {
  width: min(360px, 100%);
  height: auto;
  display: block;
  margin-bottom: 18px;
}

.login-hero h1 {
  font-size: 42px;
  margin: 18px 0 8px;
}

.login-hero p {
  font-size: 17px;
  color: #d9e2ef;
  line-height: 1.6;
}

.form-card {
  display: grid;
  gap: 14px;
}

.form-card label {
  display: grid;
  gap: 6px;
  font-weight: 650;
  color: #384255;
}

.form-card label small {
  color: var(--muted);
  font-weight: 400;
}

.form-card input,
.form-card select,
.form-card textarea,
.toolbar input,
.toolbar select,
.inline-form select,
.editable input,
.editable select {
  width: 100%;
  border: 1px solid #c8d1df;
  border-radius: 6px;
  padding: 10px 11px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.form-card textarea {
  min-height: 90px;
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.form-grid.two-cols {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.form-grid.three-cols {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.form-grid .check {
  align-content: end;
  display: flex;
  gap: 8px;
  align-items: center;
}

.form-grid .check input {
  width: auto;
}

.compact {
  max-width: 380px;
}

.wide {
  display: grid;
  gap: 0;
}

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.toolbar-wrap {
  flex-wrap: wrap;
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  color: var(--muted);
  font-weight: 700;
}

.check-inline input {
  width: auto;
}

.toolbar input {
  max-width: 460px;
}

.toolbar select {
  max-width: 220px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #c8d1df;
  background: #fff;
  color: var(--text);
  text-decoration: none;
  border-radius: 6px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
  min-height: 38px;
}

.btn:hover {
  background: #f9fafb;
}

.btn.primary {
  background: var(--gold);
  border-color: var(--gold);
  color: #081640;
}

.btn.primary:hover {
  background: var(--gold-dark);
  border-color: var(--gold-dark);
  color: #fff;
}

.btn.danger {
  background: #fff5f5;
  border-color: #f3b8b8;
  color: var(--danger);
}

.btn.small {
  padding: 7px 9px;
  font-size: 12px;
  min-height: 30px;
}

.flash-wrap {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.flash {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.flash.success {
  border-color: #a7e6bb;
  background: #f0fdf4;
}

.flash.danger {
  border-color: #f3b8b8;
  background: #fff5f5;
}

.flash.warning {
  border-color: #efd08a;
  background: #fffbeb;
}

.flash.info {
  border-color: #aac9f5;
  background: #eff6ff;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 51, 0.58);
}

.confirm-overlay[hidden] {
  display: none;
}

.confirm-dialog {
  width: min(430px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(23, 32, 51, 0.25);
  padding: 20px;
}

.confirm-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.confirm-header h2 {
  margin: 0;
  font-size: 18px;
}

.confirm-header p {
  margin: 3px 0 0;
  color: var(--muted);
}

.confirm-logo {
  width: 62px;
  height: 36px;
  object-fit: contain;
}

.confirm-message {
  margin: 0 0 20px;
  color: #384255;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.confirm-actions .btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.confirm-actions .btn.danger:hover {
  background: #a61f1f;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.kpi-link {
  color: inherit;
  display: block;
  text-decoration: none;
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}

.kpi-link:hover {
  border-color: rgba(201, 154, 46, 0.72);
  box-shadow: 0 14px 30px rgba(5, 23, 70, 0.14);
  transform: translateY(-1px);
}

.kpi span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-bottom: 8px;
}

.kpi strong {
  font-size: 23px;
}

.kpi small {
  color: var(--muted);
  display: block;
  margin-top: 6px;
}

.kpi.danger strong {
  color: var(--danger);
}

.kpi.ok strong {
  color: var(--ok);
}

.kpi.warning strong {
  color: var(--warning);
}

.financial-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid #fed7aa;
  border-left: 5px solid #ea580c;
  border-radius: 8px;
  background: #fff7ed;
  color: #7c2d12;
  box-shadow: var(--shadow);
}

.financial-alert a {
  color: #7c2d12;
  font-weight: 800;
}

.soft-alert {
  border-color: #dbe4f0;
  border-left-color: var(--gold);
  background: #fffaf0;
  color: #4a3511;
}

.alert-actions {
  display: flex;
  gap: 12px;
  white-space: nowrap;
}

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.grid.three {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 18px;
}

.table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 11px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #667085;
  background: #f9fafb;
}

.table td small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.compact-table th,
.compact-table td {
  padding: 9px 8px;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.editable {
  min-width: 1250px;
}

.editable th,
.editable td {
  padding: 8px;
}

.editable input,
.editable select {
  min-width: 88px;
  padding: 8px;
}

.editable [name="item_description[]"],
.editable [name="product_id[]"] {
  min-width: 210px;
}

.editable [name="item_supplier[]"] {
  min-width: 140px;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
  background: #eef2ff;
  color: #3730a3;
}

.status-rascunho,
.status-novo {
  background: #f1f3f6;
  color: #475467;
}

.status-enviado,
.status-negociacao,
.status-andamento,
.status-gerado {
  background: #eff6ff;
  color: #1d4ed8;
}

.status-aprovado,
.status-aprovada,
.status-assinado,
.status-concluido,
.status-pago {
  background: #ecfdf5;
  color: #047857;
}

.status-recusado,
.status-cancelado,
.status-cancelada,
.status-atrasado {
  background: #fff5f5;
  color: #b42318;
}

.status-pendente,
.status-aberta {
  background: #fffbeb;
  color: #92400e;
}

.muted {
  color: var(--muted);
  text-align: center;
}

.late-row {
  background: #fff7ed;
}

.summary-bar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
  background: rgba(245, 247, 250, 0.94);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin: 2px 0 18px;
}

.summary-bar div {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.summary-bar span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.summary-bar strong {
  font-size: 16px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title h2 {
  margin: 0;
}

.hint {
  color: var(--muted);
  background: #f9fafb;
  border: 1px dashed #c8d1df;
  padding: 10px;
  border-radius: 8px;
  margin-top: 10px;
}

.inline-form {
  display: flex;
  gap: 10px;
  align-items: center;
}

.progress {
  width: 110px;
  height: 9px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--primary);
}

.export-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
}

.export-item {
  display: grid;
  gap: 5px;
  min-height: 92px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--text);
  text-decoration: none;
}

.export-item:hover {
  border-color: var(--primary);
  background: #f0fdfa;
}

.export-item span {
  color: var(--muted);
  line-height: 1.35;
}

.flash + .page-header {
  margin-top: 8px;
}

@media (max-width: 1100px) {
  .mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    background: #04113a;
    color: #fff;
    border-bottom: 1px solid rgba(201, 154, 46, 0.35);
    box-shadow: 0 8px 20px rgba(5, 23, 70, 0.16);
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(300px, 88vw);
    height: 100vh;
    transform: translateX(-105%);
    transition: transform .2s ease;
    z-index: 100;
    overflow: hidden;
    box-shadow: 18px 0 34px rgba(0, 0, 0, 0.24);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 90;
  }

  .sidebar nav,
  .sidebar-nav {
    flex: 1 1 auto;
    max-height: none;
    overflow-y: auto;
  }

  .main {
    margin-left: 0;
    padding: 18px;
    width: 100%;
  }

  .kpi-grid,
  .export-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid.two,
  .grid.three,
  .login-card,
  .form-grid,
  .form-grid.two-cols,
  .form-grid.three-cols {
    grid-template-columns: 1fr 1fr;
  }

  .summary-bar {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 700px) {
  .main {
    padding: 16px;
  }

  .main-login {
    padding: 16px;
  }

  .form-grid,
  .form-grid.two-cols,
  .form-grid.three-cols,
  .grid.two,
  .grid.three,
  .kpi-grid,
  .export-grid,
  .login-card {
    grid-template-columns: 1fr;
  }

  .page-header {
    display: grid;
    gap: 12px;
  }

  .actions,
  .row-actions,
  .toolbar,
  .inline-form {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    align-items: stretch;
  }

  .actions form,
  .row-actions form {
    width: 100%;
  }

  .btn,
  .actions .btn,
  .row-actions .btn,
  .row-actions button,
  .toolbar input,
  .toolbar select,
  .inline-form select,
  .inline-form button {
    width: 100%;
    max-width: none;
  }

  .summary-bar {
    grid-template-columns: 1fr;
  }

  .table {
    font-size: 12px;
    min-width: 680px;
  }

  .card {
    padding: 14px;
  }

  .login-hero {
    padding: 24px;
  }

  .login-logo {
    width: min(260px, 100%);
  }

  .login-hero h1 {
    font-size: 30px;
  }

  .login-hero p {
    font-size: 15px;
  }

  .mobile-brand small {
    display: none;
  }

  .mobile-brand-logo {
    width: 48px;
    height: 28px;
  }
}

/* melhorias operacionais */
.mobile-topbar-actions { display:flex; align-items:center; gap:8px; }
.notification-pill { position:relative; display:inline-flex; align-items:center; justify-content:center; min-width:40px; height:40px; border:1px solid rgba(201,154,46,.55); border-radius:12px; color:#fff; text-decoration:none; background:rgba(201,154,46,.14); }
.notification-pill span, .nav-count { display:inline-flex; align-items:center; justify-content:center; min-width:18px; height:18px; padding:0 5px; border-radius:999px; background:#dc2626; color:#fff; font-size:11px; font-weight:800; margin-left:6px; }
.notification-pill span { position:absolute; right:-6px; top:-6px; margin-left:0; }
.badge.ok { background:#dcfce7; color:#166534; }
.badge.danger { background:#fee2e2; color:#991b1b; }
code { background:#f1f5f9; padding:2px 5px; border-radius:6px; }
.span-2 { grid-column: span 2; }
@media (max-width:700px){ .span-2 { grid-column: span 1; } }

/* ajustes aluguel/estoque/mobile final */
.backbar {
  margin: -8px 0 14px;
}

.action-compact {
  gap: 6px;
  justify-content: flex-start;
}

.action-compact .btn,
.action-compact button {
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .sidebar {
    height: 100dvh;
    max-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .sidebar-nav {
    flex: 1 1 auto;
    min-height: 0;
    max-height: calc(100dvh - 138px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 28px;
  }

  .sidebar-footer {
    flex-shrink: 0;
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 700px) {
  .table-scroll {
    max-width: 100%;
    overflow-x: auto;
  }

  .table {
    min-width: 760px;
  }

  .action-compact {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .action-compact .btn,
  .action-compact button,
  .action-compact form {
    width: 100%;
  }
}
