:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #1c2430;
  --muted: #667085;
  --accent: #126c63;
  --accent-strong: #0d554e;
  --danger: #a33a34;
  --focus: #8bb7ff;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(139, 183, 255, 0.28);
}

label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 14px;
  font-weight: 600;
}

.shell {
  min-height: 100vh;
}

.site-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.site-footer a {
  color: inherit;
}

.site-footer a:hover {
  color: var(--accent-strong);
}

.auth {
  width: min(440px, calc(100vw - 32px));
  margin: 0 auto;
  min-height: 100vh;
  display: grid;
  align-content: center;
  gap: 22px;
}

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

.mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.brand h1,
.topbar h1 {
  font-size: 24px;
  line-height: 1.2;
}

.brand p,
.topbar p,
.hint {
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}

.panel,
.editor-form {
  display: grid;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}

.primary {
  min-height: 42px;
  border-radius: 6px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

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

.ghost {
  min-height: 38px;
  border-radius: 6px;
  padding: 0 14px;
  background: #eef2f6;
  color: #223047;
  font-weight: 700;
}

.danger {
  min-height: 36px;
  border-radius: 6px;
  padding: 0 12px;
  background: #f9e9e7;
  color: var(--danger);
  font-weight: 700;
}

.error {
  min-height: 20px;
  color: var(--danger);
  font-size: 14px;
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

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

.user-chip {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 8px 11px;
  border-radius: 999px;
  background: #eef4f3;
  color: var(--accent-strong);
  font-size: 14px;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #fff;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

.sidebar-tools {
  display: grid;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.sidebar-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.add-entry {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.button-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.icon-button {
  width: 42px;
  min-width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 6px;
  background: #e8eef3;
  color: #223047;
}

.icon-button:hover {
  background: #dce5ec;
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.danger.icon-button {
  background: #f9e9e7;
  color: var(--danger);
}

.list {
  overflow: auto;
  padding: 8px;
}

.entry-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px 36px;
  gap: 4px;
  align-items: center;
  border-radius: 6px;
}

.entry-row[draggable="true"],
.catalog-row[draggable="true"] {
  cursor: grab;
}

.entry-row.dragging,
.catalog-row.dragging {
  z-index: 2;
  opacity: 1;
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.18);
}

.entry-row,
.catalog-row,
.catalog-block {
  transition: transform 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

.entry-row.drop-before,
.catalog-row.drop-before {
  transform: translateY(5px);
}

.entry-row.drop-before::before,
.catalog-row.drop-before::before {
  content: "";
  position: absolute;
  z-index: 4;
  top: -4px;
  left: 8px;
  right: 8px;
  height: 3px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 1px 5px rgba(18, 108, 99, 0.45);
}

.drag-preview {
  position: fixed !important;
  top: -1000px !important;
  left: -1000px !important;
  z-index: 9999 !important;
  opacity: 1 !important;
  overflow: hidden;
  border: 1px solid #b9c8c5;
  border-radius: 8px;
  background: #fff !important;
  box-shadow: 0 14px 34px rgba(16, 24, 40, 0.28) !important;
  pointer-events: none;
}

.entry-main {
  width: 100%;
  display: grid;
  gap: 4px;
  text-align: left;
  background: transparent;
  border-radius: 6px;
  padding: 11px 12px;
  color: var(--text);
}

.entry-row:hover,
.entry-row.active {
  background: #eef4f3;
}

.entry-main strong {
  font-size: 15px;
}

.entry-main span {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-action {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.entry-action:hover {
  background: #dce8e6;
  color: var(--text);
}

.entry-action.danger-action:hover {
  background: #f9e9e7;
  color: var(--danger);
}

.catalog-block {
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: #fff;
}

.catalog-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px 36px 36px;
  gap: 4px;
  align-items: center;
  background: #eef4f3;
}

.catalog-main {
  min-width: 0;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 7px;
  align-items: center;
  padding: 11px 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.catalog-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.catalog-chevron {
  color: var(--muted);
  font-size: 11px;
}

.catalog-children {
  padding: 5px 5px 5px 14px;
  border-top: 1px solid var(--line);
  border-left: 3px solid #dce8e6;
}

.entry-drop-zone,
.catalog-drop-zone {
  min-height: 8px;
  display: grid;
  place-items: center;
  margin: 2px 0;
  border: 1px dashed transparent;
  border-radius: 6px;
  opacity: 0;
  transition: min-height 140ms ease, opacity 140ms ease, background-color 140ms ease;
}

.drag-active .entry-drop-zone,
.drag-active .catalog-drop-zone {
  min-height: 22px;
  opacity: 1;
}

.entry-drop-zone.drop-inside,
.catalog-drop-zone.drop-inside,
.catalog-row.drop-inside {
  border-color: var(--accent);
  background: #eef4f3;
  box-shadow: inset 0 0 0 1px rgba(18, 108, 99, 0.18);
}

.root-entries {
  display: grid;
  gap: 2px;
}

.search-catalog-row {
  display: block;
  padding: 10px 12px;
  cursor: default;
}

.search-catalog-block .catalog-children {
  padding-left: 8px;
}

.empty-state {
  display: grid;
  gap: 4px;
  padding: 16px 12px;
  color: var(--muted);
}

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

.editor-form {
  max-width: 900px;
  margin: 0 auto;
}

.form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.form-head h2 {
  font-size: 20px;
}

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

.split > label {
  min-width: 0;
}

.password-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px 42px;
  gap: 8px;
  align-items: stretch;
  min-width: 0;
}

.password-row input {
  min-width: 0;
}

.custom-fields-editor {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfd;
}

.custom-fields-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.custom-fields-head h3 {
  font-size: 16px;
}

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

.custom-field-row {
  display: grid;
  grid-template-columns: minmax(130px, 0.8fr) minmax(180px, 1.2fr) 42px;
  gap: 8px;
  align-items: center;
}

.custom-field-row input {
  min-width: 0;
}

.modal {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: 10px;
  box-shadow: 0 24px 70px rgba(16, 24, 40, 0.25);
}

.modal-wide {
  width: min(720px, calc(100vw - 32px));
}

.modal::backdrop {
  background: rgba(16, 24, 40, 0.48);
}

.modal-card {
  display: grid;
  gap: 16px;
  padding: 22px;
  background: #fff;
}

.modal-close {
  width: 36px;
  min-width: 36px;
  height: 36px;
  font-size: 24px;
  line-height: 1;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.confirm-modal {
  width: min(440px, calc(100vw - 32px));
}

.confirm-card {
  grid-template-columns: 44px 1fr;
  gap: 12px 16px;
  align-items: start;
}

.confirm-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: var(--danger);
  background: #fff0f0;
  border-radius: 50%;
}

.confirm-icon svg {
  width: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.confirm-copy h2 {
  font-size: 19px;
}

.confirm-copy p {
  margin-top: 7px;
  color: var(--muted);
  line-height: 1.55;
}

.confirm-actions {
  grid-column: 1 / -1;
  margin-top: 4px;
}

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  top: 20px;
  transform: translate(-50%, -12px);
  min-width: 220px;
  padding: 13px 18px;
  color: #fff;
  background: #182230;
  border-radius: 9px;
  box-shadow: 0 14px 36px rgba(16, 24, 40, 0.24);
  text-align: center;
  font-weight: 600;
  opacity: 0;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.toast-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.toast-success {
  background: #344054;
}

.loading-overlay {
  position: fixed;
  z-index: 200;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(246, 247, 249, 0.82);
  backdrop-filter: blur(3px);
}

.loading-card {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 280px;
  padding: 20px 22px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 18px 48px rgba(16, 24, 40, 0.18);
}

.loading-card p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.loading-spinner {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 3px solid #d9dee7;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: loading-spin 700ms linear infinite;
}

@keyframes loading-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .loading-spinner { animation-duration: 1400ms; }
}

.settings-panel {
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.settings-section {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.settings-section > div > h3 {
  font-size: 17px;
}

.settings-form {
  display: grid;
  gap: 14px;
}

.settings-form > .primary,
.settings-session > .settings-item {
  justify-self: start;
}

.settings-item {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 7px;
  background: #f2f5f8;
  color: var(--text);
  text-align: left;
  font-weight: 700;
}

.settings-item:hover {
  background: #e6ecef;
}

.settings-danger {
  background: #f9e9e7;
  color: var(--danger);
}

.settings-danger:hover {
  background: #f4d9d6;
}

.member-list {
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}

.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
}

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

.member-row span {
  color: var(--muted);
  font-size: 13px;
}

.member-form {
  display: grid;
  gap: 14px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    width: 100%;
    justify-content: flex-start;
  }

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 320px;
  }

  .editor {
    padding: 16px;
  }

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

  .custom-field-row {
    grid-template-columns: 1fr 1fr 42px;
  }
}

@media (max-width: 480px) {
  .custom-field-row {
    grid-template-columns: 1fr 42px;
  }

  .custom-field-row .custom-field-value {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .custom-field-row .custom-field-delete {
    grid-column: 2;
    grid-row: 1;
  }
}
