:root {
  /* Light theme (default) */
  --bg-1: #eef1fb;
  --bg-2: #f7f8fd;
  --surface: #ffffff;
  --surface-2: #f4f6fc;
  --surface-3: #eef1f9;
  --border: #e3e7f2;
  --text: #1a1f36;
  --muted: #6b7290;
  --accent: #a855f7;
  --accent-2: #ec4899;
  --accent-3: #6366f1;
  --danger: #f43f5e;
  --price: #9333ea;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 12px 30px rgba(60, 30, 120, 0.12);
  --shadow-sm: 0 4px 14px rgba(60, 30, 120, 0.08);
  --glow-1: rgba(168, 85, 247, 0.14);
  --glow-2: rgba(236, 72, 153, 0.10);
}

[data-theme="dark"] {
  --bg-1: #0b0f1e;
  --bg-2: #141a30;
  --surface: #171d33;
  --surface-2: #1f273f;
  --surface-3: #262f4d;
  --border: #2c3454;
  --text: #f2f3fb;
  --muted: #9aa2c4;
  --price: #f5d0fe;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.28);
  --glow-1: rgba(168, 85, 247, 0.18);
  --glow-2: rgba(236, 72, 153, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(1000px 500px at 80% -10%, var(--glow-1), transparent 60%),
    radial-gradient(900px 500px at -10% 0%, var(--glow-2), transparent 55%),
    linear-gradient(180deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  padding-top: calc(16px + env(safe-area-inset-top));
  background: linear-gradient(120deg, #7c3aed 0%, #a21caf 55%, #db2777 100%);
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  font-size: 18px;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  backdrop-filter: blur(4px);
}
.app-header h1 { font-size: 21px; margin: 0; font-weight: 800; letter-spacing: 0.2px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.theme-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  font-size: 16px;
  cursor: pointer;
}
.who-btn {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
  padding: 7px 14px 7px 8px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.who-btn::before {
  content: attr(data-initial);
  width: 24px; height: 24px;
  display: grid; place-items: center;
  background: #fff; color: #a21caf;
  border-radius: 999px; font-size: 12px; font-weight: 800;
}

/* Layout */
.content { max-width: 760px; margin: 0 auto; padding: 18px; }

/* Add card */
.add-card {
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.add-row { display: flex; gap: 10px; }
.add-row input { flex: 1; min-width: 0; }

input, select {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 15px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: #6f77a0; }
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.25);
}

button { font-family: inherit; }
.primary {
  background: linear-gradient(120deg, var(--accent-3), var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 20px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(168, 85, 247, 0.35);
  transition: transform .1s, filter .15s;
}
.primary:hover { filter: brightness(1.06); }
.primary:active { transform: translateY(1px); }
.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 18px;
  cursor: pointer;
}
.link-btn {
  background: none;
  border: none;
  color: #c4b5fd;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 2px 2px;
  cursor: pointer;
}

.details-panel { margin-top: 14px; display: grid; gap: 12px; }
.details-panel label { display: grid; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 600; letter-spacing: .2px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Filters */
.filters { margin-bottom: 18px; display: grid; gap: 10px; }
.search-wrap { position: relative; }
.search-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 15px; opacity: 0.7; pointer-events: none;
}
#searchInput {
  padding-left: 42px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  border-radius: 999px;
}
.filter-row { display: flex; gap: 10px; flex-wrap: wrap; }
.filter-select {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  padding: 11px 12px;
}

/* Groups */
.groups { display: grid; gap: 22px; }
.source-group {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.source-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 18px; font-weight: 800; margin: 0 0 14px;
}
.source-logo {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 800; color: #fff;
}
.source-badge {
  margin-left: auto;
  font-size: 12px; color: var(--muted); font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 999px;
}
.category-block { margin: 0 0 14px; }
.category-block:last-child { margin-bottom: 0; }
.category-title {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.7px;
  color: #fff; margin: 0 0 10px; padding: 4px 11px; border-radius: 999px;
}

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 14px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
  position: relative;
  box-shadow: var(--shadow-sm);
  transition: transform .12s, box-shadow .12s, border-color .12s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: #3a4470; }
.card .thumb {
  aspect-ratio: 1 / 1;
  background-size: cover; background-position: center;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.card .thumb.placeholder {
  background: linear-gradient(135deg, var(--surface-3), var(--surface-2));
}
.card .thumb .ph-letter {
  font-size: 34px; font-weight: 800;
  color: var(--muted); opacity: 0.55;
}
.card .body { padding: 11px 12px 12px; display: grid; gap: 8px; }
.card .name { font-size: 13px; line-height: 1.35; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 34px; }
.card .meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.card .price { font-size: 15px; font-weight: 800; color: var(--price); }
.card .price:empty::before { content: "—"; color: var(--muted); font-weight: 600; }
.card .by {
  font-size: 10.5px; color: var(--muted); font-weight: 600;
  display: inline-flex; align-items: center; gap: 5px;
}
.card .by::before {
  content: attr(data-initial);
  width: 18px; height: 18px; border-radius: 999px;
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--accent-3); font-size: 9px; font-weight: 800;
}

.card .open { text-decoration: none; color: inherit; display: contents; }

/* Card action buttons */
.card-actions {
  position: absolute; top: 8px; right: 8px;
  display: flex; gap: 6px; opacity: 1; z-index: 3;
}
.icon-btn {
  background: rgba(10, 12, 24, 0.72);
  color: #fff; border: 1px solid rgba(255,255,255,0.12);
  width: 30px; height: 30px; border-radius: 999px; cursor: pointer;
  font-size: 14px; display: grid; place-items: center;
  backdrop-filter: blur(3px);
}
.icon-btn:hover { background: rgba(10, 12, 24, 0.92); }
.icon-btn.del:hover { background: var(--danger); border-color: transparent; }

/* Empty */
.empty { text-align: center; color: var(--text); padding: 56px 16px; }
.empty-emoji { font-size: 48px; margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 14px; }

/* Dialog */
.dialog {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  color: var(--text);
  border-radius: var(--radius);
  padding: 22px;
  width: min(92vw, 380px);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(4, 6, 14, 0.66); backdrop-filter: blur(2px); }
.dialog h3 { margin: 0 0 6px; font-size: 18px; }
.dialog label { display: grid; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 600; margin-top: 12px; }
.dialog .field-input { margin: 14px 0; }
.dialog menu { display: flex; gap: 10px; justify-content: flex-end; margin: 20px 0 0; padding: 0; }

/* Toast */
.toast {
  position: fixed;
  left: 50%; bottom: 26px; transform: translateX(-50%);
  background: linear-gradient(120deg, var(--accent-3), var(--accent), var(--accent-2));
  border: none;
  color: #fff; padding: 13px 22px; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(168, 85, 247, 0.4);
  font-size: 14px; font-weight: 600; z-index: 60;
  max-width: 90vw; text-align: center;
}
.toast[hidden] { display: none; }
