:root {
  color-scheme: dark;
  --bg: #121312;
  --panel: #1b1d1a;
  --panel-strong: #23261f;
  --text: #f5f1e8;
  --muted: #a8aca0;
  --line: #36392f;
  --accent: #8fcf9f;
  --accent-strong: #dbb05f;
  --danger: #ef7770;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root.light {
  color-scheme: light;
  --bg: #f5f2ea;
  --panel: #fffdf7;
  --panel-strong: #ebe7dc;
  --text: #20221f;
  --muted: #6c7168;
  --line: #ded8c9;
  --accent: #277a57;
  --accent-strong: #af7432;
  --danger: #be3f39;
  --shadow: 0 18px 50px rgba(61, 55, 44, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-content: center;
  gap: 16px;
  background: var(--bg);
  transition: opacity 320ms ease, visibility 320ms ease;
}

.splash.done {
  opacity: 0;
  visibility: hidden;
}

.splash-mark,
.app-mark {
  display: grid;
  place-items: center;
  width: 58px;
  aspect-ratio: 1;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  color: #10120f;
  font-weight: 900;
  font-size: 1.65rem;
  box-shadow: var(--shadow);
}

.splash-mark {
  animation: breathe 1.2s ease-in-out infinite alternate;
}

.splash-name {
  color: var(--muted);
  letter-spacing: 0;
  text-align: center;
}

@keyframes breathe {
  from {
    transform: scale(0.96);
  }
  to {
    transform: scale(1.04);
  }
}

.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-lockup h1,
.topbar h1,
.detail-pane h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand-lockup p,
.topbar p,
.empty-state p {
  margin: 4px 0 0;
  color: var(--muted);
}

.brand-lockup.compact {
  margin-bottom: 24px;
}

.brand-lockup.compact .app-mark {
  width: 42px;
  border-radius: 10px;
  font-size: 1.2rem;
}

.login-form,
.entry-dialog form {
  display: grid;
  gap: 16px;
}

label,
.field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  padding: 12px 13px;
  outline: none;
  font-size: 16px;
}

textarea {
  resize: vertical;
  min-height: 150px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.primary-button,
.ghost-button,
.nav-item,
.icon-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  background: transparent;
  color: var(--text);
}

.primary-button {
  background: var(--accent);
  color: #10120f;
  font-weight: 800;
}

.ghost-button {
  border-color: var(--line);
  background: var(--panel);
}

.ghost-button.danger,
.danger {
  color: var(--danger);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  text-align: left;
}

.text-button:disabled {
  cursor: default;
  opacity: 0.7;
}

.form-error {
  min-height: 1.2em;
  margin: 0;
  color: var(--danger);
}

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 252px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
}

.nav-list {
  display: grid;
  gap: 8px;
  margin-bottom: auto;
}

.nav-item {
  width: 100%;
  text-align: left;
  color: var(--muted);
}

.nav-item.active,
.nav-item:hover {
  background: var(--panel-strong);
  color: var(--text);
}

.sidebar-meta {
  display: grid;
  gap: 6px;
  padding: 4px 2px 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.quick-search {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 170px 180px;
  gap: 10px;
  margin-bottom: 16px;
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tag-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 7px 11px;
}

.tag-pill.active {
  border-color: var(--accent);
  color: var(--text);
}

.tag-badge,
.tag-suggestion,
.tag-row {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.tag-badge {
  color: var(--muted);
}

.tag-dot {
  width: 9px;
  aspect-ratio: 1;
  flex: 0 0 auto;
  border-radius: 50%;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--text) 14%, transparent);
}

.tag-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 0;
}

.tag-suggestion {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--text);
  padding: 7px 10px;
}

.tag-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 120px auto;
  gap: 12px;
  align-items: end;
}

.tag-list {
  display: grid;
  gap: 10px;
}

.tag-row {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) 82px auto auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.tag-row input[type="color"] {
  min-width: 0;
  padding: 4px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.entries-list {
  display: grid;
  gap: 12px;
}

.entry-card {
  display: grid;
  grid-template-columns: 1fr 86px;
  gap: 12px;
  width: 100%;
  min-height: 116px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
  color: var(--text);
  text-align: left;
}

.entry-card.active,
.entry-card:hover {
  border-color: var(--accent);
}

.entry-meta,
.detail-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.entry-card h2 {
  margin: 6px 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.entry-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.entry-card img {
  width: 86px;
  height: 86px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--panel-strong);
}

.count-row,
.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.detail-pane {
  min-height: calc(100dvh - 150px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: var(--panel);
}

.detail-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 14px;
}

.detail-text {
  white-space: pre-wrap;
  line-height: 1.65;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.gallery img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
}

.audio-list {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

audio {
  width: 100%;
}

.entry-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.entry-dialog::backdrop {
  background: rgba(0, 0, 0, 0.52);
}

.dialog-header,
.dialog-actions,
.section-heading,
.editor-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-header h2,
.section-heading h3 {
  margin: 0;
  letter-spacing: 0;
}

.icon-button {
  width: 42px;
  padding: 0;
  border-color: var(--line);
  background: var(--panel-strong);
}

.upload-tile {
  flex: 1;
  min-height: 86px;
  place-content: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  text-align: center;
}

.upload-tile input {
  display: none;
}

.favorite-toggle {
  min-width: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.favorite-toggle input {
  width: auto;
}

.share-section {
  display: grid;
  gap: 10px;
}

.share-users {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.share-user {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  padding: 9px 12px;
}

.share-user input {
  width: auto;
}

.media-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.media-preview img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  object-fit: cover;
}

.recording-status {
  color: var(--muted);
  font-size: 0.9rem;
  min-height: 1.4em;
}

.recording-status.is-recording {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 50%, var(--line));
  border-radius: 999px;
  background: color-mix(in srgb, var(--danger) 14%, var(--panel));
  color: var(--text);
}

.record-dot {
  width: 10px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 900ms ease-in-out infinite alternate;
}

.record-bars {
  display: inline-flex;
  align-items: end;
  gap: 3px;
  height: 16px;
}

.record-bars i {
  width: 4px;
  border-radius: 999px;
  background: var(--accent);
  animation: level 780ms ease-in-out infinite alternate;
}

.record-bars i:nth-child(1) {
  height: 8px;
}

.record-bars i:nth-child(2) {
  height: 14px;
  animation-delay: 140ms;
}

.record-bars i:nth-child(3) {
  height: 10px;
  animation-delay: 280ms;
}

@keyframes pulse {
  from {
    opacity: 0.45;
  }
  to {
    opacity: 1;
  }
}

@keyframes level {
  from {
    transform: scaleY(0.45);
  }
  to {
    transform: scaleY(1);
  }
}

.audio-preview-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.settings-pane {
  display: grid;
  gap: 18px;
  grid-column: 1 / -1;
}

.settings-section {
  display: grid;
  gap: 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.settings-section:first-of-type {
  padding-top: 0;
  border-top: 0;
}

.settings-section h3 {
  margin: 0;
  letter-spacing: 0;
}

.settings-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 12px;
  align-items: end;
}

.settings-message {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
}

.users-list {
  display: grid;
  gap: 8px;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.user-row div {
  display: grid;
  gap: 3px;
}

.user-row > div {
  min-width: 0;
}

.user-roles-form {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.user-edit-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.role-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.role-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  padding: 7px 10px;
}

.role-check input {
  width: auto;
}

.user-row span,
.user-self {
  color: var(--muted);
  font-size: 0.9rem;
}

.user-delete-button {
  min-height: 36px;
}

.mobile-new-button {
  display: none;
}

.mobile-menu-button,
.mobile-menu,
.mobile-menu-backdrop {
  display: none;
}

@media (max-width: 880px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .workspace {
    padding: max(16px, env(safe-area-inset-top)) 14px calc(88px + env(safe-area-inset-bottom));
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar .primary-button {
    display: none;
  }

  .quick-search {
    grid-template-columns: 1fr;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .detail-pane {
    min-height: auto;
  }

  .entry-card {
    grid-template-columns: 1fr 72px;
  }

  .entry-card img {
    width: 72px;
    height: 72px;
  }

  .mobile-new-button {
    position: fixed;
    right: 18px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    z-index: 8;
    display: grid;
    place-items: center;
    width: 62px;
    aspect-ratio: 1;
    border: 0;
    border-radius: 50%;
    background: var(--accent);
    color: #10120f;
    font-size: 2.1rem;
    font-weight: 700;
    box-shadow: var(--shadow);
  }

  .mobile-menu-button {
    position: fixed;
    left: 18px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    z-index: 10;
    display: grid;
    place-items: center;
    width: 56px;
    aspect-ratio: 1;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--panel-strong);
    color: var(--text);
    font-size: 1.45rem;
    font-weight: 800;
    box-shadow: var(--shadow);
  }

  .mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 11;
    display: block;
    background: rgba(0, 0, 0, 0.44);
  }

  .mobile-menu-backdrop[hidden] {
    display: none;
  }

  .mobile-menu {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(88px + env(safe-area-inset-bottom));
    z-index: 12;
    display: grid;
    gap: 16px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    transform: translateY(18px);
    opacity: 0;
    pointer-events: none;
    transition: transform 180ms ease, opacity 180ms ease;
  }

  .mobile-menu.open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .mobile-menu-header .brand-lockup.compact {
    margin-bottom: 0;
  }

  .mobile-menu-list,
  .mobile-menu-actions {
    display: grid;
    gap: 8px;
  }

  .mobile-menu-item {
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    padding: 10px 12px;
    text-align: left;
  }

  .mobile-menu-item.active {
    border-color: var(--line);
    background: var(--panel-strong);
    color: var(--text);
  }

  .sidebar-meta.mobile {
    padding-top: 8px;
  }

  .entry-dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .settings-form {
    grid-template-columns: 1fr;
  }

  .tag-form,
  .tag-row,
  .user-edit-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .login-panel {
    padding: 22px;
  }

  .editor-row,
  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .favorite-toggle {
    min-height: 56px;
  }
}
