:root {
  color-scheme: light dark;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-muted: #eef1f4;
  --text: #17191c;
  --muted: #626973;
  --border: #dce0e5;
  --accent: #126f5a;
  --accent-soft: #d9f1e9;
  --danger-soft: #fff0cf;
  --shadow: 0 2px 10px rgb(27 32 38 / 8%);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
button, input { font: inherit; letter-spacing: 0; }
button { color: inherit; }
button:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

.app-header {
  position: sticky;
  z-index: 10;
  top: 0;
  padding: max(.5rem, env(safe-area-inset-top)) 1rem .75rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
}

.title-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; gap: .5rem; }
h1 { margin: 0; overflow: hidden; font-size: 1.05rem; font-weight: 700; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.icon-button, .clear-button, .text-button, .page-button, .quick-nav button, .breadcrumbs button {
  min-height: 44px;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.icon-button { min-width: 44px; border-radius: 6px; font-size: 1.5rem; }
.icon-button:hover, .icon-button:active { background: var(--surface-muted); }
.icon-button:disabled { opacity: .35; cursor: default; }

.search-row { margin-top: .55rem; }
.search-box { display: grid; grid-template-columns: 1.5rem minmax(0, 1fr) 44px; align-items: center; min-height: 48px; padding-left: .75rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); color: var(--muted); }
.search-box input { width: 100%; min-width: 0; height: 46px; border: 0; outline: 0; background: transparent; color: var(--text); }
.clear-button { min-width: 44px; font-size: 1.4rem; }
.quick-nav { display: flex; gap: .5rem; margin-top: .5rem; }
.quick-nav button { flex: 1; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); font-size: .9rem; font-weight: 650; }

main { width: min(100%, 50rem); margin: 0 auto; padding: .75rem 1rem max(2rem, env(safe-area-inset-bottom)); }
.offline-banner { margin-bottom: .65rem; padding: .65rem .8rem; border: 1px solid #e8c36d; border-radius: 6px; background: var(--danger-soft); color: #694b00; font-size: .88rem; }
.breadcrumbs { display: flex; align-items: center; gap: .2rem; min-height: 44px; overflow-x: auto; scrollbar-width: none; white-space: nowrap; }
.breadcrumbs button { flex: none; min-width: 44px; padding: 0 .45rem; color: var(--accent); font-size: .86rem; font-weight: 650; }
.sync-status { margin: 0 0 .75rem; color: var(--muted); font-size: .78rem; }

.group-list, .clip-list { display: grid; gap: .65rem; }
.group-list:not(:empty) { margin-bottom: 1rem; }
.group-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 1rem; align-items: center; gap: .7rem; width: 100%; min-height: 58px; padding: .7rem .8rem; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); box-shadow: var(--shadow); text-align: left; cursor: pointer; }
.group-name { overflow-wrap: anywhere; font-weight: 700; }
.group-count { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.row-arrow { color: var(--muted); font-size: 1.25rem; }

.clip-card { padding: .85rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); cursor: copy; transition: border-color .15s, background-color .15s, transform .15s; }
.clip-card:active { transform: scale(.995); }
.clip-card.copied { border-color: var(--accent); background: var(--accent-soft); }
.clip-header { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; }
.clip-header h2 { min-width: 0; margin: .1rem 0; overflow-wrap: anywhere; font-size: .98rem; line-height: 1.35; }
.clip-actions { display: flex; flex: none; gap: .15rem; }
.clip-actions .icon-button { font-size: 1.2rem; color: var(--accent); }
.text-button { padding: 0 .55rem; color: var(--accent); font-size: .82rem; font-weight: 700; }
.clip-group { margin: .25rem 0 .5rem; overflow-wrap: anywhere; color: var(--muted); font-size: .74rem; }
.clip-preview { margin: 0; overflow: hidden; color: var(--text); font: .86rem/1.52 ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace; overflow-wrap: anywhere; white-space: pre-wrap; word-break: break-word; }
.clip-preview:not(.expanded) { max-height: 8.1em; }
.empty-state { padding: 2.5rem 1rem; color: var(--muted); text-align: center; }
.pagination { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .7rem; margin-top: 1rem; }
.page-button { border: 1px solid var(--border); border-radius: 6px; background: var(--surface); font-weight: 650; }
.page-button:disabled { opacity: .4; }

.toast { position: fixed; z-index: 20; left: 50%; bottom: max(1.4rem, env(safe-area-inset-bottom)); min-width: 7rem; padding: .7rem 1rem; border-radius: 6px; background: #1c2422; color: #fff; box-shadow: 0 6px 20px rgb(0 0 0 / 25%); text-align: center; opacity: 0; transform: translate(-50%, .5rem); transition: opacity .15s, transform .15s; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151719;
    --surface: #202327;
    --surface-muted: #2a2e33;
    --text: #f2f4f5;
    --muted: #aeb5bd;
    --border: #363b42;
    --accent: #65d1b6;
    --accent-soft: #183b33;
    --danger-soft: #3b301a;
    --shadow: 0 2px 10px rgb(0 0 0 / 20%);
  }
  .offline-banner { color: #f3d17f; }
  .toast { background: #edf5f2; color: #17211e; }
}

@media (min-width: 48rem) {
  .app-header { padding-inline: max(1rem, calc((100% - 48rem) / 2)); }
  .group-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
