*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f11;
  --surface: #1a1a1e;
  --surface-hover: #24242a;
  --border: #2c2c33;
  --text: #e8e8ed;
  --text-muted: #8e8ea0;
  --accent: #6c63ff;
  --accent-hover: #5a52e0;
  --danger: #ff4757;
  --radius: 12px;
  --shadow: 0 2px 16px rgba(0,0,0,0.3);
}

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

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay.hidden { display: none; }
.hidden { display: none !important; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.login-card .login-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.login-card .login-header h1 {
  font-size: 1.5rem;
  margin-bottom: 0;
}

.btn-close {
  background: transparent;
  color: var(--text-muted);
  font-size: 1.5rem;
  padding: 0 4px;
  line-height: 1;
}

.btn-close:hover {
  background: transparent;
  color: var(--text);
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.user-display {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 500;
  padding: 4px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  white-space: nowrap;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

form { display: flex; flex-direction: column; gap: 12px; }

label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

input:focus { border-color: var(--accent); }

.error-message {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2em;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

button:hover { background: var(--accent-hover); }
button:active { transform: scale(0.98); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 16px;
  font-size: 0.85rem;
}

.btn-outline:hover {
  background: var(--surface-hover);
  color: var(--text);
}

header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-content h1 {
  font-size: 1.2rem;
  font-weight: 600;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.admin-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 28px;
  box-shadow: var(--shadow);
}

.admin-bar.hidden { display: none; }

.add-form {
  display: flex;
  flex-direction: row;
  gap: 10px;
  flex-wrap: wrap;
}

.add-form input {
  flex: 1;
  min-width: 140px;
}

.add-form button {
  white-space: nowrap;
}

.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.loading {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 60px 0;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 60px 0;
}

.private-check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.private-check-label:hover { border-color: var(--text-muted); }

.private-check-label input[type="checkbox"] { display: none; }

.private-check-label .toggle-track {
  width: 34px;
  height: 20px;
  background: var(--bg);
  border-radius: 10px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.private-check-label .toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.private-check-label input[type="checkbox"]:checked ~ .toggle-track {
  background: rgba(108,99,255,0.2);
  border-color: var(--accent);
}

.private-check-label input[type="checkbox"]:checked ~ .toggle-track::after {
  transform: translateX(14px);
  background: var(--accent);
}

.private-check-label input[type="checkbox"]:checked ~ .lock-icon,
.private-check-label input[type="checkbox"]:checked ~ .private-text {
  color: var(--accent);
}

.private-check-label .private-text { transition: color 0.2s; }

#notes-section {
  margin-top: 40px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.notes-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.add-note-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.add-note-form input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
}

.add-note-form input[type="text"]:focus { border-color: var(--accent); }

.add-note-form textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  resize: vertical;
  font-family: inherit;
  transition: border-color 0.2s;
}

.add-note-form textarea:focus { border-color: var(--accent); }

.add-note-form .form-bottom-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.add-note-form .form-bottom-row button[type="submit"] {
  margin-left: auto;
  white-space: nowrap;
}

.add-note-form .private-check-label { align-self: flex-end; }

.note-accordion {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.note-accordion:hover {
  border-color: #3a3a44;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}

.note-accordion.private { border-color: #8e44ad; }
.note-accordion.private:hover { border-color: #a855f7; }

.note-accordion-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.note-accordion-header:hover { background: var(--surface-hover); }

.note-accordion-header .arrow {
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.note-accordion-header.open .arrow { transform: rotate(90deg); }

.note-number {
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 700;
  min-width: 28px;
  flex-shrink: 0;
  background: rgba(108,99,255,0.1);
  border-radius: 6px;
  padding: 2px 6px;
  text-align: center;
}

.note-accordion-header .preview {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.92rem;
  color: var(--text);
  font-weight: 500;
}

.note-accordion-header .meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.private-note-badge {
  font-size: 0.7rem;
  color: #a855f7;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(168,85,247,0.1);
  padding: 2px 8px;
  border-radius: 10px;
}

.note-accordion-body {
  display: none;
  padding: 0 20px 20px;
  border-top: 1px solid var(--border);
}

.note-accordion-body.open { display: block; }

.note-accordion-body .note-title-text {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 14px;
  margin-bottom: 8px;
  color: var(--accent);
}

.note-accordion-body .note-text {
  font-size: 0.92rem;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 12px;
  color: #d0d0d8;
}

.note-accordion-body .edit-note-title {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  font-family: inherit;
  margin-top: 12px;
  transition: border-color 0.2s;
}

.note-accordion-body .edit-note-title:focus { border-color: var(--accent); }

.note-accordion-body .edit-note-body {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  resize: vertical;
  font-family: inherit;
  min-height: 60px;
  margin-top: 8px;
  transition: border-color 0.2s;
}

.note-accordion-body .edit-note-body:focus { border-color: var(--accent); }

.note-accordion-body .edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.note-accordion-body .edit-actions button { font-size: 0.85rem; padding: 6px 16px; }
.note-accordion-body .edit-actions .btn-cancel { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.note-accordion-body .edit-actions .btn-cancel:hover { background: var(--surface-hover); color: var(--text); }
.note-accordion-body .edit-actions .btn-delete { background: var(--danger); }
.note-accordion-body .edit-actions .btn-delete:hover { background: #e8404f; }

.search-bar {
  margin-bottom: 20px;
}

.search-bar input {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-bar input:focus {
  border-color: var(--accent);
}

.link-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  position: relative;
}

.link-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}

.link-card.private { border-color: #8e44ad; }
.link-card.private:hover { border-color: #a855f7; }

.link-card.dragging {
  opacity: 0.4;
  border-style: dashed;
}

.link-card.drag-over {
  border-color: var(--accent);
  border-style: dashed;
  transform: translateY(-2px);
  box-shadow: 0 0 0 2px rgba(108,99,255,0.2);
}

.private-badge {
  font-size: 0.75rem;
  color: #a855f7;
  display: flex;
  align-items: center;
  gap: 4px;
}

.card-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  user-select: none;
  padding: 8px 6px;
  margin: -8px 0 -8px -4px;
  opacity: 0.3;
  transition: opacity 0.2s, color 0.2s;
  flex-shrink: 0;
  border-radius: 4px;
}

.link-card:hover .drag-handle { opacity: 0.8; }
.drag-handle:hover { color: var(--accent); background: rgba(108,99,255,0.08); }
.drag-handle:active { cursor: grabbing; }

.favicon {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  flex-shrink: 0;
}

.link-card a {
  color: var(--accent);
  text-decoration: none;
  font-size: 1.05rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.link-card a:hover { color: var(--accent-hover); }

.click-badge {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.link-card .domain {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.link-card .tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag-chip {
  display: inline-block;
  background: rgba(108,99,255,0.12);
  color: var(--accent);
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 10px;
  line-height: 1.4;
}

.link-card .description {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.link-card .card-actions {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.link-card:hover .card-actions { opacity: 1; }

.card-actions button {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.card-actions .edit-btn:hover {
  background: rgba(108,99,255,0.15);
  color: var(--accent);
}

.card-actions .delete-btn:hover {
  background: rgba(255,71,87,0.15);
  color: var(--danger);
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.settings-card h1 { font-size: 1.5rem; margin-bottom: 0; }
.settings-card h3 { font-size: 1rem; color: var(--text-muted); margin: 20px 0 12px; }

.settings-tabs {
  display: flex;
  gap: 0;
  margin: 20px 0 16px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 0;
  padding: 10px 20px;
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab-btn:hover { background: transparent; color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn.hidden { display: none; }

.success-message {
  color: #2ed573;
  font-size: 0.85rem;
  min-height: 1.2em;
}

.add-user-form {
  display: flex;
  flex-direction: row;
  gap: 8px;
  flex-wrap: wrap;
}

.add-user-form input,
.add-user-form select {
  flex: 1;
  min-width: 120px;
}

.add-user-form select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  cursor: pointer;
}

.add-user-form select:focus { border-color: var(--accent); }

.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.user-row:last-child { border-bottom: none; }

.user-info { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.user-name { font-weight: 500; }
.user-last-login { font-size: 0.72rem; color: var(--text-muted); }

.user-role-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.role-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--text);
  font-size: 0.8rem;
  outline: none;
  cursor: pointer;
  text-transform: capitalize;
}

.role-select:focus { border-color: var(--accent); }

.btn-role-save { font-size: 0.75rem; padding: 4px 10px; }

.user-role {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 10px;
  border-radius: 10px;
  text-transform: capitalize;
}

.user-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.user-actions .admin-pw-input {
  width: 130px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.user-you { color: var(--text-muted); font-size: 0.85rem; font-style: italic; }

.btn-small {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #e8404f; }

@media (max-width: 600px) {
  .add-form { flex-direction: column; }
  .add-form input { min-width: 0; }
  .links-grid { grid-template-columns: 1fr; }
  .settings-card { padding: 20px; }
  .user-row { flex-direction: column; align-items: flex-start; }
  .user-actions { flex-wrap: wrap; }
  .user-actions .admin-pw-input { width: 100%; }
}
.note-body-toolbar { position: relative; }

.toolbar-btns { display: flex; gap: 6px; margin-top: 6px; }

.btn-toolbar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}

.btn-toolbar:hover { background: var(--surface-hover); border-color: var(--accent); }

.btn-toolbar .tb-icon { font-size: 18px; line-height: 1; }

.btn-toolbar .tb-label { font-size: 0.82rem; font-weight: 500; }

.btn-toolbar-upload {
  background: rgba(108,99,255,0.08);
  border-color: rgba(108,99,255,0.25);
}

.btn-toolbar-upload:hover {
  background: rgba(108,99,255,0.18);
  border-color: var(--accent);
}

.note-image { max-width: 100%; max-height: 400px; border-radius: 8px; margin: 8px 0; display: block; object-fit: contain; background: var(--surface); }
.note-file { color: var(--accent); text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.note-file:hover { text-decoration: underline; }

#audit-section h3 { margin-bottom: 12px; }

.audit-filters { display: flex; gap: 8px; margin-bottom: 12px; }

.audit-filters input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
}

.audit-filters input:focus { border-color: var(--accent); }
.audit-filters input::placeholder { color: var(--text-muted); }

.audit-table-wrap { max-height: 400px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }

.audit-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }

.audit-table th { position: sticky; top: 0; background: var(--surface); padding: 10px 12px; text-align: left; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border); }

.audit-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); color: var(--text); }

.audit-table tr:last-child td { border-bottom: none; }

.audit-table tr:hover td { background: var(--surface-hover); }

.audit-time { white-space: nowrap; color: var(--text-muted); font-size: 0.78rem; }
.audit-user { font-weight: 500; }
.audit-action { font-family: monospace; font-size: 0.8rem; color: var(--accent); }
.audit-details { color: #c0c0cc; }

.chat-msg-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #c0c0cc;
  cursor: help;
}

.chat-panel {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 360px;
  height: 500px;
  max-height: calc(100vh - 140px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-panel.hidden { display: none; }

.chat-resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 101;
}
.chat-resize-handle::after {
  content: '';
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: grab;
  user-select: none;
}

.chat-header .btn-close { font-size: 1.2rem; }

.btn-clear {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  margin-right: 8px;
  font-family: inherit;
}
.btn-clear:hover { color: var(--text); border-color: var(--text-muted); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg.bot {
  background: var(--bg);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-msg.user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-msg.error {
  background: rgba(239,68,68,0.12);
  color: var(--danger);
  align-self: flex-start;
  font-size: 0.82rem;
  border-bottom-left-radius: 4px;
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.chat-form input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
  font-family: inherit;
}

.chat-form input:focus { border-color: var(--accent); }

.chat-form button {
  padding: 10px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.88rem;
  white-space: nowrap;
}

.chat-form button:hover { opacity: 0.9; }

@media (max-width: 480px) {
  .chat-panel { width: calc(100vw - 32px); right: 16px; bottom: 76px; max-height: calc(100vh - 100px); }
}


