/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-blue: #2196F3;
  --success-green: #4CAF50;
  --danger-red: #F44336;
  --warning-yellow: #FFC107;
  --bg-gray: #F5F5F5;
  --card-white: #FFFFFF;
  --text-dark: #212121;
  --text-gray: #757575;
  --border-gray: #E0E0E0;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --header-height: 60px;
  --nav-height: 70px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-dark);
  background-color: var(--bg-gray);
  padding-top: var(--header-height);
  padding-bottom: var(--nav-height);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* Header */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background-color: var(--primary-blue);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  z-index: 100;
  /* needed for absolute positioned child */
}

.app-header h1 {
  font-size: 20px;
  font-weight: 600;
}

/* Main Content */
#app-content {
  min-height: calc(100vh - var(--header-height) - var(--nav-height));
  padding-bottom: 20px;
}

/* Views */
.view {
  display: none;
  animation: fadeIn 0.3s ease-in;
}

.view.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Section Header */
.section-header {
  padding: 20px;
  background-color: white;
  border-bottom: 1px solid var(--border-gray);
}

.section-header h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-dark);
}

/* Stats Cards (Dashboard) */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 16px;
}

.stat-card {
  background: white;
  padding: 16px;
  border-radius: 12px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 28px;
  font-weight: bold;
  color: var(--primary-blue);
  margin-bottom: 4px;
}

.stat-label {
  font-size: 13px;
  color: var(--text-gray);
}

/* Items List (Dashboard) */
.items-list {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item-card {
  background: white;
  padding: 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  border-left: 5px solid var(--border-gray);
  transition: transform 0.2s;
}

.item-card:active {
  transform: scale(0.98);
}

.item-card.stock-good {
  border-left-color: var(--success-green);
}

.item-card.stock-low {
  border-left-color: var(--warning-yellow);
}

.item-card.stock-critical {
  border-left-color: var(--danger-red);
}

.item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.item-name {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-dark);
}

.item-stock {
  font-size: 22px;
  font-weight: bold;
}

.item-stock.stock-good {
  color: var(--success-green);
}

.item-stock.stock-low {
  color: var(--warning-yellow);
}

.item-stock.stock-critical {
  color: var(--danger-red);
}

.item-details {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--text-gray);
}

.item-category {
  background: var(--bg-gray);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
}

/* Forms */
.stock-form {
  padding: 20px;
  background: white;
  margin: 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

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

.form-group label {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 8px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  border: 2px solid var(--border-gray);
  border-radius: 8px;
  background: white;
  color: var(--text-dark);
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23757575' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-blue);
}

.form-group small {
  display: block;
  margin-top: 6px;
  font-size: 14px;
  color: var(--text-gray);
}

.form-group textarea {
  resize: vertical;
  font-family: inherit;
}

/* Buttons */
.btn {
  width: 100%;
  min-height: 52px;
  padding: 14px 24px;
  font-size: 18px;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.98);
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.btn-primary {
  background-color: var(--primary-blue);
  color: white;
}

.btn-primary:hover {
  background-color: #1976D2;
}

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

.btn-green:hover {
  background-color: #45a049;
}

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

.btn-red:hover {
  background-color: #da190b;
}

.btn-secondary {
  background-color: white;
  color: var(--text-dark);
  border: 2px solid var(--border-gray);
}

.btn-secondary:hover {
  background-color: var(--bg-gray);
}

/* History List */
.history-list {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-card {
  background: white;
  padding: 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  border-left: 5px solid var(--border-gray);
}

.history-card.type-in {
  border-left-color: var(--success-green);
}

.history-card.type-out {
  border-left-color: var(--danger-red);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.history-item-name {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-dark);
}

.history-qty {
  font-size: 20px;
  font-weight: bold;
}

.history-qty.type-in {
  color: var(--success-green);
}

.history-qty.type-out {
  color: var(--danger-red);
}

.history-details {
  font-size: 14px;
  color: var(--text-gray);
  margin-bottom: 4px;
}

.history-notes {
  font-size: 14px;
  color: var(--text-dark);
  font-style: italic;
  margin-top: 8px;
  padding: 8px;
  background: var(--bg-gray);
  border-radius: 6px;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: white;
  border-top: 1px solid var(--border-gray);
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
  z-index: 100;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-gray);
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn.active {
  color: var(--primary-blue);
}

.nav-icon {
  font-size: 24px;
  margin-bottom: 4px;
}

.nav-label {
  font-size: 12px;
  font-weight: 500;
}

/* Floating Action Button */
.fab {
  position: fixed;
  bottom: calc(var(--nav-height) + 16px);
  right: 16px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: var(--primary-blue);
  color: white;
  font-size: 24px;
  border: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  cursor: pointer;
  transition: all 0.2s;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.fab:active {
  transform: scale(0.95);
}

.header-btn {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 2px solid rgba(255,255,255,0.4);
  color: white;
  font-size: 18px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.header-btn.active {
  background: rgba(255,255,255,0.2);
  border-color: white;
}

.manage-banner {
  display: none;
  background: var(--warning-yellow);
  color: #333;
  text-align: center;
  padding: 8px;
  font-size: 14px;
  font-weight: 600;
}

.manage-banner.show {
  display: block;
}

.item-actions {
  display: none;
  gap: 8px;
  margin-top: 10px;
}

body.manage-mode .item-actions {
  display: flex;
}

.item-actions button {
  flex: 1;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-edit-item {
  background-color: #E3F2FD;
  color: var(--primary-blue);
}

.btn-edit-item:active {
  background-color: #BBDEFB;
}

.btn-delete-item {
  background-color: #FFEBEE;
  color: var(--danger-red);
}

.btn-delete-item:active {
  background-color: #FFCDD2;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-dark);
  color: white;
  padding: 16px 24px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  font-size: 16px;
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
  max-width: 90%;
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.success {
  background: var(--success-green);
}

.toast.error {
  background: var(--danger-red);
}

/* Modal / Confirmation Dialog */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.2s ease;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: white;
  padding: 24px;
  border-radius: 16px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  animation: slideUp 0.3s ease;
}

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

.modal-content h3 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-dark);
}

.modal-content p {
  font-size: 16px;
  color: var(--text-gray);
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-actions .btn {
  min-height: 48px;
  font-size: 16px;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-gray);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state-text {
  font-size: 16px;
}

/* Loading State */
.loading {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-gray);
  font-size: 16px;
}

/* Responsive adjustments */
@media (min-width: 768px) {
  #app-content {
    max-width: 800px;
    margin: 0 auto;
  }
  
  .stats-cards {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 360px) {
  .stats-cards {
    grid-template-columns: 1fr;
  }
  
  .stat-card {
    padding: 12px;
  }
  
  .stat-value {
    font-size: 24px;
  }
}

/* Prevent zoom on input focus (iOS) */
@supports (-webkit-touch-callout: none) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}
