* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: #1e293b;
  border-right: 1px solid #334155;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  padding: 1.2rem 1rem;
  border-bottom: 1px solid #334155;
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.sidebar-logo {
  width: 42px;
  height: 42px;
  border-radius: 10px;
}

.sidebar-header h1 {
  font-size: 1.2rem;
  color: #F58220;
  line-height: 1.2;
}

.badge {
  background: #7c3aed;
  color: white;
  font-size: 0.65rem;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  text-transform: uppercase;
  font-weight: 700;
}

.nav-menu {
  list-style: none;
  padding: 0.5rem 0;
}

.nav-item {
  padding: 0.7rem 1.2rem;
  cursor: pointer;
  color: #94a3b8;
  font-size: 0.9rem;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  color: #e2e8f0;
  background: #0f172a44;
}

.nav-item.active {
  color: #F58220;
  background: #0f172a88;
  border-left-color: #F58220;
}

.content {
  margin-left: 220px;
  flex: 1;
  padding: 2rem;
  min-height: 100vh;
}

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

.section h2 {
  font-size: 1.4rem;
  color: #F58220;
  margin-bottom: 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #334155;
}

.card {
  background: #1e293b;
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.form-card { border: 1px solid #334155; }

.form-group {
  margin-bottom: 0.8rem;
  flex: 1;
}

.form-group label {
  display: block;
  margin-bottom: 0.25rem;
  color: #94a3b8;
  font-size: 0.85rem;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.5rem 0.8rem;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #e2e8f0;
  font-size: 0.9rem;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: #F58220;
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.btn {
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: opacity 0.15s;
}

.btn:hover { opacity: 0.85; }

.btn-primary { background: #F58220; color: #0f172a; }
.btn-secondary { background: #334155; color: #e2e8f0; }
.btn-danger { background: #ef4444; color: white; }
.btn-success { background: #22c55e; color: white; }
.btn-warning { background: #f59e0b; color: #0f172a; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.75rem; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.toolbar label {
  color: #94a3b8;
  font-size: 0.85rem;
}

.toolbar select {
  padding: 0.4rem 0.8rem;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #e2e8f0;
  font-size: 0.85rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #1e293b;
  border-radius: 10px;
  overflow: hidden;
}

.data-table thead {
  background: #334155;
}

.data-table th {
  padding: 0.7rem 1rem;
  text-align: left;
  font-size: 0.8rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table td {
  padding: 0.7rem 1rem;
  font-size: 0.85rem;
  border-bottom: 1px solid #0f172a;
}

.data-table tbody tr:hover {
  background: #0f172a44;
}

.status-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 10px;
  font-weight: 600;
}

.status-ocupada { background: #22c55e22; color: #22c55e; }
.status-vazia { background: #64748b22; color: #64748b; }
.status-vendida { background: #F5822022; color: #F58220; }
.status-manutencao { background: #f59e0b22; color: #f59e0b; }
.status-aprovado { background: #22c55e22; color: #22c55e; }
.status-pendente { background: #f59e0b22; color: #f59e0b; }
.status-rejeitado { background: #ef444422; color: #ef4444; }
.status-cancelado { background: #64748b22; color: #64748b; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: #1e293b;
  border-radius: 10px;
  padding: 1.2rem;
  text-align: center;
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: #F58220;
}

.stat-card .stat-label {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-top: 0.3rem;
}

.portas-visual {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.porta-card {
  background: #1e293b;
  border-radius: 10px;
  padding: 1rem;
  border: 2px solid #334155;
}

.porta-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
}

.porta-card-num {
  font-size: 1.3rem;
  font-weight: 700;
  color: #F58220;
}

.porta-card-product {
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}

.porta-card-price {
  font-size: 0.85rem;
  color: #22c55e;
  font-weight: 600;
  margin-bottom: 0.8rem;
}

.porta-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.porta-card select {
  width: 100%;
  padding: 0.35rem;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 4px;
  color: #e2e8f0;
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
}

.image-picker {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 0.8rem;
}

.image-picker-preview {
  width: 100%;
  max-width: 200px;
  height: 120px;
  border-radius: 6px;
  background: #1e293b;
  border: 2px dashed #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.6rem;
  overflow: hidden;
  color: #475569;
  font-size: 0.8rem;
}

.image-picker-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.image-picker-preview.has-image {
  border-style: solid;
  border-color: #22c55e44;
}

.image-picker-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.image-picker-status {
  font-size: 0.75rem;
  color: #94a3b8;
}

.image-picker-status.uploading { color: #f59e0b; }
.image-picker-status.done { color: #22c55e; }
.image-picker-status.error { color: #ef4444; }

.prod-thumb {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  object-fit: cover;
  background: #334155;
}

.qr-link {
  font-size: 0.7rem;
  color: #F58220;
  word-break: break-all;
}

.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 0.8rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 1000;
  animation: slideIn 0.3s ease;
}

.toast-success { background: #22c55e; color: white; }
.toast-error { background: #ef4444; color: white; }

@keyframes slideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ========== TABLET ========== */
@media (max-width: 1024px) {
  .portas-visual { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ========== MOBILE ========== */
@media (max-width: 768px) {
  body { flex-direction: column; }

  /* Sidebar → barra fixa no topo */
  .sidebar {
    width: 100%;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 100;
    border-right: none;
    border-bottom: 1px solid #334155;
  }

  .sidebar-header {
    padding: 0.7rem 1rem;
  }

  .sidebar-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
  }

  .sidebar-header h1 { font-size: 1rem; }

  .nav-menu {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0;
    gap: 0;
  }

  .nav-menu::-webkit-scrollbar { display: none; }

  .nav-item {
    white-space: nowrap;
    border-left: none;
    border-bottom: 3px solid transparent;
    padding: 0.6rem 1rem;
    font-size: 0.8rem;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .nav-item.active {
    border-left-color: transparent;
    border-bottom-color: #F58220;
  }

  /* Conteudo */
  .content {
    margin-left: 0;
    padding: 1rem;
    min-height: calc(100vh - 110px);
  }

  .section h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
  }

  /* Formularios */
  .card { padding: 1rem; }
  .form-row { flex-direction: column; gap: 0; }

  .form-group input,
  .form-group select {
    padding: 0.6rem 0.8rem;
    font-size: 1rem;
    min-height: 44px;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
    text-align: center;
  }

  /* Botoes touch-friendly */
  .btn {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    min-height: 44px;
  }

  .btn-sm {
    padding: 0.45rem 0.8rem;
    font-size: 0.8rem;
    min-height: 38px;
  }

  /* Toolbar */
  .toolbar {
    flex-wrap: wrap;
  }

  .toolbar select {
    flex: 1;
    min-height: 44px;
    font-size: 0.9rem;
  }

  /* Tabelas com scroll horizontal */
  .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  .data-table thead { display: table-header-group; }
  .data-table tbody { display: table-row-group; }
  .data-table tr { display: table-row; }
  .data-table th, .data-table td { display: table-cell; }

  .data-table th { padding: 0.6rem 0.7rem; font-size: 0.7rem; }
  .data-table td { padding: 0.6rem 0.7rem; font-size: 0.8rem; }

  /* Dashboard stats */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
  }

  .stat-card { padding: 0.8rem; }
  .stat-card .stat-value { font-size: 1.5rem; }
  .stat-card .stat-label { font-size: 0.7rem; }

  /* Portas */
  .portas-visual { grid-template-columns: 1fr; gap: 0.8rem; }

  .porta-card { padding: 0.8rem; }

  .porta-card-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.4rem;
  }

  .porta-card-actions .btn {
    width: 100%;
    text-align: center;
  }

  .porta-card select {
    padding: 0.5rem;
    font-size: 0.9rem;
    min-height: 40px;
  }

  /* Image picker */
  .image-picker-controls {
    flex-direction: column;
    align-items: flex-start;
  }

  .image-picker-controls .btn { width: 100%; text-align: center; }

  /* QR link */
  .qr-link { font-size: 0.6rem; }

  /* Toast */
  .toast {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    text-align: center;
  }
}

/* ========== TELEFONE PEQUENO ========== */
@media (max-width: 380px) {
  .content { padding: 0.7rem; }
  .sidebar-header h1 { font-size: 0.9rem; }
  .nav-item { padding: 0.5rem 0.7rem; font-size: 0.75rem; }
  .porta-card-actions { grid-template-columns: 1fr; }
}
