:root {
  color-scheme: light;
  --bg: #f7f2ee;
  --surface: #fffbff;
  --surface-2: #f1ecf4;
  --surface-3: #e8f2ee;
  --text: #1d1b20;
  --muted: #625b66;
  --outline: #79747e;
  --primary: #006d3c;
  --on-primary: #ffffff;
  --primary-soft: #c8f2d7;
  --danger: #ba1a1a;
  --shadow: 0 10px 28px rgba(40, 34, 48, 0.12);
  --radius: 8px;
  font-family: "Plus Jakarta Sans", "Outfit", system-ui, sans-serif;
}

body.dark {
  color-scheme: dark;
  --bg: #141218;
  --surface: #211f26;
  --surface-2: #2b2930;
  --surface-3: #20352d;
  --text: #e7e1e8;
  --muted: #cac4cf;
  --outline: #948f99;
  --primary: #7bdc9c;
  --on-primary: #00391c;
  --primary-soft: #1d4d32;
  --danger: #ffb4ab;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(0, 109, 60, 0.08), transparent 36%),
    linear-gradient(315deg, rgba(116, 80, 164, 0.08), transparent 32%),
    var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-container {
  min-height: 100vh;
  padding: 18px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(160px, auto) minmax(160px, 260px) minmax(220px, 520px) auto;
  gap: 16px;
  align-items: center;
  max-width: 1320px;
  margin: 0 auto 18px;
  padding: 12px;
  border: 1px solid rgba(121, 116, 126, 0.2);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.header-title-wrapper,
.header-actions,
.profile-switcher,
.search-container,
.dialog-header,
.dialog-actions,
.bookmarklet-wrapper,
.backup-actions,
.group-header,
.link-row,
.empty-state {
  display: flex;
  align-items: center;
}

.header-title-wrapper {
  min-width: 0;
  gap: 10px;
}

.header-logo {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
}

.header-title {
  margin: 0;
  overflow: hidden;
  font-size: 1.28rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-container {
  min-width: 0;
  height: 48px;
  gap: 8px;
  padding: 0 8px 0 14px;
  border-radius: 24px;
  background: var(--surface-2);
}

.search-container input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.search-icon {
  color: var(--muted);
}

.header-actions {
  justify-content: flex-end;
  gap: 6px;
}

.profile-switcher {
  min-width: 0;
  gap: 4px;
  padding: 3px 4px 3px 12px;
  border-radius: 24px;
  background: var(--surface-2);
}

.profile-switcher select {
  width: 100%;
  min-width: 0;
  height: 42px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-weight: 700;
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  outline: none;
}

.main-content {
  max-width: 1320px;
  margin: 0 auto;
}

.groups-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(300px, 1fr);
  grid-template-rows: repeat(3, minmax(190px, auto));
  gap: 14px;
  min-height: calc(100vh - 132px);
  overflow-x: auto;
  padding: 2px 2px 92px;
  scroll-snap-type: x proximity;
}

.group-card {
  display: flex;
  min-height: 190px;
  flex-direction: column;
  border: 1px solid color-mix(in srgb, var(--group-color) 34%, var(--outline));
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--group-color) 12%, var(--surface));
  box-shadow: 0 4px 14px rgba(35, 31, 40, 0.08);
  scroll-snap-align: start;
}

.group-card.drag-over {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.group-header {
  gap: 9px;
  padding: 12px 10px 8px 14px;
}

.group-icon {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--group-color) 28%, var(--surface));
  font-size: 1.15rem;
}

.group-title {
  min-width: 0;
  flex: 1;
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 1rem;
  font-weight: 700;
}

.group-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 2px;
}

.links-list {
  display: grid;
  gap: 7px;
  padding: 0 10px 12px;
}

.link-row {
  min-height: 48px;
  gap: 9px;
  padding: 7px 8px;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
}

.link-row:hover,
.link-row:focus-visible {
  background: color-mix(in srgb, var(--group-color) 16%, var(--surface-2));
  outline: none;
}

.favicon {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--surface);
}

.link-text {
  min-width: 0;
  flex: 1;
  color: inherit;
  text-decoration: none;
}

.link-title {
  display: block;
  overflow: hidden;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-url {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edit-link-btn {
  opacity: 0.7;
}

.empty-state {
  min-height: 82px;
  justify-content: center;
  margin: 0 10px 12px;
  border: 1px dashed color-mix(in srgb, var(--group-color) 40%, var(--outline));
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  display: inline-flex;
  height: 56px;
  align-items: center;
  gap: 10px;
  padding: 0 22px;
  border: 0;
  border-radius: 16px;
  background: var(--primary);
  color: var(--on-primary);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-weight: 700;
}

.m3-dialog {
  width: min(560px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 28px));
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.m3-dialog::backdrop {
  background: rgba(0, 0, 0, 0.42);
}

.dialog-header {
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 8px 22px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.dialog-body {
  display: grid;
  gap: 18px;
  padding: 12px 22px 20px;
}

.text-field,
.select-field,
.emoji-picker-container,
.color-picker-container,
.settings-section {
  display: grid;
  gap: 8px;
}

label,
.settings-section h3 {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.text-field input,
.select-field select,
.custom-emoji-row input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: 0;
  padding: 0 12px;
}

.text-field input:focus,
.select-field select:focus,
.custom-emoji-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 24%, transparent);
}

.emoji-list,
.color-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.emoji-option,
.color-option {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--surface-2);
  cursor: pointer;
}

.emoji-option.selected,
.color-option.selected {
  border-color: var(--primary);
}

.color-option {
  background: hsl(var(--hue) 72% 52%);
}

.dialog-actions {
  gap: 8px;
  justify-content: flex-end;
}

.spacer {
  flex: 1;
}

.btn {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 20px;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 700;
}

.btn:disabled,
.fab:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

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

.btn-tonal {
  background: var(--primary-soft);
  color: var(--text);
}

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

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

.settings-section {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
}

.settings-section h3,
.settings-section p {
  margin: 0;
}

.settings-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.settings-section p {
  color: var(--muted);
  line-height: 1.45;
}

.bookmarklet-wrapper,
.backup-actions {
  flex-wrap: wrap;
  gap: 10px;
}

.bookmarklet-btn {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  border-radius: 22px;
  background: var(--primary);
  color: var(--on-primary);
  padding: 0 16px;
  text-decoration: none;
  font-weight: 800;
}

.drag-hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.danger-zone {
  background: color-mix(in srgb, var(--danger) 10%, var(--surface-2));
}

.locked-state {
  display: grid;
  min-height: min(520px, calc(100vh - 180px));
  place-items: center;
  align-content: center;
  gap: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(35, 31, 40, 0.08);
}

.locked-state h2 {
  margin: 0;
  font-size: 1.35rem;
}

.pin-avatar {
  display: grid;
  width: 76px;
  height: 76px;
  place-items: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 2rem;
  font-weight: 800;
}

.pin-dialog .pin-avatar {
  margin: 0 auto;
}

.toast-container {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  display: grid;
  gap: 8px;
  width: min(420px, calc(100vw - 28px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius);
  background: #2f2b33;
  color: #fff;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

@media (max-width: 760px) {
  .app-container {
    padding: 10px;
  }

  .app-header {
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 10px;
  }

  .profile-switcher,
  .search-container {
    grid-column: 1 / -1;
  }

  .profile-switcher {
    grid-row: 2;
  }

  .search-container {
    grid-row: 3;
  }

  .header-title {
    font-size: 1.08rem;
  }

  .groups-grid {
    grid-auto-flow: row;
    grid-auto-columns: initial;
    grid-template-columns: 1fr;
    grid-template-rows: none;
    min-height: auto;
    overflow-x: visible;
    padding-bottom: 86px;
  }

  .group-card {
    min-height: 170px;
  }

  .fab {
    right: 14px;
    bottom: 14px;
    width: 56px;
    padding: 0;
    border-radius: 18px;
  }

  .fab-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }
}
