:root {
  color-scheme: dark;
  --bg: #0f1117;
  --bg-soft: #121620;
  --panel: #171c26;
  --panel-soft: #1d2430;
  --panel-hover: #222a38;
  --field: #0f141d;
  --line: #2b3444;
  --line-soft: #202838;
  --text: #f1f6ff;
  --muted: #9aa8bc;
  --muted-2: #748197;
  --accent: #46b8ff;
  --accent-2: #7fd7ff;
  --accent-bg: #10263a;
  --danger: #ff6975;
  --danger-bg: #2a1720;
  --ok: #65d6a4;
  --radius: 8px;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

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

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--text);
  outline: none;
  padding: 11px 12px;
}

textarea {
  min-height: 360px;
  resize: vertical;
  line-height: 1.55;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(70, 184, 255, 0.9);
  box-shadow: 0 0 0 3px rgba(70, 184, 255, 0.13);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.svg-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  stroke: currentColor;
}

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

.login-panel {
  width: min(410px, 100%);
  display: grid;
  gap: 18px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-brand,
.brand {
  display: flex;
  align-items: center;
  min-width: 0;
}

.login-brand {
  gap: 13px;
  margin-bottom: 4px;
}

.login-panel h1 {
  margin: 0;
  font-size: 31px;
  line-height: 1.05;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-weight: 800;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(190px, 240px) auto minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(15, 17, 23, 0.96);
  backdrop-filter: blur(18px);
}

.brand {
  gap: 11px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(70, 184, 255, 0.5);
  border-radius: var(--radius);
  color: var(--accent-2);
  background: var(--accent-bg);
  font-weight: 950;
}

.brand strong,
.brand span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand span {
  margin-top: 1px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.search-wrap {
  position: relative;
  min-width: 0;
}

.search-wrap input {
  padding-left: 38px;
}

.search-glyph {
  position: absolute;
  top: 50%;
  left: 13px;
  width: 15px;
  height: 15px;
  border: 2px solid var(--muted-2);
  border-radius: 999px;
  transform: translateY(-50%);
  pointer-events: none;
}

.search-glyph::after {
  content: "";
  position: absolute;
  right: -6px;
  bottom: -4px;
  width: 7px;
  height: 2px;
  border-radius: 999px;
  background: var(--muted-2);
  transform: rotate(45deg);
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.tabs,
.segmented {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
}

.tab-button,
.segment {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  padding: 0 13px;
  font-weight: 850;
  white-space: nowrap;
}

.tab-button.active,
.segment.active {
  color: var(--text);
  background: var(--panel-soft);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.035);
}

.primary-button,
.ghost-button,
.file-button,
.icon-button,
.mini-button {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  font-weight: 850;
  white-space: nowrap;
}

.primary-button {
  color: #05111c;
  background: var(--accent);
  box-shadow: 0 8px 24px rgba(70, 184, 255, 0.16);
}

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

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

.ghost-button:hover,
.file-button:hover {
  border-color: rgba(70, 184, 255, 0.62);
  background: var(--panel-hover);
}

.ghost-button.danger {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: #51303a;
}

.wide {
  width: 100%;
}

.file-button {
  position: relative;
  cursor: pointer;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.slim {
  min-height: 34px;
  padding-inline: 10px;
  font-size: 13px;
}

.icon-button {
  width: 38px;
  padding: 0;
  border-color: var(--line);
  color: var(--muted);
  background: transparent;
}

.icon-button::before {
  content: "";
  width: 15px;
  height: 15px;
  background:
    linear-gradient(45deg, transparent 44%, currentColor 45%, currentColor 55%, transparent 56%),
    linear-gradient(-45deg, transparent 44%, currentColor 45%, currentColor 55%, transparent 56%);
}

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

.main-shell {
  padding: 20px 18px 28px;
}

.tab-panel {
  width: min(1380px, 100%);
  margin: 0 auto;
}

.notes-layout {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 88px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--bg-soft);
}

.panel-title {
  padding: 4px 6px 10px;
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.group-list {
  display: grid;
  gap: 4px;
}

.group-item {
  width: 100%;
  min-height: 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  padding: 7px 8px;
  text-align: left;
}

.group-item:hover,
.group-item.active {
  background: var(--panel-soft);
  border-color: var(--line);
}

.group-item.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.group-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 850;
}

.group-count {
  min-width: 24px;
  min-height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  color: var(--muted);
  background: var(--field);
  font-size: 12px;
  font-weight: 850;
}

.group-tools {
  display: inline-flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.14s ease;
}

.group-item:hover .group-tools,
.group-item:focus-within .group-tools {
  opacity: 1;
}

.mini-button {
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border-color: var(--line);
  color: var(--muted);
  background: var(--field);
}

.mini-button:hover {
  color: var(--text);
  border-color: rgba(70, 184, 255, 0.64);
  background: var(--panel-hover);
}

.mini-button.danger:hover {
  color: var(--danger);
  border-color: #713846;
  background: var(--danger-bg);
}

.notes-area,
.media-layout {
  min-height: calc(100vh - 116px);
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-head h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.counter {
  min-width: 38px;
  min-height: 32px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--field);
  font-weight: 900;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 12px;
}

.note-card {
  min-height: 205px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
  padding: 15px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--panel);
  transition:
    transform 0.14s ease,
    border-color 0.14s ease,
    background 0.14s ease;
}

.note-card:hover,
.note-card:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(70, 184, 255, 0.52);
  background: var(--panel-soft);
  outline: none;
}

.note-card h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.32;
  overflow-wrap: anywhere;
}

.note-body {
  margin: 0;
  color: #d4deed;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
}

.note-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.note-tags {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--field);
  font-size: 12px;
  font-weight: 800;
}

.pill span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-pill {
  color: var(--ok);
  border-color: rgba(101, 214, 164, 0.28);
  background: rgba(101, 214, 164, 0.08);
}

.card-actions {
  display: inline-flex;
  gap: 6px;
}

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

.local-search {
  width: min(360px, 100%);
}

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

.media-card,
.attached-item,
.picker-item {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.media-card {
  display: grid;
  grid-template-rows: 158px auto auto;
}

.media-card:hover {
  border-color: rgba(70, 184, 255, 0.52);
  background: var(--panel-soft);
}

.media-preview {
  width: 100%;
  height: 158px;
  display: grid;
  place-items: center;
  background: #0b1018;
  overflow: hidden;
}

.media-preview img,
.media-preview video,
.viewer-content img,
.viewer-content video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.media-info {
  display: grid;
  gap: 5px;
  padding: 11px;
}

.media-info strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-info span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.media-card-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 0 11px 11px;
}

.media-card-actions .mini-button {
  width: 100%;
}

.empty-state {
  min-height: 190px;
  display: grid;
  place-items: center;
  gap: 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  padding: 24px;
  background: rgba(18, 22, 32, 0.42);
}

.empty-state strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
  font-size: 16px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 5, 10, 0.74);
}

.modal-dialog {
  width: min(720px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.note-dialog {
  width: min(1080px, 100%);
}

.viewer-dialog {
  width: min(980px, 100%);
}

.name-dialog {
  width: min(440px, 100%);
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line-soft);
}

.modal-footer {
  border-top: 1px solid var(--line-soft);
  border-bottom: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.note-editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  padding: 16px;
}

.note-fields {
  display: grid;
  gap: 14px;
}

.textarea-label {
  align-content: start;
}

.note-media-panel {
  display: grid;
  align-content: start;
  gap: 12px;
  min-width: 0;
  padding-left: 16px;
  border-left: 1px solid var(--line-soft);
}

.media-actions-row,
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.attached-list,
.picker-list {
  display: grid;
  gap: 8px;
}

.attached-item,
.picker-item {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
}

.attached-thumb,
.picker-thumb {
  width: 58px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #0b1018;
  overflow: hidden;
}

.attached-thumb img,
.attached-thumb video,
.picker-thumb img,
.picker-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attached-info,
.picker-info {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.attached-info strong,
.picker-info strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.attached-actions,
.picker-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.media-picker {
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.viewer-content {
  height: min(68vh, 680px);
  display: grid;
  place-items: center;
  padding: 16px;
  background: #080d14;
}

.name-dialog form {
  display: grid;
  gap: 16px;
}

.name-dialog label {
  padding: 0 16px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid rgba(70, 184, 255, 0.34);
  border-radius: var(--radius);
  background: #102033;
  color: var(--text);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-weight: 850;
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1120px) {
  .topbar {
    grid-template-columns: minmax(180px, 1fr) auto;
  }

  .search-wrap {
    grid-column: 1 / -1;
    order: 3;
  }

  .top-actions {
    grid-column: 1 / -1;
    order: 4;
    justify-content: stretch;
  }

  .top-actions > * {
    flex: 1;
  }
}

@media (max-width: 860px) {
  .notes-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .group-list {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .group-item {
    min-width: 170px;
  }

  .note-editor-grid {
    grid-template-columns: 1fr;
  }

  .note-media-panel {
    padding-left: 0;
    border-left: 0;
    border-top: 1px solid var(--line-soft);
    padding-top: 16px;
  }
}

@media (max-width: 620px) {
  body {
    font-size: 14px;
  }

  .topbar,
  .main-shell {
    padding: 12px;
  }

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

  .brand,
  .tabs,
  .top-actions {
    width: 100%;
  }

  .tabs > *,
  .top-actions > * {
    flex: 1;
  }

  .section-head,
  .media-toolbar,
  .modal-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .local-search {
    width: 100%;
  }

  .notes-grid,
  .media-grid {
    grid-template-columns: 1fr;
  }

  .note-card {
    min-height: 190px;
  }

  .note-meta {
    grid-template-columns: 1fr;
  }

  .card-actions {
    justify-content: stretch;
  }

  .card-actions .mini-button {
    flex: 1;
    width: auto;
  }

  .media-card {
    grid-template-rows: 190px auto auto;
  }

  .media-preview {
    height: 190px;
  }

  .modal {
    padding: 10px;
  }

  .modal-dialog {
    max-height: calc(100vh - 20px);
  }

  .modal-header,
  .modal-footer,
  .note-editor-grid {
    padding: 12px;
  }

  textarea {
    min-height: 300px;
  }

  .modal-actions,
  .media-actions-row {
    width: 100%;
  }

  .modal-actions > *,
  .media-actions-row > * {
    flex: 1;
  }
}
