/* Theme values follow Linka's cream background, blue accent and white surfaces. */
:root {
  --header-height: 56px;
  --color-background: #e9e5dc;
  --color-sidebar: #e4e0d6;
  --color-sidebar-selected: #d6d2c8;
  --color-surface: #ffffff;
  --color-text: #1f2937;
  /* Secondary text stays readable on both the cream backgrounds and white cards. */
  --color-muted: #4b5563;
  --color-border: #d6d2c8;
  --color-primary: #0000a5;
  --color-primary-hover: #000083;
  --color-secondary: #249b3a;
  --color-hover: #f2f0eb;
  --color-selected: #e5e5f4;
  --color-danger: #b91c1c;
  /* Both views share a landscape frame; images fill it without stretching. */
  --preview-aspect-ratio: 16 / 9;
  --shadow-card: 0 1px 3px rgb(0 0 0 / 8%);
  --shadow-hover: 0 2px 5px rgb(0 0 0 / 8%);

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  font-synthesis: none;
  color: var(--color-text);
  background: var(--color-background);
}

/* Base elements and keyboard focus */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  color: inherit;
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 4px;
}

button {
  border: 0;
  background: none;
}

input,
textarea,
select {
  color: var(--color-text);
}

.icon {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
  vertical-align: middle;
}

.icon-button {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  flex-shrink: 0;
  color: var(--color-muted);
}

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

/* Sidebar and folder navigation */
.sidebar {
  --sidebar-padding: 18px;
  width: 240px;
  position: fixed;
  inset: var(--header-height) auto 0 0;
  padding: 24px var(--sidebar-padding) 18px;
  background: var(--color-sidebar);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 30;
}

/* Navigation scrolls independently below the fixed header. */
.sidebar-scroll {
  flex: 1;
  min-height: 0;
  /* Put native scrollbars at the outer edge, with room for macOS overlay expansion. */
  margin-right: calc(-1 * var(--sidebar-padding));
  padding-right: 24px;
  overflow-y: auto;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}

.sidebar-scroll > * {
  flex-shrink: 0;
}

.brand {
  flex-shrink: 0;
  max-width: min(28vw, 240px);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 24px;
  font-weight: 600;
  line-height: 32px;
}

.nav-label {
  font-size: 10px;
  letter-spacing: 1.5px;
  font-weight: 650;
  color: var(--color-muted);
  margin: 0 13px 12px;
}

.author-navigation {
  margin-top: 24px;
}

.nav-item {
  width: 100%;
  display: flex;
  gap: 11px;
  align-items: center;
  text-align: left;
  padding: 10px 12px;
  min-height: 40px;
  border-radius: 7px;
  font-size: 12px;
  color: var(--color-text);
  margin-bottom: 3px;
}

.nav-item:hover {
  background: var(--color-hover);
}

.nav-item.active {
  background: var(--color-sidebar-selected);
  color: var(--color-text);
  font-weight: 600;
}

/* Keep the focus ring inside the navigation's scroll area so it cannot be clipped. */
.sidebar :is(button, a):focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

.nav-item .icon {
  width: 17px;
  height: 17px;
  opacity: 1;
}

.nav-item > span:not(.count) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item .count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 500;
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
}

.nav-item.active .count {
  color: var(--color-muted);
}

.folder-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 30px 1px 4px 0;
}

.folder-heading .nav-label {
  margin-bottom: 0;
}

.folder-heading-actions {
  display: flex;
  gap: 2px;
}

.folder-heading .icon-button {
  width: 27px;
  height: 27px;
}

.folder-heading .icon {
  width: 15px;
  height: 15px;
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 35px;
}

.sidebar-bottom .nav-item {
  font-size: 12px;
}

/* Workspace and search header */
.workspace {
  margin-left: 240px;
  padding-top: var(--header-height);
}

.topbar {
  /* Match Linka's full-width blue header using the existing stylesheet. */
  position: fixed;
  inset: 0 0 auto;
  z-index: 40;
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  background: var(--color-primary);
  color: #ffffff;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 10%), 0 4px 6px -4px rgb(0 0 0 / 10%);
  font-family: ui-sans-serif, system-ui, sans-serif;
}

.topbar > .icon-button {
  color: #ffffff;
}

.topbar > .icon-button:hover {
  background: rgb(255 255 255 / 15%);
}

.topbar :is(button, a):focus-visible {
  outline-color: #ffffff;
}

.search-box {
  /* Center independently of the different widths of the brand and right-hand controls. */
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  margin-left: 0;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  width: clamp(180px, calc(100vw - 900px), 250px);
  min-width: 0;
  max-width: none;
  border-radius: 8px;
  padding: 0 11px;
  gap: 9px;
  height: 32px;
  color: var(--color-muted);
}

.search-box .icon {
  width: 16px;
  height: 16px;
}

.search-box input {
  border: 0;
  outline: 0!important;
  background: transparent;
  width: 100%;
  min-width: 0;
  font-size: 11px;
  padding: 10px 0;
}

.search-box:focus-within {
  box-shadow: 0 0 0 2px var(--color-selected);
  border-color: #a1b18f;
}

.search-box input::placeholder {
  color: var(--color-muted);
}

.search-box kbd {
  font-family: inherit;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-background);
  padding: 0 5px;
  font-size: 10px;
  line-height: 18px;
}

/* Shared buttons */
.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 9px 15px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 550;
  white-space: nowrap;
}

.primary-button {
  background: var(--color-primary);
  color: #fff;
}

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

.primary-button .icon {
  width: 16px;
  height: 16px;
}

.top-add {
  min-height: 32px;
  padding: 6px 12px;
  background: #ffffff;
  color: var(--color-primary);
}

.top-add:hover {
  background: var(--color-selected);
}

.paste-shortcut {
  color: var(--color-text);
  padding: 2px 4px;
  border: 1px solid currentColor;
  border-radius: 4px;
  font-family: inherit;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.2;
}

.secondary-button {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-muted);
}

.secondary-button:hover {
  background: var(--color-hover);
}

.danger-button {
  background: var(--color-danger);
  color: #fff;
}

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

/* Library controls share the compact header. */
main {
  padding: 24px 28px 0;
  min-height: calc(100vh - var(--header-height));
  display: flex;
  flex-direction: column;
}

.library-toolbar {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
}

.library-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

/* Settings use ordinary links and forms, with no router or build dependencies. */
.settings-view {
  --header-height: 56px;
}

.settings-view .topbar {
  display: flex;
  padding: 0 24px;
}

.settings-header-controls {
  display: flex;
  margin-left: auto;
}

.header-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid rgb(255 255 255 / 55%);
  border-radius: 6px;
  font-size: 12px;
}

.header-link:hover {
  background: rgb(255 255 255 / 15%);
}

.session-controls {
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
  font-size: 12px;
}

.session-controls > span {
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-link {
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: inherit;
  white-space: nowrap;
}

.session-link:hover {
  text-decoration: underline;
}

.settings-page {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto 28px;
}

.settings-page h1 {
  font-size: 24px;
  line-height: 1.3;
  margin: 0 0 20px;
}

.settings-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 22px;
  padding: 6px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
}

.settings-nav a {
  padding: 10px 14px;
  border-radius: 5px;
  font-size: 13px;
}

.settings-nav a.selected {
  background: var(--color-primary);
  color: #ffffff;
}

.settings-card {
  padding: 24px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
}

.settings-card h2 {
  font-size: 19px;
  margin: 0 0 18px;
}

.settings-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
  font-size: 12px;
  font-weight: 550;
}

.settings-form :is(input, select, textarea) {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid #8a8d91;
  border-radius: 6px;
  background: var(--color-surface);
  font-size: 13px;
}

.settings-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.settings-help,
#hosting-message {
  color: var(--color-muted);
  font-size: 12px;
  line-height: 1.7;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.settings-color-field {
  margin-top: 20px;
}

.settings-color-field label {
  margin-bottom: 8px;
}

.color-inputs {
  display: grid;
  grid-template-columns: 52px minmax(0, 240px);
  gap: 12px;
}

.color-inputs input[type="color"] {
  height: 40px;
  padding: 3px;
}

.settings-card-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.hosting-facts {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 12px 20px;
  margin: 24px 0;
  font-size: 12px;
  line-height: 1.6;
}

.hosting-facts dt {
  font-weight: 600;
}

.hosting-facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.hosting-check {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 12px;
  align-items: baseline;
  padding: 15px 0;
  border-top: 1px solid var(--color-border);
  font-size: 12px;
}

.hosting-check p {
  grid-column: 1 / -1;
  margin: 0;
  line-height: 1.6;
  color: var(--color-muted);
}

.check-badge {
  padding: 3px 7px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
}

.check-badge.pass {
  background: #dcfce7;
  color: #166534;
}

.check-badge.optional {
  background: #dbeafe;
  color: #1e40af;
}

.check-badge.attention {
  background: #fef3c7;
  color: #92400e;
}

.view-tools {
  display: flex;
  gap: 12px;
  align-items: center;
}

.sort-control {
  position: relative;
  display: flex;
  align-items: center;
}

.sort-control select,
.sort-toggle {
  border: 0;
  background: transparent;
  font-size: 10px;
  color: #ffffff;
  appearance: none;
  padding: 8px 22px 8px 8px;
  cursor: pointer;
}

.sort-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-right: 0;
  border-radius: 5px;
}

.sort-toggle > .icon {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.sort-control option {
  color: var(--color-text);
  background: var(--color-surface);
}

/* Match Linka's white menu, rounded border, and restrained shadow. */
.sort-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 1000;
  min-width: 195px;
  padding: 4px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 10%), 0 4px 6px -4px rgb(0 0 0 / 10%);
}

.sort-menu button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 4px;
  text-align: left;
  white-space: nowrap;
  font-size: 12px;
  line-height: 18px;
}

.sort-menu button:is(:hover, :focus-visible) {
  background: var(--color-sidebar-selected);
}

.sort-menu button:focus-visible {
  outline-color: var(--color-primary);
  outline-offset: -2px;
}

.sort-menu button:disabled {
  opacity: .5;
  cursor: default;
}

.sort-menu .icon {
  width: 15px;
  height: 15px;
  visibility: hidden;
}

.sort-menu [aria-checked="true"] .icon {
  visibility: visible;
}

.toolbar-divider {
  width: 1px;
  height: 18px;
  background: rgb(255 255 255 / 30%);
}

.view-switch {
  display: flex;
  flex-shrink: 0;
  background: var(--color-hover);
  padding: 3px;
  border-radius: 6px;
  gap: 2px;
}

.view-switch .icon-button {
  width: 27px;
  height: 25px;
  border-radius: 4px;
}

.view-switch .icon {
  width: 14px;
  height: 14px;
}

.view-switch .selected {
  background: var(--color-surface);
  box-shadow: 0 1px 3px #29391e0e;
  color: var(--color-primary);
}

/* Domain grouping uses the existing card and list layouts. */
.domain-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 4px 0 20px;
  font-size: 11px;
  color: var(--color-muted);
}

.domain-toolbar select {
  max-width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  font-size: 11px;
}

.domain-heading {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--color-border);
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.domain-heading span {
  color: var(--color-muted);
  font-size: 11px;
  font-weight: 400;
}

/* Bookmark cards */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 22px;
  align-items: start;
}

.bookmark-card {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
  position: relative;
  min-width: 0;
  box-shadow: var(--shadow-card);
}

.bookmark-card:hover {
  box-shadow: var(--shadow-hover);
  border-color: var(--color-border);
}

.card-preview {
  display: block;
  aspect-ratio: var(--preview-aspect-ratio);
  background: var(--preview-bg, #eef0e7);
  overflow: hidden;
  border-radius: 7px 7px 0 0;
  position: relative;
  border-bottom: 1px solid var(--color-border);
}

.card-preview img {
  position: absolute;
  width: 100%;
  height: 100%;
  inset: 0;
  /* Crop excess edges so different source ratios fill the same frame. */
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s;
}

.card-preview img.loaded {
  opacity: 1;
}

/* Small site icons stay small; ordinary preview images use the full image area. */
.card-preview img.site-icon {
  width: 48px;
  height: 48px;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
}

.preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-placeholder > span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: 1px solid #0000000b;
  background: #ffffff46;
  border-radius: 13px;
  color: var(--preview-ink, #7d8b6a);
  font-family: Georgia, serif;
  font-size: 26px;
}

/* Archive and external-link controls use the same overlay style. */
.preview-link {
  position: absolute;
  inset: 0;
}

.preview-action {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 12px;
  top: 12px;
  width: 28px;
  height: 28px;
  border: 1px solid #ffffffa0;
  border-radius: 7px;
  background: #ffffffe0;
  color: var(--color-muted);
  opacity: 0;
}

.archive-button {
  right: 46px;
}

.preview-message {
  position: absolute;
  left: 6px;
  bottom: 6px;
  max-width: calc(100% - 12px);
  padding: 3px 5px;
  border-radius: 4px;
  background: var(--color-surface);
  color: var(--color-muted);
  font-size: 9px;
  line-height: 12px;
}

.preview-action:hover,
.preview-action:focus-visible {
  background: var(--color-primary);
  color: #ffffff;
  border-color: var(--color-primary);
}

.preview-action .icon {
  width: 14px;
  height: 14px;
}

.bookmark-card:hover .preview-action,
.bookmark-card:focus-within .preview-action {
  opacity: 1;
}

.card-content {
  padding: 14px 15px 9px;
}

.card-source {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  height: 22px;
  color: var(--color-muted);
  font-size: 9px;
  letter-spacing: 0.1px;
}

.source-mark {
  position: relative;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  font-size: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--preview-bg);
  color: var(--preview-ink);
  font-weight: 600;
  flex-shrink: 0;
}

.source-site {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.source-mark img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  visibility: hidden;
}

.source-mark.has-favicon img {
  visibility: visible;
}

.source-mark.has-favicon .source-letter {
  visibility: hidden;
}

.source-domain {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.favorite-button {
  margin-left: auto;
  width: 25px;
  height: 25px;
  opacity: 0;
  color: var(--color-muted);
}

.favorite-button .icon {
  width: 14px;
  height: 14px;
}

.bookmark-card:hover .favorite-button,
.favorite-button:focus-visible,
.favorite-button.is-favorite {
  opacity: 1;
}

.favorite-button.is-favorite {
  color: #b7a16c;
}

.favorite-button.is-favorite .icon {
  fill: #e7d9b6;
}

.card-title {
  font-size: 13px;
  line-height: 1.65;
  font-weight: 550;
  letter-spacing: -0.1px;
  margin: 6px 0 15px;
  min-height: 43px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-title a:hover {
  color: var(--color-primary);
}

.card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  border-top: 1px solid #eae7df;
  padding-top: 6px;
  height: 34px;
}

.folder-tag {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 9px;
  color: var(--color-muted);
  min-width: 0;
}

.folder-tag span:first-child {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-border);
  flex-shrink: 0;
}

.folder-tag span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.more-button {
  width: 24px;
  height: 24px;
}

.more-button .icon {
  width: 16px;
  height: 16px;
}

.card-menu {
  position: relative;
}

.menu-popover {
  position: absolute;
  right: 0;
  top: 29px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: 0 7px 22px #27391a14;
  padding: 5px;
  min-width: 150px;
  border-radius: 8px;
  z-index: 20;
}

.menu-popover button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  text-align: left;
  border-radius: 4px;
  padding: 9px;
}

.menu-popover button:hover {
  background: var(--color-hover);
}

.menu-popover .icon {
  width: 14px;
  height: 14px;
}

.menu-popover .delete-action {
  color: var(--color-danger);
}

.bookmark-card.menu-open {
  z-index: 21;
}

/* Plain text notes */
.note-preview {
  width: 100%;
  text-align: left;
  aspect-ratio: var(--preview-aspect-ratio);
  padding: 23px 23px 15px;
  border-radius: 7px 7px 0 0;
  overflow: hidden;
  background: #f4f0e4;
  border-bottom: 1px solid #ebe4d2;
}

.note-preview > span {
  font-family: Georgia, serif;
  color: #7e745b;
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 14px 0;
}

/* Pagination and empty states */
.pagination {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px 0 20px;
  gap: 10px;
}

.pagination p {
  font-size: 10px;
  color: var(--color-muted);
  margin: 0;
  letter-spacing: 0.1px;
}

.pagination .secondary-button {
  padding: 10px 20px;
}

.pagination .icon {
  width: 14px;
  height: 14px;
}

.main-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 0 25px;
  margin-top: auto;
  border-top: 1px solid var(--color-border);
  font-size: 9px;
  color: var(--color-muted);
}

.main-footer > span:last-child {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.6px;
  color: var(--color-muted);
}

.filter-indicator {
  margin-right: auto;
  padding: 3px 6px;
  background: var(--color-selected);
  border-radius: 4px;
  font-size: 9px;
  color: var(--color-muted);
}

.empty-state {
  text-align: center;
  padding: 65px 12px 80px;
}

.empty-symbol {
  background: var(--color-hover);
  color: #94a17f;
  display: inline-flex;
  border-radius: 18px;
  padding: 18px;
  transform: rotate(-8deg);
  margin-bottom: 10px;
}

.empty-symbol .icon {
  width: 30px;
  height: 30px;
}

.empty-state h2 {
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.5px;
  margin: 12px 0;
}

.empty-state p {
  font-size: 12px;
  color: var(--color-muted);
  margin: 0 0 24px;
  line-height: 1.6;
}

.load-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid #e9cfbd;
  background: #fff7ee;
  color: #9a6c4b;
  padding: 15px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 12px;
}

/* Dialogs and forms */
.modal {
  padding: 30px;
  border: 1px solid var(--color-selected);
  border-radius: 16px;
  box-shadow: 0 25px 100px #28391c24;
  max-width: calc(100vw - 32px);
  width: 500px;
  color: var(--color-text);
  background: var(--color-background);
}

.modal::backdrop {
  background: #303c2560;
  backdrop-filter: blur(3px);
}

.small-modal {
  width: 400px;
}

.modal-heading {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  align-items: flex-start;
  margin-bottom: 23px;
}

.modal-heading h2 {
  font-size: 24px;
  font-weight: 550;
  letter-spacing: -0.7px;
  margin: 6px 0 0;
}

.modal-heading > .icon-button {
  margin: -4px -8px 0 0;
}

.type-tabs {
  display: flex;
  background: var(--color-hover);
  padding: 4px;
  border-radius: 8px;
  margin-bottom: 22px;
  gap: 4px;
}

.type-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex: 1;
  padding: 8px;
  font-size: 12px;
  border-radius: 5px;
  color: var(--color-muted);
}

.type-tab.active {
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: 0 1px 4px #293d1c0a;
}

.type-tab .icon {
  width: 15px;
  height: 15px;
}

.modal label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 11px;
  color: var(--color-muted);
  margin: 15px 0;
}

.modal input,
.modal textarea,
.modal select {
  width: 100%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: 11px 12px;
  border-radius: 7px;
  font-size: 12px;
  line-height: 1.5;
}

.modal input::placeholder,
.modal textarea::placeholder {
  color: var(--color-muted);
}

.modal textarea {
  resize: vertical;
  min-height: 80px;
}

.modal input[type="file"] {
  font-size: 10px;
  padding: 8px;
}

.modal input[type="file"]::file-selector-button {
  border: 0;
  background: var(--color-hover);
  padding: 6px 9px;
  border-radius: 4px;
  color: var(--color-muted);
  font: inherit;
  margin-right: 12px;
  cursor: pointer;
}

.modal-actions {
  display: flex;
  gap: 9px;
  justify-content: flex-end;
  margin-top: 25px;
  border-top: 1px solid var(--color-border);
  padding-top: 20px;
}

/* Folder definitions and their icon picker use native inputs and local SVGs. */
.folder-settings-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--color-border);
}

.folder-settings-row > .icon {
  width: 20px;
  height: 20px;
}

.folder-settings-row strong {
  font-size: 13px;
  overflow-wrap: anywhere;
}

.folder-settings-row p {
  margin: 5px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--color-muted);
  overflow-wrap: anywhere;
}

.folder-row-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.folder-remove {
  color: var(--color-danger);
}

.folder-delete-confirmation {
  grid-column: 2 / -1;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-hover);
}

.folder-delete-confirmation p {
  margin: 0 0 12px;
}

.folder-delete-confirmation .form-error {
  color: var(--color-danger);
}

.folder-delete-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  line-height: 1.5;
  cursor: pointer;
}

.folder-delete-option input {
  flex: none;
  margin: 3px 0 0;
  accent-color: var(--color-danger);
}

.folder-delete-option small {
  display: block;
  color: var(--color-muted);
  font-size: 12px;
}

.folder-editor {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}

.folder-editor textarea {
  min-height: 80px;
  resize: vertical;
}

.folder-editor .icon-choice {
  position: relative;
  margin: 0;
}

.folder-editor .icon-choice input {
  width: 1px;
  height: 1px;
  padding: 0;
}

.transfer-export {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}

#transfer-dialog h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

#transfer-dialog label {
  margin: 12px 0;
}

#transfer-dialog .modal-actions {
  margin-top: 16px;
  padding-top: 12px;
}

.folder-icon-picker {
  min-width: 0;
  margin: 15px 0;
  padding: 0;
  border: 0;
}

.folder-icon-picker legend {
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--color-muted);
}

.icon-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.modal .icon-choice {
  position: relative;
  margin: 0;
}

.icon-choice > span {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 44px;
  padding: 10px 6px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
}

.icon-choice .icon {
  width: 17px;
  height: 17px;
}

.icon-choice input:checked + span {
  background: var(--color-sidebar-selected);
  border-color: var(--color-primary);
}

.icon-choice input:focus-visible + span {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.modal-description {
  font-size: 12px;
  color: var(--color-muted);
  line-height: 1.7;
  margin-top: 0;
}

.modal-description code {
  background: var(--color-hover);
  border-radius: 3px;
  padding: 2px 4px;
  color: var(--color-primary);
}

.form-error {
  font-size: 11px;
  background: #faeee7;
  color: var(--color-danger);
  padding: 10px 12px;
  border-radius: 6px;
}

/* Feedback and accessibility */
.toast {
  position: fixed;
  bottom: 24px;
  left: calc(50% + 120px);
  transform: translateX(-50%);
  background: var(--color-primary);
  color: #f6f8f0;
  padding: 13px 20px;
  box-shadow: 0 5px 20px #25341a1f;
  border-radius: 9px;
  font-size: 12px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: calc(100vw - 35px);
}

.toast .icon {
  width: 15px;
  height: 15px;
  color: #d4d5f0;
}

.toast.error {
  background: var(--color-danger);
}

.mobile-menu,
.sidebar-scrim {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.skip-link {
  position: fixed;
  top: -70px;
  left: 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-primary);
  border-radius: 6px;
  padding: 12px;
  z-index: 100;
}

.skip-link:focus {
  top: 12px;
}

.skeleton-card {
  pointer-events: none;
}

.skeleton-image {
  aspect-ratio: var(--preview-aspect-ratio);
  background: #e9ede2;
  border-radius: 7px 7px 0 0;
}

.skeleton-line {
  background: #edf0e7;
  height: 10px;
  margin: 16px;
  border-radius: 3px;
  width: 70%;
}

.skeleton-line.short {
  width: 40%;
  height: 8px;
}

/* List view */
.card-grid.list-mode {
  grid-template-columns: 1fr;
  gap: 10px;
}

.list-mode .bookmark-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: stretch;
  /* A consistent row height keeps the preview ratio independent of title wrapping. */
  height: 68px;
}

.list-mode .card-preview,
.list-mode .note-preview {
  /* Let the row height determine the width of the landscape preview. */
  width: auto;
  height: 100%;
  min-width: 0;
  aspect-ratio: var(--preview-aspect-ratio);
  border-radius: 7px 0 0 7px;
  border-bottom: 0;
  border-right: 1px solid var(--color-border);
}

/* Two text rows leave room for padding without increasing the thumbnail height. */
.list-mode .card-content {
  display: grid;
  grid-template-columns: fit-content(40%) minmax(0, 1fr) 26px;
  grid-template-rows: minmax(26px, auto) 14px;
  gap: 2px 8px;
  align-items: center;
  align-content: center;
  padding: 6px 14px;
  min-width: 0;
  min-height: 0;
}

/* Flatten the existing wrappers so both views can share the same card markup. */
.list-mode .card-source,
.list-mode .card-bottom {
  display: contents;
}

.list-mode .card-title {
  grid-area: 1 / 1 / 2 / 3;
  min-height: 0;
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 16px;
}

.list-mode .source-site {
  grid-area: 2 / 1;
  min-width: 0;
  line-height: 14px;
}

.list-mode .folder-tag {
  grid-area: 2 / 2;
  line-height: 14px;
}

.list-mode .favorite-button {
  grid-area: 1 / 3;
  margin: 0;
  opacity: 1;
  width: 26px;
  height: 22px;
}

.list-mode .card-menu {
  grid-area: 2 / 3;
}

.list-mode .more-button {
  width: 26px;
  height: 22px;
}

.list-mode .note-preview {
  padding: 8px;
}

.list-mode .note-preview > span {
  font-size: 12px;
  line-height: 16px;
  margin: 0;
  -webkit-line-clamp: 2;
}

body:has(dialog[open]) {
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

/* Responsive layouts */
@media (min-width: 1800px) {
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  }
}

@media (max-width: 1400px) {
  .paste-shortcut {
    display: none;
  }

  .session-controls > span {
    max-width: 60px;
  }
}

@media (max-width: 1200px) {
  .sidebar {
    --sidebar-padding: 13px;
    width: 215px;
  }

  .workspace {
    margin-left: 215px;
  }

  .topbar {
    gap: 18px;
  }

  main {
    padding: 24px 28px 0;
  }

  .card-grid {
    gap: 18px;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }

  .toast {
    left: calc(50% + 107px);
  }

}

@media (max-width: 1200px) {
  :root {
    --header-height: 88px;
  }

  /* Keep the same controls in two compact rows when one row would crowd them. */
  .topbar {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-rows: 32px 32px;
    gap: 8px 10px;
    padding: 8px 16px;
  }

  .brand {
    grid-area: 1 / 1;
  }

  .mobile-menu {
    grid-area: 1 / 2;
  }

  .library-toolbar {
    display: contents;
  }

  .filter-indicator {
    display: none;
  }

  .view-tools {
    grid-area: 2 / 3 / 3 / 5;
    justify-self: end;
    max-width: 100%;
    min-width: 0;
  }

  .sort-control {
    min-width: 0;
  }

  .sort-control select,
  .sort-toggle {
    width: 100%;
    min-width: 0;
    text-overflow: ellipsis;
  }

  .top-add {
    grid-area: 2 / 1 / 3 / 3;
    justify-self: start;
  }

  .session-controls {
    grid-area: 1 / 4;
  }

  .search-box {
    position: static;
    left: auto;
    transform: none;
    grid-area: 1 / 3;
    width: 100%;
    max-width: none;
    margin-left: 0;
  }

  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
  }

  .card-content {
    padding: 11px 12px 7px;
  }

  .card-title {
    font-size: 12px;
  }

}

@media (max-width: 700px) {
  .settings-view .topbar {
    padding: 0 16px;
  }

  .settings-columns,
  .hosting-facts {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .settings-card {
    padding: 18px;
  }

  .settings-nav a {
    padding: 9px 10px;
    font-size: 12px;
  }

  .sidebar {
    transform: translateX(-100%);
    width: 240px;
    transition: transform 0.2s;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-scrim.open {
    display: block;
    position: fixed;
    inset: var(--header-height) 0 0;
    background: #22331650;
    z-index: 29;
  }

  .workspace {
    margin-left: 0;
  }

  .topbar .brand {
    font-size: 20px;
  }

  .mobile-menu {
    display: inline-flex;
  }

  .search-box kbd {
    display: none;
  }

  .top-add {
    padding: 6px 11px;
  }

  .top-add span {
    display: none;
  }

  .top-add .icon {
    width: 18px;
    height: 18px;
  }

  main {
    padding: 20px 20px 0;
  }

  .view-tools {
    gap: 8px;
  }

  .toolbar-divider {
    display: none;
  }

  .sort-control select,
  .sort-toggle {
    font-size: 9px;
  }

  .filter-indicator {
    font-size: 8px;
  }

  .favorite-button {
    opacity: 1;
  }

  .card-grid {
    gap: 14px;
  }

  .card-title {
    font-size: 11px;
    margin-top: 5px;
    min-height: 37px;
    line-height: 1.7;
  }

  .card-source {
    font-size: 8px;
    gap: 5px;
  }

  .source-mark {
    width: 12px;
    height: 12px;
    font-size: 7px;
  }

  .card-content {
    padding: 10px 11px 5px;
  }

  .card-bottom {
    height: 29px;
  }

  .folder-tag {
    font-size: 8px;
  }

  .favorite-button .icon {
    width: 13px;
    height: 13px;
  }

  .favorite-button {
    width: 22px;
    height: 22px;
  }

  .preview-placeholder > span {
    width: 38px;
    height: 38px;
    font-size: 23px;
    border-radius: 8px;
  }

  .toast {
    left: 50%;
    font-size: 11px;
    min-width: 200px;
  }

  .note-preview {
    padding: 16px;
  }

  .note-preview > span {
    font-size: 12px;
    margin-top: 10px;
    -webkit-line-clamp: 3;
  }

  .list-mode .bookmark-card {
    height: 60px;
  }

  .list-mode .card-content {
    padding: 6px 10px;
  }

  .list-mode .card-title {
    font-size: 11px;
    line-height: 14px;
  }

  .modal {
    padding: 23px;
  }

  .modal-heading h2 {
    font-size: 22px;
  }

  .modal-actions {
    gap: 7px;
  }

  .main-footer {
    font-size: 8px;
  }

  .main-footer > span:last-child {
    font-size: 14px;
  }
}

@media (max-width: 360px) {
  .card-grid {
    grid-template-columns: 1fr;
  }

  .card-title {
    font-size: 13px;
  }

  .card-source {
    font-size: 10px;
  }

  .folder-tag {
    font-size: 9px;
  }

}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* Touch devices cannot reveal hover-only controls. */
@media (hover: none) {
  .preview-action {
    opacity: 1;
    width: 34px;
    height: 34px;
  }

  .archive-button {
    right: 52px;
  }
}

/* Server capabilities also hide edit controls before JavaScript starts. */
body[data-can-edit="0"] :is(#add-open, #empty-add, .folder-heading-actions, #transfer-open, #export-library, .favorite-button, .archive-button, .card-menu),
body[data-can-admin="0"] #settings-open {
  display: none !important;
}

body[data-can-admin="0"] .settings-nav a:not([data-settings-tab="folders"]) {
  display: none;
}
.user-row {
  padding: 20px 0;
  border-bottom: 1px solid var(--color-border);
}
.user-row h3 {
  margin: 0 0 6px;
}
.user-row > p {
  margin: 0 0 12px;
  color: var(--color-muted);
}
.user-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.user-row details summary {
  cursor: pointer;
  padding: 6px 0;
}
.user-row details form {
  margin-top: 12px;
}
.settings-form .account-role {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.settings-form .account-role input {
  width: 18px;
  height: 18px;
}
/* Shared setup and Settings form sections. */
.privacy-options,
.account-password {
  min-width: 0;
  margin: 24px 0;
  padding: 16px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.privacy-options legend,
.account-password legend {
  padding: 0 6px;
  font-size: 14px;
  font-weight: 600;
}

:is(.setup-form, .settings-form) .privacy-options label {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
  margin: 16px 0;
  font-size: 14px;
  font-weight: 400;
}

.privacy-options input[type="radio"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--color-primary);
}

.privacy-options small {
  display: block;
  margin-top: 5px;
  color: var(--color-muted);
  font-size: 13px;
  line-height: 1.5;
}

.account-fields > :is(h2, h3) {
  margin: 0 0 18px;
  font-size: 20px;
}

.account-fields .account-label {
  display: block;
  margin: 18px 0 8px;
  font-size: 14px;
  font-weight: 600;
}

.account-fields > input,
.password-input {
  width: 100%;
  border: 1px solid #9ca3af;
  border-radius: 6px;
  background: var(--color-surface);
}

.account-fields > input,
.account-fields .password-input input {
  min-width: 0;
  height: 42px;
  padding: 8px 10px;
  font-size: 14px;
}

.password-input:focus-within {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
}

.password-input,
.password-actions {
  display: flex;
  align-items: center;
}

.password-input {
  padding-right: 4px;
}

.account-fields .password-input input {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  font-family: ui-monospace, monospace;
}

.password-input .icon-button {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  color: var(--color-text);
}

.password-input .icon-button:hover {
  background: var(--color-hover);
}

.password-actions {
  flex-wrap: wrap;
  gap: 12px;
}

.password-status,
.account-help {
  color: var(--color-muted);
  font-size: 13px;
  line-height: 1.5;
}

.account-help {
  margin: 12px 0;
}

#user-create-form {
  margin-top: 24px;
}
