:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --panel: #ffffff;
  --panel-strong: #eef3f1;
  --text: #202722;
  --muted: #66736b;
  --line: #dbe3df;
  --accent: #196a5b;
  --accent-strong: #0f5145;
  --danger: #b83333;
  --shadow: 0 18px 45px rgba(30, 45, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

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

.unlock-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #172520;
}

.unlock-panel {
  width: min(420px, 100%);
  display: grid;
  justify-items: center;
  gap: 14px;
  text-align: center;
  color: #f5faf7;
}

.unlock-mark {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #d5efe5;
  color: #15362e;
  font-size: 26px;
  font-weight: 800;
}

.unlock-panel h1 {
  margin: 4px 0 0;
  font-size: 28px;
}

.unlock-panel p {
  margin: 0 0 10px;
  color: #b9c8c1;
}

.unlock-form {
  width: min(320px, 100%);
  display: grid;
  gap: 10px;
  padding: 0;
}

.unlock-form input {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

.unlock-form input::placeholder {
  color: #aebdb6;
}

.sidebar {
  background: #172520;
  color: #f5faf7;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #d5efe5;
  color: #15362e;
  font-weight: 800;
}

.brand h1 {
  font-size: 20px;
  margin: 0 0 3px;
}

.brand p {
  margin: 0;
  color: #b9c8c1;
  font-size: 13px;
}

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

.nav-item,
.secondary-button,
.primary-button,
.danger-button,
.icon-button {
  border: 0;
  border-radius: 8px;
}

.nav-item {
  min-height: 44px;
  padding: 0 12px;
  background: transparent;
  color: #dce7e2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.11);
  color: #ffffff;
}

.nav-item strong {
  min-width: 26px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 12px;
}

.storage-panel {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.category-panel {
  display: grid;
  gap: 10px;
}

.panel-title {
  color: #b9c8c1;
  font-size: 13px;
}

.category-form {
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  gap: 8px;
}

.category-form input {
  min-height: 38px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.category-form input::placeholder {
  color: #91a29a;
}

.category-form button {
  border: 0;
  border-radius: 8px;
  background: #d5efe5;
  color: #15362e;
}

#account-form {
  grid-template-columns: 1fr;
}

#account-form button {
  min-height: 36px;
}

.account-panel {
  display: grid;
  gap: 10px;
}

.category-list {
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}

.category-item {
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #dce7e2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
}

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

.category-item:hover,
.category-item.active {
  background: rgba(255, 255, 255, 0.11);
  color: #ffffff;
}

.category-item strong {
  min-width: 24px;
  height: 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.14);
  font-size: 12px;
}

.workspace {
  padding: 28px;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 150px 150px 96px;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.search-wrap {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

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

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(25, 106, 91, 0.12);
}

.primary-button {
  min-height: 44px;
  padding: 0 18px;
  background: var(--accent);
  color: white;
}

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

.secondary-button {
  min-height: 42px;
  padding: 0 14px;
  background: var(--panel-strong);
  color: var(--text);
  display: grid;
  place-items: center;
  text-align: center;
}

.sidebar .secondary-button {
  background: rgba(255, 255, 255, 0.1);
  color: #edf7f2;
}

.danger-button {
  min-height: 42px;
  padding: 0 14px;
  background: #fae6e6;
  color: var(--danger);
}

.icon-button {
  width: 36px;
  height: 36px;
  background: var(--panel-strong);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.import-button input {
  display: none;
}

.view-toggle {
  min-height: 44px;
  padding: 4px;
  border-radius: 8px;
  background: var(--panel-strong);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.view-button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.view-button.active {
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 1px 4px rgba(25, 35, 30, 0.1);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.summary-grid article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.summary-grid strong {
  display: block;
  font-size: 22px;
  overflow-wrap: anywhere;
}

.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  align-content: start;
  align-items: stretch;
  gap: 14px;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.item-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  height: 340px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 1px 0 rgba(25, 35, 30, 0.03);
  overflow: hidden;
}

.item-card:hover {
  border-color: #adc3bb;
  box-shadow: var(--shadow);
}

.item-card[draggable="true"],
.items-table tr[draggable="true"] {
  cursor: grab;
}

.item-card.dragging,
.items-table tr.dragging {
  opacity: 0.55;
}

.item-card.drag-over,
.items-table tr.drag-over {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card-top {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
  flex: 0 0 auto;
}

.type-pill {
  display: inline-flex;
  align-items: center;
  height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  background: #e5efeb;
  color: #175447;
  font-size: 12px;
}

.item-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-content {
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-image {
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.image-preview-button {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 8px;
  overflow: hidden;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 0 0 auto;
}

.software-logo {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.bookmark-icon {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  object-fit: contain;
  border-radius: 6px;
}

.category-label {
  width: fit-content;
  max-width: 100%;
  color: #4d604f;
  background: #edf4e9;
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.card-link {
  display: -webkit-box;
  color: var(--accent);
  text-decoration: none;
  overflow-wrap: anywhere;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.file-link {
  display: -webkit-box;
  color: var(--accent);
  background: #edf5f2;
  border-radius: 8px;
  padding: 10px 12px;
  text-decoration: none;
  overflow-wrap: anywhere;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
}

.tag {
  border-radius: 999px;
  background: #f0f2f1;
  color: #516158;
  padding: 4px 8px;
  font-size: 12px;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.card-actions button,
.card-actions a {
  flex: 1;
  min-height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  border: 0;
  text-decoration: none;
}

.empty-state {
  min-height: 280px;
  display: grid;
  place-items: center;
  border: 1px dashed #b8c6c0;
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.58);
}

.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.items-table {
  width: 100%;
  min-width: 880px;
  border-collapse: collapse;
}

.items-table th,
.items-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.items-table th {
  color: var(--muted);
  background: #f8faf9;
  font-size: 13px;
  font-weight: 600;
}

.items-table tr:last-child td {
  border-bottom: 0;
}

.table-title-cell {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.table-title-cell strong,
.table-link-cell a {
  overflow-wrap: anywhere;
}

.table-subtext {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin-top: 3px;
}

.table-icon,
.table-icon-fallback {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.table-icon {
  object-fit: cover;
}

.table-icon-fallback {
  display: grid;
  place-items: center;
  color: var(--accent);
  font-weight: 700;
}

.table-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 150px;
}

.table-link-cell a {
  color: var(--accent);
  text-decoration: none;
}

.table-edit-button {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  display: inline-grid;
  place-items: center;
  text-decoration: none;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

dialog {
  width: min(620px, calc(100vw - 30px));
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0;
}

dialog::backdrop {
  background: rgba(18, 28, 24, 0.45);
}

form {
  padding: 22px;
  display: grid;
  gap: 14px;
}

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

.dialog-head h2 {
  margin: 0;
  font-size: 22px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

label input,
label select,
label textarea {
  color: var(--text);
}

textarea {
  resize: vertical;
}

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

.form-actions .danger-button {
  margin-right: auto;
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    padding: 20px;
  }

  .nav-list {
    grid-template-columns: repeat(6, minmax(86px, 1fr));
    overflow-x: auto;
  }

  .storage-panel {
    grid-template-columns: 1fr 1fr;
  }

  .category-panel {
    display: none;
  }

  .workspace {
    padding: 20px;
  }

  .toolbar,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .code-repo-shell {
    grid-template-columns: 1fr;
  }

  .code-tree-panel {
    max-height: 240px;
  }
}

.viewer-dialog {
  width: min(860px, calc(100vw - 30px));
}

.viewer-dialog.code-dialog {
  width: min(1280px, calc(100vw - 24px));
  overflow: visible;
}

.viewer-dialog.code-dialog .viewer-body {
  padding: 0 18px 18px;
}

.viewer-dialog .dialog-head {
  padding: 22px;
}

.viewer-dialog.code-dialog .dialog-head {
  padding: 18px;
}

.viewer-body {
  padding: 0 22px 22px;
}

.note-viewer {
  min-height: 220px;
  max-height: 68vh;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.7;
  background: #f8faf9;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.code-viewer {
  min-height: 260px;
  max-height: 68vh;
  overflow: auto;
  margin: 12px 0 0;
  white-space: pre;
  line-height: 1.55;
  background: #101816;
  color: #e8f3ee;
  border-radius: 8px;
  padding: 16px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.code-repo-shell {
  height: 80vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 14px;
}

.code-tree-panel,
.code-editor-panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
}

.code-tree-panel {
  overflow: auto;
  padding: 12px;
}

.code-toolbar {
  margin-bottom: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.code-tree {
  display: grid;
  gap: 2px;
}

.code-folder {
  display: block;
  margin-left: calc(var(--depth) * 12px);
}

.code-folder summary {
  min-height: 30px;
  display: flex;
  align-items: center;
  color: var(--muted);
  cursor: pointer;
}

.code-file {
  display: block;
  width: calc(100% - (var(--depth) * 12px));
  min-height: 32px;
  margin-left: calc(var(--depth) * 12px);
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-file:hover,
.code-file.active {
  background: #e5efeb;
}

.code-empty,
.code-loading {
  color: var(--muted);
  padding: 16px;
}

.code-editor-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
}

.code-editor-head {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.code-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

#active-code-path {
  font-family: Consolas, "Courier New", monospace;
  overflow-wrap: anywhere;
}

.code-editor-wrap {
  min-height: 420px;
  height: 100%;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid #253b34;
  border-radius: 8px;
  background: #101816;
}

.code-line-numbers {
  padding: 11px 8px;
  overflow: hidden;
  background: #0b1210;
  color: #81958d;
  border-right: 1px solid #253b34;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.55;
  text-align: right;
  user-select: none;
}

.code-line-numbers span {
  display: block;
}

.code-editor {
  min-height: 420px;
  height: 100%;
  resize: none;
  border: 0;
  border-radius: 0;
  background: #101816;
  color: #e8f3ee;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
}

.code-context-menu {
  position: absolute;
  z-index: 2000;
  min-width: 148px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.code-context-menu button {
  width: 100%;
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.code-context-menu button:hover {
  background: var(--panel-strong);
}

.image-viewer {
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border-radius: 8px;
  background: #f8faf9;
}

.toast {
  position: fixed;
  left: 50%;
  top: 24px;
  transform: translateX(-50%);
  z-index: 2147483647;
  min-width: 160px;
  max-width: min(360px, calc(100vw - 44px));
  min-height: 42px;
  display: grid;
  place-items: center;
  padding: 10px 14px;
  border-radius: 8px;
  background: #172520;
  color: #ffffff;
  box-shadow: var(--shadow);
}

@media (max-width: 520px) {
  .items-grid {
    grid-template-columns: 1fr;
  }

  .form-actions {
    flex-wrap: wrap;
  }

  .form-actions button {
    flex: 1 1 120px;
  }
}
