* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--color-background);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.45;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  min-height: 100vh;
  height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 66px minmax(0, 1fr);
  align-items: stretch;
}

.topbar {
  grid-column: 1 / -1;
  height: 66px;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--color-accent);
  color: #fff;
  font-weight: 800;
}

.brand-company-logo {
  width: 208px;
  height: 56px;
  box-sizing: border-box;
  display: block;
  padding: 0;
  background: transparent;
  object-fit: contain;
  object-position: left center;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar {
  background: var(--color-primary-dark);
  color: rgba(255, 255, 255, 0.88);
  display: block;
  align-self: stretch;
  height: 100%;
  min-height: 0;
  box-sizing: border-box;
  position: relative;
  padding: 12px;
  overflow: hidden;
}

.sidebar > nav {
  max-height: calc(100% - 78px);
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.sidebar-product-brand {
  width: 100%;
  min-height: 64px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 5px 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.13);
  opacity: 0.9;
  position: static;
  margin-top: 10px;
  background: var(--color-primary-dark);
  z-index: auto;
}

.sidebar-product-mark {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
}

.sidebar-product-mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.sidebar-product-copy {
  min-width: 0;
  display: grid;
  line-height: 1;
}

.sidebar-product-copy strong {
  display: flex;
  align-items: baseline;
  color: #FFFFFF;
  font-size: 15px;
  font-weight: 400;
  white-space: nowrap;
}

.sidebar-product-copy strong span,
.sidebar-product-copy strong b {
  font: inherit;
}

.sidebar-product-copy strong b {
  color: #159FA8;
}

.sidebar-product-copy small {
  margin-top: 5px;
  color: rgba(255, 255, 255, 0.62);
  font-size: 9px;
  font-weight: 400;
  white-space: nowrap;
}

.nav-section {
  margin: 10px 0 0;
}

.sidebar > nav .nav-section + .nav-section {
  margin-top: 18px;
}

.sidebar > nav .nav-section:last-child {
  margin-bottom: 0;
}

.nav-title {
  color: rgba(255, 255, 255, 0.56);
  font-size: 11px;
  font-weight: 700;
  margin: 8px 10px;
  text-transform: uppercase;
}

.nav-link {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 7px;
  padding: 8px 10px;
  color: rgba(255, 255, 255, 0.86);
}

.nav-link.has-counter {
  position: relative;
}

.nav-counter {
  min-width: 20px;
  height: 20px;
  margin-left: auto;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #1d3858;
  border-radius: 10px;
  background: #d93f4c;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.nav-indicators {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
}

.nav-indicators .nav-counter {
  min-width: 18px;
  height: 18px;
  margin-left: 0;
  padding: 0 4px;
  border-width: 1px;
  font-size: 9px;
}

.whatsapp-unread-counter { background: #168c68; }
.whatsapp-attention-counter { background: #c9820b; }
.whatsapp-overdue-counter { background: #d3414b; }

.nav-link.active .nav-counter {
  border-color: #008b94;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.nav-link.active {
  background: linear-gradient(90deg, #009DA5, #00848D);
  box-shadow: inset 3px 0 0 rgba(255, 255, 255, 0.18);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.main {
  min-width: 0;
  padding: 16px 14px 20px;
}

@media (min-width: 981px) {
  body {
    height: 100vh;
    overflow: hidden;
  }

  .app-shell {
    min-height: 0;
    overflow: hidden;
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    height: auto;
  }

  .sidebar > nav {
    flex: 0 1 auto;
    max-height: none;
  }

  .sidebar-product-brand {
    flex: 0 0 auto;
    margin-top: auto;
  }

  .main {
    min-height: 0;
    overflow-y: auto;
  }
}

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

.page-title {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.page-subtitle {
  color: var(--color-muted);
  margin: 4px 0 0;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.panel-header {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border);
}

.panel-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.panel-body {
  padding: 14px;
}

.metric {
  padding: 14px;
}

.metric-label {
  color: var(--color-muted);
  font-size: 13px;
}

.metric-value {
  font-size: 28px;
  font-weight: 800;
  margin-top: 4px;
}

.metric-foot {
  color: var(--color-muted);
  font-size: 12px;
  margin-top: 6px;
}

.btn,
button.btn {
  min-height: 36px;
  border: 0;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--color-accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.btn:hover {
  background: var(--color-accent-hover);
}

.btn.secondary {
  background: #EEF3F6;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn.danger {
  background: var(--color-danger);
}

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
  background: #EDF3F8;
  color: var(--color-primary);
}

.badge.success {
  background: rgba(21, 150, 106, 0.12);
  color: var(--color-success);
}

.badge.warning {
  background: rgba(217, 145, 24, 0.14);
  color: #9A650F;
}

.badge.danger {
  background: rgba(200, 72, 72, 0.12);
  color: var(--color-danger);
}

.form-card {
  width: min(420px, calc(100vw - 32px));
  margin: 8vh auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  padding: 24px;
}

.form-title {
  margin: 0 0 4px;
  font-size: 24px;
}

.form-subtitle {
  margin: 0 0 20px;
  color: var(--color-muted);
}

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--color-border);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--color-text);
  background: #fff;
  font: inherit;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(0, 157, 165, 0.14);
  outline: none;
}

.alert {
  border-radius: 7px;
  padding: 10px 12px;
  margin-bottom: 14px;
  border: 1px solid var(--color-border);
  background: #fff;
}

.alert.error {
  border-color: rgba(200, 72, 72, 0.28);
  color: #8D2727;
  background: rgba(200, 72, 72, 0.08);
}

.alert.success {
  border-color: rgba(21, 150, 106, 0.24);
  color: #0C6C4B;
  background: rgba(21, 150, 106, 0.08);
}

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

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

.table th {
  color: var(--color-muted);
  font-size: 12px;
  text-transform: uppercase;
}

.table.compact th,
.table.compact td {
  padding: 8px 10px;
  font-size: 13px;
}

.table-wrap {
  overflow-x: auto;
}

.muted {
  color: var(--color-muted);
  font-size: 12px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 160px 160px auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  margin-bottom: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 14px;
}

.span-2 {
  grid-column: span 2;
}

.form-actions,
.action-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.customer-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.detail-grid > div,
.line-item {
  display: grid;
  gap: 3px;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
}

.line-item:last-child {
  border-bottom: 0;
}

.finance-settings-grid,
.finance-form-layout,
.finance-detail-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.finance-payments-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
}

.finance-toolbar {
  grid-template-columns: minmax(260px, 1fr) 220px auto;
}

.finance-methods {
  display: grid;
  gap: 10px;
}

.finance-method-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 130px 160px minmax(230px, 1.25fr) 104px auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: #F8FBFC;
}

.finance-method-row .form-group {
  margin-bottom: 0;
}

.finance-method-active {
  min-height: 42px;
  align-self: end;
}

.finance-method-reference .input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
