/**
 * Calculadora de Custo Efetivo - Estilo App
 * Mobile-first, PWA-like
 */

:root {
  --primary: #0f766e;
  --primary-light: #14b8a6;
  --primary-dark: #0d5c55;
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xl: 24px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}

/* Header estilo app */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 1rem 1.25rem;
  padding-top: calc(0.75rem + var(--safe-top));
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

.app-header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 480px;
  margin: 0 auto;
}

.app-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-admin-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  color: white;
  text-decoration: none;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.15);
  -webkit-tap-highlight-color: transparent;
}

.app-admin-btn:active {
  background: rgba(255, 255, 255, 0.25);
}

/* Conteúdo rolável */
.app-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  padding-bottom: calc(1rem + 80px + var(--safe-bottom));
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

/* Cards estilo app */
.app-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card-hero {
  padding: 1.5rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
}

.card-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.9;
  margin-bottom: 0.5rem;
}

.card-hero .card-label {
  opacity: 0.85;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.card-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* Input TPV destaque */
.input-money-app {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.currency-symbol {
  font-size: 1.5rem;
  font-weight: 600;
  opacity: 0.9;
}

.input-money-app input {
  flex: 1;
  background: transparent;
  border: none;
  font-size: 2rem;
  font-weight: 700;
  color: white;
  letter-spacing: -0.02em;
  min-width: 0;
}

.input-money-app input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

.input-money-app input:focus {
  outline: none;
}

/* Select estilo app */
.select-wrapper {
  position: relative;
}

.select-wrapper select {
  width: 100%;
  padding: 1rem 2.5rem 1rem 1rem;
  font-size: 1rem;
  background: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  appearance: none;
  cursor: pointer;
  color: var(--text);
}

.select-wrapper select:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--primary);
}

.select-arrow {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.25rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* Fees card */
.fees-card {
  background: var(--bg);
}

.fees-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1.5rem;
}

.fees-group h4 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  grid-column: 1 / -1;
}

.fee-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  font-size: 0.9rem;
}

.fee-label {
  color: var(--text-muted);
}

.fee-value {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.95rem;
}

/* Distribution */
.distribution-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.dist-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.dist-item label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.dist-item input {
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
}

.dist-item input:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--primary);
}

.distribution-total {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  margin-top: 1rem;
  padding: 1rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 1rem;
}

.distribution-total strong {
  font-size: 1.25rem;
  color: var(--primary);
}

.distribution-total small {
  color: var(--text-muted);
}

/* Form row compacto */
.form-row-app {
  display: grid;
  grid-template-columns: 1fr 1fr 1.5fr;
  gap: 0.75rem;
}

.field-app {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-app label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.field-app input {
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
}

.field-app input:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--primary);
}

/* Espaço para botão fixo */
.bottom-spacer {
  height: 1rem;
}

/* Footer fixo estilo app */
.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1rem 1.25rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
  background: linear-gradient(180deg, rgba(241, 245, 249, 0) 0%, var(--bg) 20%);
  max-width: 480px;
  margin: 0 auto;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
}

.btn-app-primary {
  width: 100%;
  padding: 1rem 1.5rem;
  min-height: 56px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border: none;
  border-radius: var(--radius-xl);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 8px 24px rgba(15, 118, 110, 0.4);
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s, box-shadow 0.15s;
}

.btn-app-primary:active {
  transform: scale(0.98);
}

.btn-icon {
  font-size: 1.25rem;
  opacity: 0.9;
}

/* Resultado - card destacado */
.result-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-top: 1rem;
  box-shadow: var(--shadow);
  animation: slideUp 0.3s ease;
}

.result-card.hidden {
  display: none;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.result-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.result-close {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg);
  border-radius: 50%;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.result-close:hover,
.result-close:active {
  background: var(--border);
}

.result-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.result-details {
  margin-bottom: 1.25rem;
}

.result-detail-item {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.result-detail-item:last-child {
  border-bottom: none;
}

.result-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.result-detail-amount {
  font-weight: 700;
  color: var(--primary);
  font-size: 1.05rem;
}

.result-detail-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding-left: 0.5rem;
}

.result-detail-breakdown small {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.result-detail-breakdown small.subtotal {
  font-weight: 600;
  color: var(--text);
}

.result-main {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1.25rem;
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.12) 0%, rgba(15, 118, 110, 0.06) 100%);
  border-radius: var(--radius-sm);
}

.result-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.result-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.result-percent {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary-dark);
}

.result-details ul {
  list-style: none;
}

.error-msg {
  color: #dc2626;
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* Desktop - centralizar */
@media (min-width: 481px) {
  .app-header-content,
  .app-content,
  .app-footer {
    max-width: 480px;
    box-shadow: 0 0 0 1px var(--border);
  }

  .app-content {
    padding-bottom: calc(1rem + 90px);
  }

  .app-footer {
    border-radius: var(--radius) var(--radius) 0 0;
  }
}

/* Tablet/Desktop - mais colunas */
@media (min-width: 640px) {
  .distribution-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .fees-grid {
    grid-template-columns: 1fr 2fr;
  }

  .form-row-app {
    grid-template-columns: 1fr 1fr 2fr;
  }
}

@media (min-width: 768px) {
  .distribution-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}
