:root {
  color-scheme: light;
  --bg: #eef2ff;
  --bg-2: #e2e8f0;
  --surface: rgba(255, 255, 255, 0.84);
  --surface-strong: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --border: rgba(15, 23, 42, 0.12);
  --accent: #1d4ed8;
  --accent-strong: #1e40af;
  --danger: #b91c1c;
  --shadow: 0 18px 60px rgba(15, 23, 42, 0.14);
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --content-width: 960px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.18), transparent 34%),
    radial-gradient(circle at bottom right, rgba(99, 102, 241, 0.16), transparent 28%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
}

button,
input,
textarea {
  font: inherit;
}

input,
textarea,
[contenteditable="true"] {
  user-select: text;
  -webkit-user-select: text;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(100%, var(--content-width));
  margin: 0 auto;
  height: 100dvh;
  padding: 20px;
}

.screen {
  height: calc(100dvh - 40px);
  min-height: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.screen[hidden] {
  display: none !important;
}

.selection-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  margin: 10px -4px -4px;
  padding: 4px 0 0;
  background: transparent;
  border-top: 0;
  box-shadow: none;
}

.selection-toolbar[hidden] {
  display: none;
}

.selection-toolbar button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 7px;
  color: #fff;
  background: transparent;
  border-radius: 8px;
}

.selection-toolbar button:hover,
.selection-toolbar button:focus-visible {
  background: rgba(255, 255, 255, 0.16);
  outline: none;
}

.selection-toolbar svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.selection-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar,
.editor-header,
.stats-bar,
.action-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.topbar {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.screen-list {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #352f68;
}

.screen-list .topbar,
.screen-list .stats-bar,
.screen-list .search-field,
.screen-list .selection-toolbar {
  flex: 0 0 auto;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  flex-wrap: nowrap;
}

.topbar-row-title {
  gap: 12px;
}

.topbar-row-actions {
  display: grid;
  grid-template-columns: max-content max-content max-content minmax(0, 1fr);
  gap: 8px;
  width: 100%;
  align-items: center;
}

.topbar > .status-group {
  justify-content: flex-start;
  margin: -2px 0 0;
}

.topbar-row-actions > * {
  min-width: 0;
}

.topbar-row-actions > .primary-button {
  width: 100%;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.eyebrow-line {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.app-version {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(29, 78, 216, 0.12);
  color: #fff;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  line-height: 1;
  white-space: nowrap;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: #fff;
  font-size: clamp(1.8rem, 4.8vw, 2.8rem);
  line-height: 1;
  white-space: nowrap;
}

h2 {
  margin-bottom: 8px;
  font-size: clamp(1.4rem, 4vw, 2rem);
}

.subtle,
.hint {
  color: var(--muted);
}

.search-field {
  display: block;
}

.screen-list > .search-field {
  margin-top: 12px;
}

.search-field input,
.editor-form textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;
}

.search-field input {
  padding: 15px 16px;
  min-height: 56px;
}

.topbar-row-search {
  width: 100%;
  margin-bottom: 12px;
}

.topbar-row-search input {
  width: 100%;
}

.editor-form textarea {
  min-height: min(56dvh, 520px);
  padding: 18px;
  resize: vertical;
  line-height: 1.5;
  font-size: 1rem;
}

.search-field input:focus,
.editor-form textarea:focus {
  outline: none;
  border-color: rgba(29, 78, 216, 0.55);
  box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.12);
}

.stats-bar {
  margin-bottom: 10px;
  padding: 0 2px;
  color: var(--muted);
  font-size: 0.95rem;
  justify-content: space-between;
  gap: 10px 12px;
  flex-wrap: nowrap;
  min-width: 0;
}

.stats-bar p {
  margin: 0;
}

.note-count-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  min-width: 0;
}

.status-group {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: nowrap;
  min-width: 0;
}

.sync-panel {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.62);
}

.sync-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
}

.sync-toggle input {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
}

.prefs-dialog {
  width: min(940px, calc(100vw - 32px));
  max-width: 940px;
  max-height: calc(100dvh - 32px);
  border: 0;
  padding: 0;
  background: transparent;
  overflow: hidden;
}

.prefs-dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(4px);
}

.prefs-dialog .sync-panel {
  max-height: calc(100dvh - 32px);
  margin: 0;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.24);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sync-panel-header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.prefs-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
  min-width: 180px;
}

.sync-panel h2 {
  margin-bottom: 6px;
  font-size: 1.25rem;
}

.sync-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 600;
}

.field input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.95);
}

.sync-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.sync-metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.sync-metrics p {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.78);
}

.sync-metrics span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.sync-metrics strong {
  font-size: 1rem;
}

.sync-status {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.93rem;
}

.notes-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1px 2px 4px;
  display: grid;
  gap: 8px;
  align-content: start;
}

.notes-list.is-selection-mode {
  padding-left: 36px;
}

#noteCount {
  color: #fff;
}

.screen-list.is-selection-mode .search-field {
  display: none;
}

.date-group {
  display: grid;
  gap: 6px;
}

.date-heading {
  margin: 6px 4px 0;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 700;
}

.note-card {
  border-radius: var(--radius-md);
  position: relative;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.note-select-control {
  display: none;
}

.is-selection-mode .note-card {
  display: block;
}

.is-selection-mode .note-select-control {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  z-index: 1;
  top: 50%;
  left: -32px;
  width: 24px;
  height: 24px;
  transform: translateY(-50%);
}

.note-select-checkbox {
  width: 20px;
  height: 20px;
  margin: 0;
}

.is-selection-mode .note-select-checkbox {
  appearance: none;
  border: 2px solid #fff;
  border-radius: 5px;
  background: transparent;
  accent-color: #fff;
}

.is-selection-mode .note-select-checkbox:checked {
  background: #fff;
  box-shadow: inset 0 0 0 4px #352f68;
}

.note-card * {
  user-select: none;
  -webkit-user-select: none;
}

.note-card.is-dragging {
  opacity: 0.45;
}

.note-drop-indicator {
  height: 4px;
  margin: -2px 4px;
  border-radius: 999px;
  background: #f97316;
  box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.18);
}

body.is-note-dragging {
  user-select: none;
  cursor: grabbing;
}

.note-card-button {
  width: 100%;
  display: block;
  padding: 10px 12px 9px;
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  text-align: left;
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.05);
}

.note-card.is-pinned .note-card-button {
  background: #d9f1ff;
  border-color: #93c5fd;
}

.is-selection-mode .note-card-button {
  padding-left: 12px;
}

.note-card-button:hover {
  transform: translateY(-1px);
}

.note-card-body {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 3px;
  align-items: start;
}

.note-card-date {
  grid-column: 1;
  grid-row: 1;
  display: block;
  color: var(--text);
  font-size: 0.84rem;
  line-height: 1.22;
  white-space: nowrap;
  text-align: right;
  transform: translateY(3px);
}

.note-card-time {
  grid-column: auto;
  grid-row: auto;
  display: block;
  color: var(--accent-strong);
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1;
  text-align: right;
}

.note-card-status {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
  padding: 0;
  align-self: stretch;
}

.note-status-icons {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.note-photo-icon {
  display: block;
  width: 17px;
  height: 17px;
}

.note-card-preview {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: stretch;
  margin: 0;
  color: var(--text);
  line-height: 1.22;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.95rem;
  min-width: 0;
  padding-left: 0;
}

.status-icon {
  width: 16px;
  height: 16px;
  display: block;
  flex: 0 0 auto;
}

.status-icon-synced {
  filter: none;
}

.status-icon-pending {
  opacity: 0.9;
}

.status-icon-error {
  opacity: 0.95;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(29, 78, 216, 0.08);
  color: var(--accent-strong);
  font-size: 0.8rem;
  font-weight: 700;
}

.connection-pill {
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  flex: 0 0 auto;
}

.status-pill-label {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: inherit;
  opacity: 0.8;
}

.status-icon-svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status-icon-image {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  display: block;
  object-fit: contain;
}

.connection-pill strong {
  font-size: 0.84rem;
  font-weight: 800;
}

.status-state-online {
  background: rgba(22, 163, 74, 0.14);
  color: #15803d;
}

.status-state-offline {
  background: rgba(185, 28, 28, 0.14);
  color: var(--danger);
}

.status-state-checking {
  background: rgba(245, 158, 11, 0.16);
  color: #b45309;
}

.status-state-disabled {
  background: rgba(100, 116, 139, 0.16);
  color: #475569;
}

.screen-list .connection-pill {
  background: #d9efe4;
}

.screen-list .connection-pill.status-state-offline {
  background: #e8d2da;
}

.screen-list .connection-pill.status-state-checking {
  background: #f6e8c8;
}

.screen-list .connection-pill.status-state-disabled {
  background: #e5e7eb;
}

.status-pill.pending {
  background: rgba(245, 158, 11, 0.14);
  color: #b45309;
}

.status-pill.error {
  background: rgba(185, 28, 28, 0.14);
  color: var(--danger);
}

.editor-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  margin-bottom: 16px;
}

.editor-header .primary-button {
  margin-left: auto;
  width: auto;
}

.editor-meta {
  margin-bottom: 14px;
}

.editor-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.editor-title {
  margin-bottom: 8px;
}

.editor-title-row .editor-title {
  margin-bottom: 8px;
}

.camera-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 48px;
  height: 42px;
  padding: 5px;
  color: var(--text);
  background: transparent;
  border-radius: 10px;
}

.camera-button:hover,
.camera-button:focus-visible {
  background: rgba(29, 78, 216, 0.08);
  outline: none;
}

.camera-button img {
  display: block;
  width: 38px;
  height: 38px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.meta-grid p {
  margin-bottom: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.62);
}

.meta-grid span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.meta-grid strong {
  font-size: 0.98rem;
}

.hint {
  margin: 12px 0 0;
  font-size: 0.93rem;
}

.action-row {
  justify-content: flex-end;
  margin-top: 16px;
}

.editor-form {
  display: grid;
  gap: 0;
}

.photo-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.photo-select-button {
  min-height: 40px;
  padding: 0 14px;
}

.editor-photos {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.editor-photos:empty {
  display: none;
}

.editor-photo {
  min-width: 0;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #e2e8f0;
}

.editor-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.editor-photo-missing {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  color: var(--muted);
  text-align: center;
  font-size: 0.78rem;
}

.primary-button,
.ghost-button,
.danger-button {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  font-weight: 700;
  white-space: nowrap;
}

.primary-button {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 12px 28px rgba(29, 78, 216, 0.24);
}

.ghost-button {
  color: var(--text);
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--border);
}

.danger-button {
  color: #fff;
  background: linear-gradient(135deg, #ef4444, var(--danger));
}

.small-button {
  min-height: 40px;
  padding: 0 14px;
  font-size: 0.92rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.empty-state,
.error-state {
  padding: 28px 18px;
  border: 1px dashed rgba(71, 85, 105, 0.32);
  border-radius: var(--radius-md);
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.4);
}

@media (max-width: 720px) {
  .app-shell {
    padding: 12px;
  }

  .screen {
    height: calc(100dvh - 24px);
    padding: 14px;
    border-radius: 20px;
  }

  .screen-editor {
    display: flex;
    flex-direction: column;
  }

  .screen-editor[hidden] {
    display: none !important;
  }

  .topbar,
  .stats-bar {
    flex-direction: row;
    align-items: center;
  }

  .topbar {
    gap: 8px;
    margin-bottom: 10px;
  }

  .topbar > .status-group {
    gap: 8px;
  }

  .topbar-row {
    gap: 8px;
  }

  .note-count-group {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }

  .editor-header {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
  }

  .editor-meta {
    margin-bottom: 8px;
  }

  .editor-title {
    display: block;
    margin-bottom: 6px;
    font-size: 1.6rem;
    line-height: 1.08;
  }

  .camera-button {
    width: 44px;
    height: 40px;
  }

  .camera-button img {
    width: 36px;
    height: 36px;
  }

  .meta-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .meta-grid p {
    padding: 10px 12px;
  }

  .meta-grid span {
    margin-bottom: 4px;
    font-size: 0.75rem;
  }

  .meta-grid strong {
    font-size: 0.88rem;
  }

  .editor-form {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .editor-form textarea {
    min-height: 0;
    flex: 0 0 auto;
    height: min(26dvh, 190px);
    padding: 14px;
    font-size: 0.98rem;
  }

  .photo-actions {
    margin-top: 4px;
  }

  .editor-photos {
    gap: 8px;
  }

  .action-row {
    display: block;
    margin-top: 10px;
  }

  .note-card-button {
    padding: 9px 11px 8px;
  }

  .note-card-body {
    column-gap: 8px;
    row-gap: 4px;
  }

  .sync-panel-header,
  .sync-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .prefs-dialog {
    width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    margin: 12px;
  }

  .prefs-dialog .sync-panel {
    max-height: calc(100dvh - 24px);
    padding-bottom: 18px;
  }

  .prefs-actions {
    min-width: 0;
  }

  .sync-grid {
    grid-template-columns: 1fr;
  }

  .sync-metrics {
    grid-template-columns: 1fr 1fr;
  }

  .primary-button,
  .ghost-button,
  .danger-button {
    width: auto;
    min-height: 40px;
    padding: 0 10px;
    font-size: 0.92rem;
  }

  .selection-toolbar {
    margin-top: 8px;
  }

  .primary-button {
    padding: 0 12px;
  }

  .sync-toggle {
    min-height: 40px;
    padding: 0 8px;
  }

  .sync-toggle input {
    width: 20px;
    height: 20px;
  }

  .sync-actions {
    position: sticky;
    bottom: 0;
    margin-top: 12px;
    padding-top: 10px;
    padding-bottom: 2px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.92) 24%);
    z-index: 1;
  }

  .editor-header .ghost-button,
  .editor-header .danger-button,
  .editor-header .primary-button {
    width: auto;
  }
}
