/* ============================================================
   Multi Soluções Ltda — Design System
   Dark Navy + Sky Blue + Amber
   ============================================================ */

:root {
  --bg: #0B1929;
  --surface: #112240;
  --elevated: #1A3358;
  --border: #1E3A5F;
  --primary: #38BDF8;
  --primary-d: #0EA5E9;
  --primary-glow: rgba(56, 189, 248, .15);
  --accent: #F59E0B;
  --success: #34D399;
  --danger: #F87171;
  --warning: #FBBF24;
  --text: #E2E8F0;
  --text-muted: #94A3B8;
  --text-dim: #64748B;
  --sidebar: 260px;
  --topbar: 60px;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, .4);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  color: var(--primary-d);
}

/* ── SCROLLBAR ───────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--elevated);
  border-radius: 3px;
}

/* ═══════════════════════════════════════════
   LOGIN
═══════════════════════════════════════════ */
body.login-mode {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 20% 50%, #0e2a4a 0%, var(--bg) 60%);
}

#login-wrapper {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  animation: fadeUp .4s ease;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.logo-icon {
  font-size: 48px;
  margin-bottom: 10px;
}

.login-logo h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.login-logo p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.login-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 16px;
}

/* ═══════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════ */
body.app-mode {
  display: block;
}

#app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── SIDEBAR ───────────────────────────── */
#sidebar {
  width: var(--sidebar);
  min-width: var(--sidebar);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform .3s cubic-bezier(.4, 0, .2, 1);
  z-index: 200;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  font-size: 28px;
  flex-shrink: 0;
}

.sidebar-brand {
  flex: 1;
  min-width: 0;
}

.brand-name {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: 10px;
  color: var(--text-dim);
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 0;
}

.nav-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-dim);
  padding: 16px 16px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--text-muted);
  font-size: 13px;
  transition: all .15s;
  border-left: 3px solid transparent;
  position: relative;
}

.nav-item:hover {
  background: var(--primary-glow);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-glow);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}

.nav-item .ic {
  width: 20px;
  text-align: center;
  font-size: 15px;
  flex-shrink: 0;
}

.badge-danger {
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
  margin-left: auto;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

.user-avatar {
  width: 34px;
  height: 34px;
  background: var(--primary);
  color: var(--bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 10px;
  color: var(--text-dim);
}

.btn-logout {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 6px;
  transition: color .15s;
}

.btn-logout:hover {
  color: var(--danger);
}

/* ── MAIN WRAPPER ── */
#main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  /* overflow:clip prevents scroll without clipping position:absolute children */
  overflow: clip;
  min-width: 0;
}

#topbar {
  height: var(--topbar);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  flex-shrink: 0;
}

#menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

#page-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

#page-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 24px;
}

/* ═══════════════════════════════════════════
   COMPONENTS
═══════════════════════════════════════════ */

/* ── CARDS ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  /* needed so absolute dropdowns inside cards can overflow card bounds */
  overflow: visible;
}

/* ── AUTOCOMPLETE DROPDOWNS (global) ── */
/* Any div used as a search dropdown should float above everything */
[id$="-dropdown"],
[id$="-drop"],
.ac-drop {
  z-index: 9999 !important;
  position: absolute;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* Metric cards */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.metric-card.blue::before {
  background: var(--primary);
}

.metric-card.green::before {
  background: var(--success);
}

.metric-card.amber::before {
  background: var(--accent);
}

.metric-card.red::before {
  background: var(--danger);
}

.metric-icon {
  font-size: 28px;
}

.metric-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.metric-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(.97);
}

.btn-primary {
  background: var(--primary);
  color: #0b1929;
}

.btn-primary:hover {
  background: var(--primary-d);
}

.btn-success {
  background: var(--success);
  color: #0b1929;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-warning {
  background: var(--accent);
  color: #0b1929;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--elevated);
  color: var(--text);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
  justify-content: center;
  padding: 12px;
}

.btn-icon {
  padding: 7px 9px;
}

.btn[disabled] {
  opacity: .5;
  cursor: not-allowed;
}

/* ── FORMS ── */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

input,
select,
textarea {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-dim);
}

select option {
  background: var(--surface);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

/* ── TABLES ── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  background: var(--elevated);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 11px 14px;
  text-align: left;
  white-space: nowrap;
}

tbody td {
  padding: 11px 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

tbody tr:hover td {
  background: var(--primary-glow);
}

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

/* ── STATUS BADGES ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-rascunho {
  background: rgba(100, 116, 139, .2);
  color: #94A3B8;
}

.badge-enviado {
  background: rgba(56, 189, 248, .15);
  color: #38BDF8;
}

.badge-aprovado {
  background: rgba(52, 211, 153, .15);
  color: #34D399;
}

.badge-recusado {
  background: rgba(248, 113, 113, .15);
  color: #F87171;
}

.badge-cancelado {
  background: rgba(100, 116, 139, .15);
  color: #64748B;
}

.badge-aberta {
  background: rgba(56, 189, 248, .15);
  color: #38BDF8;
}

.badge-fechada {
  background: rgba(52, 211, 153, .15);
  color: #34D399;
}

.badge-alerta {
  background: rgba(245, 158, 11, .15);
  color: #F59E0B;
}

.badge-ok {
  background: rgba(52, 211, 153, .15);
  color: #34D399;
}

/* ── SEARCH BAR ── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-input {
  max-width: 280px;
}

/* ── MODAL ── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .7);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
  animation: fadeIn .2s;
}

#modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 580px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
  animation: fadeUp .25s ease;
}

.modal-wide {
  max-width: 820px !important;
}

#modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  border-radius: 14px 14px 0 0;
}

#modal-header h3 {
  font-size: 15px;
  font-weight: 700;
}

#modal-header button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 6px;
}

#modal-header button:hover {
  color: var(--text);
}

#modal-body {
  padding: 20px;
}

/* ── TOAST ── */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  min-width: 260px;
  max-width: 360px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: slideIn .25s ease;
  font-size: 13px;
}

.toast.success {
  border-left: 4px solid var(--success);
}

.toast.error {
  border-left: 4px solid var(--danger);
}

.toast.info {
  border-left: 4px solid var(--primary);
}

.toast.warning {
  border-left: 4px solid var(--warning);
}

/* ── ALERTS ── */
.alert {
  padding: 10px 14px;
  border-radius: 7px;
  font-size: 13px;
  margin-bottom: 12px;
}

.alert-danger {
  background: rgba(248, 113, 113, .1);
  border: 1px solid rgba(248, 113, 113, .3);
  color: var(--danger);
}

.alert-warning {
  background: rgba(251, 191, 36, .1);
  border: 1px solid rgba(251, 191, 36, .3);
  color: var(--warning);
}

.alert-success {
  background: rgba(52, 211, 153, .1);
  border: 1px solid rgba(52, 211, 153, .3);
  color: var(--success);
}

/* ── LOADING ── */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-dim);
  font-size: 14px;
}

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--elevated) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}

/* ── PAGE HEADER ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.page-header h2 {
  font-size: 18px;
  font-weight: 700;
}

/* ── EMPTY STATE ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 14px;
}

/* ── TABS ── */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--elevated);
  padding: 4px;
  border-radius: 9px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.tab-btn {
  flex: 1;
  min-width: 80px;
  text-align: center;
  padding: 7px 12px;
  border-radius: 6px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
}

.tab-btn.active {
  background: var(--primary);
  color: #0b1929;
  font-weight: 600;
}

/* ── DIVIDER ── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ═══════════════════════════════════════════
   ORÇAMENTO — ITENS TABLE
═══════════════════════════════════════════ */
.items-table input {
  padding: 6px 8px;
  font-size: 12px;
  border-radius: 5px;
}

.items-table td {
  padding: 6px 8px;
}

.items-total-row td {
  background: var(--elevated);
  font-weight: 700;
  border-top: 2px solid var(--border);
}

/* ═══════════════════════════════════════════
   ANIMATIONS
═══════════════════════════════════════════ */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }

  100% {
    background-position: 200% 0;
  }
}

/* ─── BASE field-row: slightly smaller min so 2-col survives medium phones ─── */
.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
}

/* ── Utility: makes inline flex rows stack on mobile ── */
.flex-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.flex-row>* {
  min-width: 0;
}

/* ─── SIDEBAR OVERLAY — MOBILE ─────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  z-index: 199;
  backdrop-filter: blur(2px);
}

/* ─── RESPONSIVE ──────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --sidebar: 82vw;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    border-right: none;
    box-shadow: 4px 0 40px rgba(0, 0, 0, .6);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #sidebar-overlay.open {
    display: block;
  }

  .sidebar-close {
    display: block;
  }

  #menu-toggle {
    display: block;
  }

  /* Main content */
  #page-content {
    padding: 14px 12px;
    overflow-x: hidden;
  }

  /* Metric grid */
  .metric-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  /* Forms */
  .field-row {
    grid-template-columns: 1fr;
  }

  /* Modal */
  #modal-overlay {
    padding: 10px;
    align-items: flex-end;
  }

  #modal-box {
    max-width: 100% !important;
    max-height: 92vh;
    border-radius: 14px 14px 0 0;
  }

  .modal-wide {
    max-width: 100% !important;
  }

  #modal-header {
    padding: 14px 16px;
  }

  #modal-body {
    padding: 14px 16px;
  }

  /* Toolbar */
  .toolbar {
    gap: 8px;
  }

  .search-input {
    max-width: 100%;
    min-width: 0;
    flex: 1;
  }

  /* Tabs — allow wrap */
  .tabs {
    flex-wrap: wrap;
  }

  .tab-btn {
    flex: 0 1 auto;
    min-width: 0;
  }

  /* Tables — shrink font slightly */
  tbody td,
  thead th {
    font-size: 12px;
    padding: 9px 10px;
  }

  /* Page header — stack on very narrow */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .page-header h2 {
    font-size: 16px;
  }

  /* Hide non-essential table cols on mobile via data attribute */
  [data-mobile="hide"] {
    display: none;
  }

  /* Card padding */
  .card {
    padding: 14px;
  }

  /* Inline flex rows used throughout forms/cards */
  .flex-row {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  :root {
    --sidebar: 90vw;
  }

  #page-content {
    padding: 10px 8px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar .btn {
    justify-content: center;
  }

  .search-input {
    max-width: 100%;
    width: 100%;
  }

  /* Buttons full-width in toolbars */
  .page-header .btn {
    width: 100%;
    justify-content: center;
  }

  /* Modal fully covers screen */
  #modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  #modal-box {
    border-radius: 14px 14px 0 0;
    max-height: 95vh;
  }

  /* Metric cards — smaller text */
  .metric-value {
    font-size: 22px;
  }

  .metric-icon {
    font-size: 22px;
  }

  /* Stack items table actions */
  .items-table td {
    padding: 5px 6px;
  }

  .items-table input {
    padding: 5px 6px;
    font-size: 11px;
  }
}

/* ─── Orçamento Form Grid ───────────────────────────── */
.orc-form-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  align-items: start;
}

.orc-sidebar-card {
  position: sticky;
  top: 20px;
}

@media (max-width: 768px) {
  .orc-form-grid {
    grid-template-columns: 1fr;
  }

  .orc-sidebar-card {
    position: static;
  }
}

/* ─── PRINT (bonus) ──────────────────────────────── */
@media print {

  #sidebar,
  #topbar,
  .btn,
  .toolbar,
  .tabs,
  #toast-container {
    display: none !important;
  }

  #page-content {
    padding: 0;
    overflow: visible;
  }

  body {
    background: #fff;
    color: #000;
  }
}