@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap');

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

  :root {
    --bg: #F7F5F0;
    --surface: #FFFFFF;
    --text: #1a1a1a;
    --text-muted: #888;
    --border: rgba(0,0,0,0.08);
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 2px 12px rgba(0,0,0,0.07);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
    --font: 'Nunito', sans-serif;
  }

  body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    max-width: 480px;
    margin: 0 auto;
  }

  /* HEADER */
  .header {
    background: var(--surface);
    padding: 20px 16px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 0 var(--border);
    margin-top: 20px;
  }

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

  .app-title {
    font-size: 26px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.5px;
  }

  .app-title span {
    display: inline-block;
    background: #FFD93D;
    border-radius: 8px;
    padding: 0 6px;
    margin-left: 4px;
    font-size: 22px;
  }

  .btn-add {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: #FF6B6B;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 12px rgba(255,107,107,0.35);
    transition: transform 0.15s, box-shadow 0.15s;
  }
  .btn-add:hover { transform: scale(1.08); box-shadow: 0 6px 18px rgba(255,107,107,0.4); }
  .btn-add:active { transform: scale(0.95); }

  /* SEARCH */
  .search-wrap {
    position: relative;
    margin-bottom: 14px;
  }
  .search-wrap i {
    position: absolute;
    left: 12px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 18px;
    pointer-events: none;
  }
  .search-input {
    width: 100%;
    padding: 10px 12px 10px 38px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--bg);
    font-family: var(--font);
    font-size: 15px;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
  }
  .search-input:focus { border-color: #FF6B6B; }
  .search-input::placeholder { color: var(--text-muted); }

  /* FILTER TABS */
  .filter-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 12px;
    scrollbar-width: none;
  }
  .filter-tabs::-webkit-scrollbar { display: none; }
  .filter-tab {
    flex-shrink: 0;
    padding: 5px 12px;
    border-radius: 20px;
    border: 1.5px solid var(--border);
    background: transparent;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.18s;
    white-space: nowrap;
    display: flex; align-items: center; gap: 5px;
  }
  .filter-tab.active {
    background: var(--cat-color, #FF6B6B);
    border-color: var(--cat-color, #FF6B6B);
    color: #fff;
  }
  .filter-tab:hover:not(.active) { border-color: #aaa; color: var(--text); }

  /* LIST */
  .list-wrap {
    padding: 12px 16px 80px;
  }

  .list-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin: 16px 0 8px;
  }

  /* ITEM */
  .item-outer {
    position: relative;
    margin-bottom: 8px;
    border-radius: var(--radius-sm);
    overflow: hidden;
  }

  .item-bg-left, .item-bg-right {
    position: absolute;
    top: 0; bottom: 0;
    width: 80px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
    color: #fff;
    opacity: 0;
    transition: opacity 0.2s;
  }
  .item-bg-left { left: 0; background: #E24B4A; border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
  .item-bg-right { right: 0; background: #63c132; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

  .item-card {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow);
    cursor: grab;
    transition: transform 0.12s, box-shadow 0.12s;
    user-select: none;
    touch-action: pan-y;
    will-change: transform;
    z-index: 1;
  }
  .item-card:active { cursor: grabbing; }

  .item-card.bought {
    opacity: 0.5;
  }
  .item-card.bought .item-name {
    text-decoration: line-through;
    color: var(--text-muted);
  }

  /* Category dot */
  .cat-dot {
    width: 38px; height: 38px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
  }

  .item-info { flex: 1; min-width: 0; }
  .item-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .item-cat-label {
    font-size: 12px;
    font-weight: 600;
    margin-top: 2px;
  }

  .item-actions {
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .item-checkbox {
    width: 24px; height: 24px;
    border-radius: 50%;
    border: 2px solid var(--border-color, #ddd);
    background: transparent;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.18s;
    flex-shrink: 0;
  }
  .item-checkbox.checked {
    background: var(--check-color, #63c132);
    border-color: var(--check-color, #63c132);
  }
  .item-checkbox.checked::after {
    content: '';
    width: 12px; height: 8px;
    border-left: 2.5px solid #fff;
    border-bottom: 2.5px solid #fff;
    transform: rotate(-45deg) translateY(-1px);
    display: block;
  }

  .btn-delete {
    width: 30px; height: 30px;
    border-radius: 8px;
    border: none;
    background: #FEF2F2;
    color: #E24B4A;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    transition: background 0.15s;
    flex-shrink: 0;
  }
  .btn-delete:hover { background: #FECACA; }

  /* EMPTY STATE */
  .empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
  }
  .empty-state i { font-size: 48px; margin-bottom: 12px; display: block; opacity: 0.4; }
  .empty-state p { font-size: 15px; font-weight: 600; }

  /* STATS BAR */
  .stats-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0 10px;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
  }
  .stats-bought { color: #63c132; }

  /* MODAL */
  .modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 200;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
  }
  .modal-overlay.open { display: flex; }

  .modal {
    background: var(--surface);
    border-radius: 24px 24px 0 0;
    padding: 20px 20px 32px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  }
  @keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }

  .modal-handle {
    width: 36px; height: 4px;
    background: var(--border);
    border-radius: 4px;
    margin: 0 auto 18px;
  }

  .modal-title {
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 20px;
  }

  .modal-tabs {
    display: flex;
    border-radius: var(--radius-sm);
    background: var(--bg);
    padding: 3px;
    margin-bottom: 18px;
    gap: 2px;
  }
  .modal-tab {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 8px;
    background: transparent;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.18s;
  }
  .modal-tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
  }

  .form-group { margin-bottom: 14px; }
  .form-label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 6px;
  }
  .form-input {
    width: 100%;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--bg);
    font-family: var(--font);
    font-size: 15px;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
  }
  .form-input:focus { border-color: #FF6B6B; }

  /* Category picker */
  .cat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }
  .cat-option {
    border-radius: var(--radius-sm);
    padding: 10px 4px 8px;
    border: 2px solid transparent;
    cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    transition: all 0.15s;
    background: var(--bg);
  }
  .cat-option:hover { transform: scale(1.04); }
  .cat-option.selected { border-color: currentColor; }
  .cat-option .cat-icon-wrap {
    width: 36px; height: 36px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
  }
  .cat-option span {
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  /* History items */
  .history-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    border: 1.5px solid transparent;
  }
  .history-item:hover { background: var(--bg); }
  .history-item.selected { background: var(--bg); border-color: #FF6B6B; }
  .history-item-name { font-size: 14px; font-weight: 700; flex: 1; }
  .history-item-cat { font-size: 12px; font-weight: 600; }

  .history-search {
    width: 100%;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--bg);
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    outline: none;
    margin-bottom: 10px;
    transition: border-color 0.2s;
  }
  .history-search:focus { border-color: #FF6B6B; }

  .btn-primary {
    width: 100%;
    padding: 14px;
    border-radius: var(--radius-sm);
    border: none;
    background: #FF6B6B;
    color: #fff;
    font-family: var(--font);
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 14px rgba(255,107,107,0.35);
    margin-top: 6px;
  }
  .btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(255,107,107,0.4); }
  .btn-primary:active { transform: scale(0.98); }
  .btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

  .modal-close {
    position: absolute;
    top: 20px; right: 20px;
    width: 32px; height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--bg);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    color: var(--text-muted);
  }

  /* CAT MODAL */
  .cat-modal-form .form-input { margin-bottom: 10px; }

  .icon-picker {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    margin-bottom: 12px;
    max-height: 160px;
    overflow-y: auto;
  }
  .icon-opt {
    width: 40px; height: 40px;
    border-radius: 8px;
    border: 1.5px solid var(--border);
    background: var(--bg);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    transition: all 0.15s;
  }
  .icon-opt.selected, .icon-opt:hover { border-color: #FF6B6B; background: #FFF5F5; }

  .color-picker-row {
    display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px;
  }
  .color-dot {
    width: 32px; height: 32px;
    border-radius: 50%;
    border: 2.5px solid transparent;
    cursor: pointer;
    transition: transform 0.15s;
  }
  .color-dot.selected { border-color: var(--text); transform: scale(1.15); }

  .manage-cats-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 0;
    background: none; border: none;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 700;
    color: #FF6B6B;
    cursor: pointer;
    margin-bottom: 8px;
  }

  /* Toast */
  .toast {
    position: fixed;
    bottom: 24px; left: 50%;
    transform: translateX(-50%) translateY(60px);
    background: var(--text);
    color: var(--surface);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    z-index: 999;
    transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
    white-space: nowrap;
  }
  .toast.show { transform: translateX(-50%) translateY(0); }

  .section-empty { font-size: 13px; color: var(--text-muted); text-align: center; padding: 12px 0; }