/* ===== CSS Variables ===== */
:root {
  --color-primary: #10B981;
  --color-primary-hover: #059669;
  --color-primary-light: #D1FAE5;
  --color-danger: #EF4444;
  --color-danger-hover: #DC2626;
  --color-danger-light: #FEE2E2;
  --color-bg: #F9FAFB;
  --color-surface: #FFFFFF;
  --color-border: #E5E7EB;
  --color-text: #111827;
  --color-text-secondary: #6B7280;
  --color-text-muted: #9CA3AF;
  --color-checked: #D1D5DB;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px;
}

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

.btn svg {
  width: 18px;
  height: 18px;
}

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

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

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

.btn-secondary:hover {
  background: #374151;
}

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

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

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

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

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-icon:hover {
  background: var(--color-border);
  color: var(--color-text);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

/* ===== Home Page ===== */
.home-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 16px;
}

.home-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 480px;
  text-align: center;
}

.home-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  background: var(--color-primary-light);
  border-radius: 50%;
  margin-bottom: 16px;
}

.home-logo svg {
  width: 36px;
  height: 36px;
  color: var(--color-primary);
}

.home-card h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.home-subtitle {
  color: var(--color-text-secondary);
  margin-bottom: 32px;
}

.home-section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  text-align: left;
}

.home-form {
  display: flex;
  gap: 8px;
}

.home-form input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

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

.home-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 28px 0;
}

.home-divider::before,
.home-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

.home-divider span {
  color: var(--color-text-muted);
  font-size: 13px;
  text-transform: uppercase;
}

/* ===== List Page Header ===== */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.header-left h1 {
  font-size: 22px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ===== Add Item Form ===== */
.add-item-form {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 16px;
  margin-bottom: 24px;
}

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

.form-input {
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  background: var(--color-surface);
}

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

.input-name {
  flex: 1;
  min-width: 150px;
}

.input-quantity {
  width: 72px;
}

.input-unit {
  width: 72px;
}

.input-category {
  width: 150px;
}

.btn-add {
  flex-shrink: 0;
}

/* ===== Items Container ===== */
.items-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px;
  color: var(--color-text-secondary);
}

.loading svg {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-secondary);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  color: var(--color-text-muted);
}

.empty-state p {
  font-size: 15px;
}

/* ===== Category Group ===== */
.category-group {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.category-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  font-weight: 600;
  font-size: 14px;
  text-transform: capitalize;
}

.category-header svg {
  width: 18px;
  height: 18px;
  color: var(--color-primary);
}

.category-count {
  margin-left: auto;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  background: var(--color-border);
  padding: 2px 8px;
  border-radius: 100px;
}

/* ===== Item Row ===== */
.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  transition: background 0.2s, opacity 0.3s;
  animation: slideIn 0.3s ease;
}

.item-row:last-child {
  border-bottom: none;
}

.item-row.checked {
  opacity: 0.5;
  background: var(--color-bg);
}

.item-row.checked .item-name {
  text-decoration: line-through;
  color: var(--color-text-muted);
}

.item-row.removing {
  animation: slideOut 0.3s ease forwards;
}

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

@keyframes slideOut {
  from {
    opacity: 1;
    transform: translateX(0);
    max-height: 60px;
  }
  to {
    opacity: 0;
    transform: translateX(40px);
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin: 0;
    border: none;
  }
}

.item-checkbox {
  width: 22px;
  height: 22px;
  border: 2px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  position: relative;
  transition: all 0.2s;
  background: var(--color-surface);
}

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

.item-checkbox:checked::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 6px;
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.item-name {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-quantity {
  font-size: 13px;
  color: var(--color-text-secondary);
  background: var(--color-bg);
  padding: 2px 10px;
  border-radius: 100px;
  white-space: nowrap;
  flex-shrink: 0;
}

.item-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.item-delete:hover {
  background: var(--color-danger-light);
  color: var(--color-danger);
}

.item-delete svg {
  width: 16px;
  height: 16px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--color-text);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transition: transform 0.3s ease;
  white-space: nowrap;
}

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

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.modal-content {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  max-width: 400px;
  width: 100%;
}

.modal-content h3 {
  font-size: 18px;
  margin-bottom: 8px;
}

.modal-content p {
  color: var(--color-text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ===== Responsive ===== */

/* Mobile */
@media (max-width: 640px) {
  .container {
    padding: 12px;
  }

  .home-card {
    padding: 32px 24px;
  }

  .home-card h1 {
    font-size: 24px;
  }

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

  .home-form .btn {
    justify-content: center;
  }

  .list-header {
    flex-wrap: wrap;
  }

  .header-left h1 {
    font-size: 18px;
  }

  .header-right .btn-label {
    display: none;
  }

  .header-right .btn {
    padding: 10px;
  }

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

  .input-name,
  .input-quantity,
  .input-unit,
  .input-category {
    width: 100%;
  }

  .form-row .btn-add {
    justify-content: center;
  }

  .item-row {
    padding: 10px 12px;
    gap: 8px;
  }

  .item-name {
    font-size: 14px;
  }
}

/* Tablet */
@media (min-width: 641px) and (max-width: 1024px) {
  .form-row {
    flex-wrap: wrap;
  }

  .input-name {
    flex: 1 1 100%;
  }

  .input-quantity,
  .input-unit,
  .input-category,
  .btn-add {
    flex: 1;
  }
}

/* Desktop */
@media (min-width: 1025px) {
  .container {
    padding: 24px;
  }

  .form-row {
    flex-wrap: nowrap;
  }
}
