/* ========================================
   Home Inventory (Kucna zaliha) - Styles
   Mobile-first, PWA-optimized
   ======================================== */

/* --- CSS Variables --- */
:root {
  --color-primary: #2d5016;
  --color-primary-dark: #1a3a0e;
  --color-primary-light: #4a7c2e;
  --color-accent: #c7a951;
  --color-bg: #f5f5f0;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-text-secondary: #666666;
  --color-border: #d9d9d0;
  --color-danger: #c0392b;
  --color-warning: #e67e22;
  --color-success: #27ae60;
  --color-checked: #b8e6b0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.12);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.15);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --nav-height: 60px;
  --header-height: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

input, textarea, select, button {
  font-family: inherit;
  font-size: inherit;
}

a { color: var(--color-primary-light); text-decoration: none; }

/* --- App Shell --- */
#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

.screen {
  display: none;
  height: 100%;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.screen.active {
  display: flex;
}

/* --- Login Screen --- */
#screen-login {
  background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 100%);
  justify-content: center;
  align-items: center;
  padding: 24px;
}

.login-container {
  width: 100%;
  max-width: 360px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 40px 24px 32px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo {
  margin-bottom: 8px;
}

.login-logo svg {
  width: 64px;
  height: 64px;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--color-primary-dark);
  margin-bottom: 2px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-bottom: 28px;
}

.pin-label {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
}

.pin-hint {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: -8px;
  margin-bottom: 16px;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 8px;
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  transition: all 0.15s ease;
}

.pin-dot.filled {
  border-color: var(--color-primary);
  background: var(--color-primary);
}

.pin-dot.error {
  border-color: var(--color-danger);
  background: var(--color-danger);
  animation: shake 0.3s ease;
}

.pin-error {
  font-size: 13px;
  color: var(--color-danger);
  min-height: 20px;
  margin-bottom: 4px;
}

.pin-attempts {
  font-size: 12px;
  color: var(--color-warning);
  min-height: 18px;
  margin-bottom: 8px;
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 280px;
  margin: 0 auto;
}

.pin-btn {
  height: 56px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-btn:active {
  background: var(--color-border);
}

.pin-btn-clear {
  font-size: 16px;
  font-weight: 500;
  color: var(--color-text-secondary);
}

.pin-btn-back {
  color: var(--color-text-secondary);
}

/* --- Header --- */
#app-header {
  height: var(--header-height);
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 4px;
  flex-shrink: 0;
  z-index: 10;
}

.header-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  border-radius: 50%;
  flex-shrink: 0;
}

.header-btn:active {
  background: rgba(255,255,255,0.15);
}

/* --- Main Content --- */
#main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.view {
  display: none;
  flex-direction: column;
  min-height: 100%;
  padding-bottom: 16px;
}

.view.active {
  display: flex;
}

/* --- Bottom Navigation --- */
#bottom-nav {
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-shrink: 0;
  z-index: 10;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 0;
  transition: color 0.15s;
}

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

.nav-btn svg {
  width: 22px;
  height: 22px;
}

/* --- View Toolbar --- */
.view-toolbar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  flex-wrap: wrap;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.btn:active {
  opacity: 0.8;
}

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

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--color-border);
  color: var(--color-text);
}

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

.btn-small {
  padding: 6px 14px;
  font-size: 13px;
}

.btn-full {
  width: 100%;
  justify-content: center;
  margin-top: 8px;
}

.btn svg {
  flex-shrink: 0;
}

/* --- Folders List --- */
.folders-list {
  padding: 0 16px;
}

.folder-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: background 0.1s;
}

.folder-item:active {
  background: var(--color-bg);
}

.folder-item svg {
  flex-shrink: 0;
  color: var(--color-primary-light);
}

.folder-item .folder-name {
  flex: 1;
  font-weight: 500;
}

.folder-item .folder-count {
  font-size: 12px;
  color: var(--color-text-secondary);
}

.folder-actions {
  display: flex;
  gap: 4px;
}

.folder-actions button {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: 50%;
}

.folder-actions button:active {
  background: var(--color-bg);
}

.subfolder-indent {
  padding-left: 24px;
}

.folder-section-label {
  padding: 12px 16px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* --- Products Grid --- */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  padding: 0 16px;
}

.product-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: box-shadow 0.15s;
  position: relative;
}

.product-card:active {
  box-shadow: var(--shadow-md);
}

.product-card .product-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
  word-break: break-word;
}

.product-card .product-qty {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-primary);
}

.product-card .product-unit {
  font-size: 12px;
  color: var(--color-text-secondary);
}

.product-card .product-category {
  font-size: 11px;
  color: var(--color-text-secondary);
  margin-top: 4px;
}

.product-card .product-threshold {
  font-size: 11px;
  color: var(--color-warning);
  margin-top: 2px;
}

.product-card.low-stock {
  border-left: 3px solid var(--color-warning);
}

.product-card.out-of-stock {
  border-left: 3px solid var(--color-danger);
  opacity: 0.7;
}

.product-card .card-checkbox {
  position: absolute;
  top: 8px;
  right: 8px;
}

/* --- Empty State --- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  color: var(--color-text-secondary);
  font-size: 14px;
  gap: 12px;
}

/* --- Detail Form --- */
.detail-form {
  padding: 16px;
}

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: var(--color-primary-light);
}

textarea.form-input {
  resize: vertical;
  min-height: 60px;
}

select.form-input {
  appearance: auto;
  cursor: pointer;
}

.form-row {
  display: flex;
  gap: 10px;
}

.flex-2 { flex: 2; }

.detail-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  margin-bottom: 24px;
}

.detail-actions .btn {
  flex: 1;
}

/* --- Purchase History --- */
.purchase-history h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--color-text);
}

.purchase-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  font-size: 13px;
}

.purchase-item .purchase-date {
  font-size: 11px;
  color: var(--color-text-secondary);
  min-width: 70px;
}

.purchase-item .purchase-delta {
  font-weight: 600;
  color: var(--color-primary);
}

.purchase-item .purchase-price {
  color: var(--color-text-secondary);
}

/* --- Shopping List --- */
.shopping-stats {
  padding: 8px 16px;
  font-size: 13px;
  color: var(--color-text-secondary);
}

.shopping-list {
  padding: 0 16px;
}

.shopping-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: background 0.1s;
}

.shopping-item.checked {
  background: var(--color-checked);
  text-decoration: line-through;
  opacity: 0.7;
}

.shopping-item .item-checkbox {
  width: 22px;
  height: 22px;
  border: 2px solid var(--color-border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}

.shopping-item.checked .item-checkbox {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.shopping-item .item-checkbox::after {
  content: '';
  display: none;
  width: 6px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  position: relative;
  top: -1px;
}

.shopping-item.checked .item-checkbox::after {
  display: block;
}

.shopping-item .item-name {
  flex: 1;
  font-weight: 500;
}

.shopping-item .item-qty {
  font-size: 13px;
  color: var(--color-text-secondary);
}

.shopping-item .item-delete {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: 50%;
}

.shopping-item .item-delete:active {
  background: var(--color-bg);
}

/* --- Settings --- */
.settings-section {
  padding: 12px 16px;
}

.settings-heading {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 15px;
}

.settings-value {
  font-size: 13px;
  color: var(--color-text-secondary);
}

/* --- Toggle Group (HR/EN) --- */
.toggle-group {
  display: flex;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.toggle-btn {
  padding: 6px 14px;
  background: transparent;
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: all 0.15s;
}

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

/* --- Toggle Switch --- */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--color-border);
  transition: 0.2s;
  border-radius: 26px;
}

.slider:before {
  position: absolute;
  content: '';
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--color-primary-light);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 400px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
  font-size: 17px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: 50%;
}

.modal-body {
  padding: 16px 18px;
}

.modal-body .form-group {
  margin-bottom: 12px;
}

.modal-body .btn {
  margin-top: 8px;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 200;
  box-shadow: var(--shadow-lg);
  transition: opacity 0.3s ease;
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
}

/* --- Search bar --- */
.search-bar {
  padding: 8px 16px;
}

.search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 15px;
  outline: none;
  background: var(--color-surface);
}

.search-input:focus {
  border-color: var(--color-primary-light);
}

/* --- Animations --- */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

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

.product-card, .folder-item, .shopping-item {
  animation: fadeIn 0.2s ease;
}

/* --- Scrollbar --- */
#main-content::-webkit-scrollbar {
  width: 4px;
}

#main-content::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
}

/* --- Utility --- */
.hidden { display: none !important; }

/* --- Responsive Desktop --- */
@media (min-width: 768px) {
  #screen-app {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
    position: relative;
  }

  body {
    background: #e0e0d8;
  }

  .products-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .products-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* --- Notification badge --- */
.sync-badge {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-left: 6px;
}

.sync-badge.online { background: var(--color-success); }
.sync-badge.offline { background: var(--color-danger); }
.sync-badge.syncing { background: var(--color-warning); animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* --- Add to shopping button on product card --- */
.btn-add-to-cart {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--color-primary-light);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.product-card:hover .btn-add-to-cart,
.product-card:active .btn-add-to-cart {
  opacity: 1;
}

/* Quick quantity controls */
.qty-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.qty-btn {
  width: 28px;
  height: 28px;
  border: 1.5px solid var(--color-border);
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.qty-btn:active {
  background: var(--color-bg);
}

.qty-value {
  font-weight: 600;
  min-width: 28px;
  text-align: center;
}

/* Barcode scan button */
.btn-scan {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: none;
  background: var(--color-bg);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
}

/* Context menu */
.context-menu {
  position: fixed;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 150;
  min-width: 160px;
  overflow: hidden;
}

.context-menu button {
  display: block;
  width: 100%;
  padding: 12px 16px;
  border: none;
  background: none;
  text-align: left;
  font-size: 14px;
  cursor: pointer;
  color: var(--color-text);
}

.context-menu button:active {
  background: var(--color-bg);
}

.context-menu button.danger {
  color: var(--color-danger);
}
