/* ============================================
   Handla — iOS-Inspired Shopping List PWA
   ============================================ */

:root {
  /* Colors — Light */
  --bg: #F2F2F7;
  --bg-card: #FFFFFF;
  --bg-navbar: rgba(242, 242, 247, 0.85);
  --text-primary: #000000;
  --text-secondary: #8E8E93;
  --text-tertiary: #C7C7CC;
  --accent: #007AFF;
  --accent-bg: rgba(0, 122, 255, 0.1);
  --destructive: #FF3B30;
  --destructive-bg: rgba(255, 59, 48, 0.1);
  --green: #34C759;
  --separator: rgba(60, 60, 67, 0.12);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);

  /* Layout */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --navbar-height: 96px;
  --radius: 12px;
  --radius-sm: 10px;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --bg-card: #1C1C1E;
    --bg-navbar: rgba(0, 0, 0, 0.85);
    --text-primary: #FFFFFF;
    --text-secondary: #8E8E93;
    --text-tertiary: #48484A;
    --separator: rgba(84, 84, 88, 0.35);
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
  }
}

[data-theme="dark"] {
  --bg: #000000;
  --bg-card: #1C1C1E;
  --bg-navbar: rgba(0, 0, 0, 0.85);
  --text-primary: #FFFFFF;
  --text-secondary: #8E8E93;
  --text-tertiary: #48484A;
  --separator: rgba(84, 84, 88, 0.35);
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
}

/* ============================================
   Reset & Base
   ============================================ */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.47;
  overflow: hidden;
  height: 100dvh;
  position: fixed;
  width: 100%;
}

#app {
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

button {
  font: inherit;
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
}

input, select {
  font: inherit;
  color: var(--text-primary);
}

/* ============================================
   Views & Transitions
   ============================================ */

.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1),
              opacity 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  pointer-events: none;
  will-change: transform, opacity;
}

.view.active {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.view.slide-out {
  transform: translateX(-30%);
  opacity: 0.5;
}

/* ============================================
   Navbar
   ============================================ */

.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  padding-top: var(--safe-top);
  background: var(--bg-navbar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
  flex-shrink: 0;
}

.navbar-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  min-height: 44px;
}

.navbar-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 16px 10px;
}

.large-title {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.37px;
  line-height: 1.15;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--accent);
  transition: background 0.15s;
}

.icon-btn:active {
  background: var(--accent-bg);
}

.text-btn {
  font-size: 17px;
  color: var(--accent);
  padding: 6px 2px;
  font-weight: 400;
}

.text-btn.primary {
  font-weight: 600;
}

.text-btn:active {
  opacity: 0.5;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 2px;
  width: auto;
  color: var(--accent);
  font-size: 17px;
  border-radius: var(--radius-sm);
  padding-right: 8px;
}

.back-btn svg {
  margin-left: -6px;
  flex-shrink: 0;
}

.counter-badge {
  font-size: 17px;
  color: var(--text-secondary);
  font-weight: 400;
}

/* ============================================
   Content Area
   ============================================ */

.content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: calc(100px + var(--safe-bottom));
}

/* ============================================
   Card Group (List / Item Cards)
   ============================================ */

.card-group {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-group + .card-group {
  margin-top: 16px;
}

/* ============================================
   List Card (Home View)
   ============================================ */

.list-card {
  position: relative;
  overflow: hidden;
}

.list-card-inner {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  gap: 12px;
  background: var(--bg-card);
  position: relative;
  z-index: 1;
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
  cursor: pointer;
}

.list-card-inner:active {
  background: var(--separator);
}

.list-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
}

.list-card-info {
  flex: 1;
  min-width: 0;
}

.list-card-name {
  font-size: 17px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-card-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.list-card-chevron {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.list-card + .list-card {
  border-top: 0.5px solid var(--separator);
}

/* Swipe delete background */
.list-card-delete-bg {
  position: absolute;
  inset: 0;
  background: var(--destructive);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 20px;
  color: white;
  font-weight: 600;
  font-size: 15px;
}

/* ============================================
   Category Section (List Detail)
   ============================================ */

.category-section {
  margin-bottom: 16px;
}

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  cursor: pointer;
}

.category-name {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.category-count {
  font-size: 13px;
  color: var(--text-tertiary);
}

/* ============================================
   Item Row
   ============================================ */

.item-row {
  position: relative;
  overflow: hidden;
}

.item-row-inner {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  background: var(--bg-card);
  position: relative;
  z-index: 1;
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

.item-checkbox {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--text-tertiary);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  cursor: pointer;
}

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

.item-checkbox svg {
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.2s ease;
  color: white;
}

.item-row.checked .item-checkbox svg {
  opacity: 1;
  transform: scale(1);
}

.item-info {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-size: 17px;
  transition: all 0.25s ease;
}

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

.item-detail {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.item-row + .item-row {
  border-top: 0.5px solid var(--separator);
}

/* Swipe delete background */
.item-delete-bg {
  position: absolute;
  inset: 0;
  background: var(--destructive);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 20px;
  color: white;
  font-weight: 600;
  font-size: 15px;
}

/* ============================================
   FAB (Floating Action Button)
   ============================================ */

.fab {
  position: absolute;
  bottom: calc(24px + var(--safe-bottom));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 122, 255, 0.4);
  z-index: 50;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.fab:active {
  transform: scale(0.92);
  box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

/* ============================================
   Bottom Sheet
   ============================================ */

.bottom-sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
}

.bottom-sheet.open {
  pointer-events: auto;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.bottom-sheet.open .sheet-backdrop {
  opacity: 1;
}

.sheet-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg);
  border-radius: 14px 14px 0 0;
  padding: 12px 16px;
  padding-bottom: calc(24px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 85dvh;
  overflow-y: auto;
}

.bottom-sheet.open .sheet-content {
  transform: translateY(0);
}

.sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--text-tertiary);
  margin: 0 auto 12px;
}

.sheet-title {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
}

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

.sheet-header .sheet-title {
  flex: 1;
}

/* ============================================
   Settings
   ============================================ */

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  font-size: 17px;
  width: 100%;
  text-align: left;
}

.setting-row.destructive {
  color: var(--destructive);
  cursor: pointer;
}

.setting-row.destructive:active {
  background: var(--destructive-bg);
}

.setting-row select {
  background: var(--bg);
  border: 1px solid var(--separator);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 15px;
  color: var(--text-primary);
}

/* ============================================
   Form
   ============================================ */

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

.form-group.small {
  max-width: 80px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  font-size: 17px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
}

.form-group input::placeholder {
  color: var(--text-tertiary);
}

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

.form-row .form-group {
  flex: 1;
}

/* ============================================
   Dialog (Alert-style)
   ============================================ */

.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 24px;
}

.dialog-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.dialog {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 20px;
  width: 100%;
  max-width: 320px;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

.dialog-overlay.open .dialog {
  transform: scale(1);
}

.dialog h3 {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 16px;
}

.dialog input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--separator);
  border-radius: 8px;
  font-size: 17px;
  outline: none;
}

.dialog input:focus {
  border-color: var(--accent);
}

.dialog-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.dialog-btn {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  font-size: 17px;
  font-weight: 500;
  text-align: center;
  background: var(--bg);
  transition: opacity 0.15s;
}

.dialog-btn:active {
  opacity: 0.6;
}

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

.dialog-btn.destructive {
  background: var(--destructive-bg);
  color: var(--destructive);
}

/* ============================================
   Empty State
   ============================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}

.empty-icon {
  margin-bottom: 16px;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-secondary);
}

.empty-hint {
  font-size: 15px !important;
  font-weight: 400 !important;
  color: var(--text-tertiary) !important;
  margin-top: 4px;
}

/* ============================================
   Animations
   ============================================ */

@keyframes item-added {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.item-enter {
  animation: item-added 0.3s cubic-bezier(0.32, 0.72, 0, 1) forwards;
}

@keyframes check-bounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.check-bounce {
  animation: check-bounce 0.3s ease;
}

@keyframes slide-out-right {
  to {
    transform: translateX(100%);
    opacity: 0;
    height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin: 0;
    overflow: hidden;
  }
}

.item-removing {
  animation: slide-out-right 0.3s ease forwards;
}

/* ============================================
   Scrollbar (webkit)
   ============================================ */

.content::-webkit-scrollbar {
  display: none;
}

.content {
  scrollbar-width: none;
}

/* ============================================
   Selection handling
   ============================================ */
.item-row-inner, .list-card-inner {
  -webkit-user-select: none;
  user-select: none;
}
