@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&display=swap');

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

:root {
  --bg: #f0f1f5;
  --surface: #ffffff;
  --surface-hover: #f8f9fb;
  --text: #1a1d2e;
  --text-secondary: #6b7194;
  --accent: #3d5af1;
  --accent-light: #eef1ff;
  --accent-hover: #2d48d9;
  --danger: #e74c5e;
  --danger-light: #fef0f1;
  --pin: #b57400;
  --pin-light: #fff5df;
  --border: #e8eaef;
  --shadow-sm: 0 1px 3px rgba(26, 29, 46, 0.04);
  --shadow-md: 0 4px 16px rgba(26, 29, 46, 0.06);
  --shadow-lg: 0 8px 32px rgba(26, 29, 46, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --search-sticky-top: 45px;
  --app-height: 100vh;
  --modal-viewport-height: 100vh;
  --modal-viewport-top: 0px;
  --keyboard-offset: 0px;
}

body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: var(--app-height);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.scroll-locked {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  overflow: hidden;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(16px);
  background: rgba(255, 255, 255, 0.88);
}

header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.header-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: color-mix(in srgb, currentColor 12%, transparent);
  border: none;
  color: var(--text-secondary);
  font-size: 1.3rem;
  font-weight: 300;
  transition: all 0.15s ease;
  line-height: 1;
}

.header-btn:hover {
  color: var(--accent);
}

#fab {
  color: rgba(61, 90, 241, 0.7);
}

#fab:hover {
  color: var(--accent);
}

#open-settings {
  color: rgba(107, 113, 148, 0.7);
}

.header-btn-danger {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--danger);
}

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

.header-btn-hidden {
  visibility: hidden;
  pointer-events: none;
}

/* ── Main ── */
main {
  padding: 0.75rem 1rem 5rem;
  display: grid;
  gap: 0.75rem;
  max-width: 520px;
  margin: 0 auto;
}


/* ── Form ── */
label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.65rem;
}

input,
select,
textarea {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 0.6rem 0.75rem;
  font-size: 0.88rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61, 90, 241, 0.1);
}

input::placeholder,
textarea::placeholder {
  color: #b0b5c9;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #8f94b4 50%), linear-gradient(135deg, #8f94b4 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% + 1px), calc(100% - 13px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2rem;
}

form button[type="submit"] {
  width: 100%;
  margin-top: 0.25rem;
}

/* ── Buttons ── */
button {
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: all 0.15s ease;
}

button:hover {
  background: var(--accent-hover);
}

button:active {
  transform: scale(0.97);
}

button.ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 0.35rem 0.6rem;
  font-size: 0.78rem;
  border: none;
}

button.ghost:hover {
  background: var(--accent-light);
  color: var(--accent);
}

/* ── Search Container ── */
.search-container {
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  max-width: 100%;
  position: sticky;
  top: var(--search-sticky-top);
  z-index: 9;
}

.search-wrapper {
  max-width: 520px;
  margin: 0 auto;
}

.search-bar {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: #9a9db3;
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: #e3e4ea;
  border: none;
  border-radius: 10px;
  padding: 0.65rem 1rem 0.65rem 2.4rem;
  font-size: 0.88rem;
  color: var(--text);
}

.search-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(61, 90, 241, 0.15);
  background: #dcdde5;
}

/* ── Search Filters ── */
.search-filters {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.55rem;
  overflow-x: auto;
  padding-bottom: 0.15rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.search-filters::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  appearance: none;
  border: 1px solid rgba(26, 29, 46, 0.08);
  background: #e3e4ea;
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  user-select: none;
  white-space: nowrap;
}

.filter-chip:hover {
  color: var(--text);
  background: #dcdde5;
}

.filter-chip:active {
  transform: scale(0.98);
}

.filter-chip:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(61, 90, 241, 0.18);
}

.filter-chip.is-active {
  background: var(--accent-light);
  color: var(--accent);
  border-color: rgba(61, 90, 241, 0.25);
}

/* ── Items List ── */
.items {
  list-style: none;
  display: grid;
  gap: 0.5rem;
  min-width: 0;
}

.item {
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.12s ease, box-shadow 0.12s ease;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  border-left: 3px solid var(--border);
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.item.item-pinned {
  background: var(--pin-light);
  border-left-color: var(--pin);
}

.item p.item-text {
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.45;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
  margin: 0;
}

.item .item-time {
  color: #999;
  font-size: 0.72rem;
  font-weight: 400;
  margin-top: 0.1rem;
}

.item .item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.1rem;
}

.item .item-meta .item-time {
  margin-top: 0;
}

.item .item-expiry {
  color: #999;
  font-size: 0.72rem;
  font-weight: 500;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.22rem;
}

.item .item-expiry.item-expiry-urgent {
  color: var(--danger);
}

.item .item-expiry em {
  font-style: italic;
}

.item .expiry-indicator {
  flex-shrink: 0;
}

.item a.item-link {
  width: 100%;
  max-width: 100%;
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 500;
  text-decoration: none;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
}

.item a:hover {
  text-decoration: underline;
}

/* ── Selection Header ── */
.header-selection {
  background: var(--accent);
  color: #fff;
  padding: 0.65rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 10;
  animation: slideDown 0.2s ease;
}

.header-selection[hidden] {
  display: none;
}

.header-selection #selection-count {
  font-size: 1.05rem;
  font-weight: 700;
  flex: 1;
}

.selection-actions {
  display: flex;
  gap: 0.25rem;
}

.selection-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: transparent;
  color: #fff;
  font-size: 1.15rem;
  border: none;
  cursor: pointer;
  transition: background 0.12s ease;
}

.selection-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.selection-btn:active {
  transform: scale(0.92);
}

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

.selection-btn:disabled:hover {
  background: transparent;
}

.selection-btn:disabled:active {
  transform: none;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-100%); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Item tap / selection states ── */
.item {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.item:active:not(.item-selected) {
  background: var(--surface-hover);
}

.item.item-selected {
  background: var(--accent-light);
  border-color: rgba(61, 90, 241, 0.2);
  border-left-color: var(--accent);
}

/* ── Pin indicator ── */
.item .pin-indicator {
  display: inline-block;
  vertical-align: -1px;
  opacity: 0.7;
  color: var(--pin);
}

/* ── File Preview ── */
.file-preview {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.file-item {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem;
  display: grid;
  gap: 0.25rem;
}

.file-item img {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.file-item img:hover {
  opacity: 0.85;
}

/* ── Lightbox ── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(8px);
  z-index: 150;
  display: grid;
  place-items: center;
  padding: 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: overlayIn 0.2s ease;
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  animation: modalIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.lightbox-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 1rem;
  z-index: 151;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.file-item figcaption {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.file-item a,
.file-item span {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 0.82rem;
}

/* ── Empty State ── */
.empty {
  border: 1px dashed var(--border);
  background: linear-gradient(180deg, #ffffff, #f6f8ff);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1rem;
}

.empty-default {
  display: grid;
  gap: 0.45rem;
}

.empty-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text);
}

.empty-subtitle {
  font-size: 0.82rem;
  font-weight: 500;
}

.empty-steps {
  padding-left: 1.1rem;
  margin: 0.1rem 0;
  display: grid;
  gap: 0.3rem;
}

.empty-steps li {
  color: var(--text-secondary);
  font-size: 0.84rem;
  line-height: 1.4;
}

.empty-tip {
  font-size: 0.78rem;
  color: #8a90b2;
}

.empty-search {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.84rem;
  padding: 1.2rem 0.75rem;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  width: min(calc(100vw - 1.5rem), 30rem);
  max-width: 30rem;
  padding: 0.7rem 1rem;
  border-radius: 14px;
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  box-shadow: var(--shadow-lg);
  white-space: normal;
  overflow-wrap: anywhere;
  z-index: 200;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 640px) {
  .toast {
    width: min(calc(100vw - 1rem), 26rem);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 0.75rem);
    padding: 0.8rem 0.95rem;
    border-radius: 16px;
    font-size: 0.82rem;
  }
}



/* ── Modal ── */
.modal-overlay {
  position: fixed;
  top: var(--modal-viewport-top);
  right: 0;
  left: 0;
  height: var(--modal-viewport-height);
  background: rgba(26, 29, 46, 0.4);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-padding-block-end: calc(1rem + var(--keyboard-offset));
  animation: overlayIn 0.2s ease;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 400px;
  max-height: calc(var(--modal-viewport-height) - 2rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  text-transform: none;
  letter-spacing: -0.01em;
  margin: 0;
}

.modal-close {
  width: 30px;
  height: 30px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.modal-close:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.settings-note {
  font-size: 0.76rem;
  color: var(--text-secondary);
  margin-top: -0.1rem;
  margin-bottom: 0.7rem;
}

.settings-note-compact {
  margin-top: 0;
  margin-bottom: 0;
}

.settings-section {
  display: grid;
  gap: 0.75rem;
  padding-top: 0.25rem;
  border-top: 1px solid rgba(26, 29, 46, 0.08);
}

.settings-auth-group {
  display: grid;
  gap: 0.65rem;
}

.settings-auth-group[hidden] {
  display: none;
}

.settings-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.settings-section-head h3 {
  font-size: 0.95rem;
  margin: 0;
}

.settings-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
}

.settings-toggle input {
  width: auto;
  min-height: auto;
  margin: 0;
}

.sync-status {
  margin: 0;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: rgba(61, 90, 241, 0.08);
  color: var(--accent);
  font-size: 0.8rem;
  line-height: 1.4;
}

.settings-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.settings-actions-compact {
  margin-top: -0.15rem;
}

.settings-actions > * {
  flex: 1 1 10rem;
}

.secondary-btn {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(61, 90, 241, 0.2);
  box-shadow: none;
}

.secondary-btn:hover {
  background: rgba(61, 90, 241, 0.08);
}

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Share page ── */
.share {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.share .card {
  text-align: center;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  header,
  main {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}

/* ── Entrance animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.item {
  animation: fadeIn 0.25s ease both;
}

.item:nth-child(1) { animation-delay: 0.04s; }
.item:nth-child(2) { animation-delay: 0.08s; }
.item:nth-child(3) { animation-delay: 0.12s; }
.item:nth-child(4) { animation-delay: 0.16s; }
.item:nth-child(5) { animation-delay: 0.2s; }
