/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #0b1220;
  --surface: #121b31;
  --surface2: #182442;
  --border: #2b3c69;
  --text: #eef2ff;
  --text-muted: #8a9cc5;
  --accent: #7bc8ff;
  --accent-dim: #3a6fa0;
  --danger: #ff6b6b;
  --tag-person: #7bc8ff;
  --tag-meeting: #ffb86c;
  --tag-team: #a78bfa;
  --tag-project: #6ee7b7;
  --tag-custom: #f9a8d4;
  --radius: 10px;
  --radius-sm: 6px;
}

body {
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Login screen ── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.login-box h2 { margin-bottom: 0.5rem; font-size: 1.3rem; }
.login-box p { color: var(--text-muted); font-size: 0.88rem; margin-bottom: 1rem; }
.login-box input[type="password"] {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  margin-bottom: 0.8rem;
}
.login-box input[type="password"]:focus { border-color: var(--accent); }
.login-box .btn { width: 100%; }
.login-error { color: var(--danger); font-size: 0.82rem; margin-top: 0.6rem; }

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 1.2rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar h1 { font-size: 1.15rem; font-weight: 600; }
.back-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}

/* ── Layout ── */
#app-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.app {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 260px;
  min-width: 200px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { font-size: 0.95rem; font-weight: 600; }

.object-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
}
.filter-chip {
  font-size: 0.72rem;
  padding: 0.2rem 0.55rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.filter-chip:hover { border-color: var(--accent); color: var(--text); }
.filter-chip.active { background: var(--accent-dim); border-color: var(--accent); color: var(--text); }

.object-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 0.4rem;
}
.object-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
  font-size: 0.88rem;
}
.object-item:hover { background: var(--surface2); }
.object-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
  font-weight: 600;
}
.object-icon[data-type="person"] { background: color-mix(in srgb, var(--tag-person) 25%, transparent); color: var(--tag-person); }
.object-icon[data-type="meeting"] { background: color-mix(in srgb, var(--tag-meeting) 25%, transparent); color: var(--tag-meeting); }
.object-icon[data-type="team"] { background: color-mix(in srgb, var(--tag-team) 25%, transparent); color: var(--tag-team); }
.object-icon[data-type="project"] { background: color-mix(in srgb, var(--tag-project) 25%, transparent); color: var(--tag-project); }
.object-icon[data-type="custom"] { background: color-mix(in srgb, var(--tag-custom) 25%, transparent); color: var(--tag-custom); }

/* ── Content area ── */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* ── Notes list ── */
.notes-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.notes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
.notes-header h2 { font-size: 1rem; font-weight: 600; }
.notes-search {
  padding: 0.6rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
.notes-search input {
  width: 100%;
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}
.notes-search input:focus { border-color: var(--accent); }

.notes-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding: 0.4rem 0.8rem;
}
.note-card {
  padding: 0.8rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.note-card:hover { border-color: var(--accent); background: var(--surface2); }
.note-card-title { font-weight: 600; font-size: 0.95rem; margin-bottom: 0.3rem; }
.note-card-preview { font-size: 0.82rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-card-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.45rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.note-card-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  text-align: center;
  flex: 1;
}
.empty-state-icon { font-size: 2.5rem; margin-bottom: 0.8rem; opacity: 0.5; }
.empty-state p { font-size: 0.9rem; }

/* ── Editor ── */
.editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.save-status {
  font-size: 0.78rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  transition: opacity 0.3s;
}
.save-status:empty { display: none; }
.save-status[data-state="unsaved"] { color: #ffb86c; }
.save-status[data-state="saving"]  { color: var(--text-muted); }
.save-status[data-state="saved"]   { color: var(--text-muted); }
.save-status[data-state="error"]   { color: var(--danger); background: rgba(255,107,107,0.12); }

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
}
.editor-actions { display: flex; gap: 0.4rem; }
.editor-title {
  width: 100%;
  padding: 0.8rem 1.2rem;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 700;
  outline: none;
  font-family: inherit;
}
.editor-title::placeholder { color: var(--text-muted); }

.editor-body-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
/* ── Editor toolbar ── */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.35rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}
.toolbar-btn {
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
  min-width: 28px;
  text-align: center;
  line-height: 1.4;
}
.toolbar-btn:hover { border-color: var(--border); color: var(--text); background: var(--surface2); }
.toolbar-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--text); }
.toolbar-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 0.15rem;
  flex-shrink: 0;
}

.editor-body {
  flex: 1;
  padding: 1rem 1.2rem;
  font-size: 0.95rem;
  line-height: 1.7;
  outline: none;
  overflow-y: auto;
  word-wrap: break-word;
}

/* ── Markdown elements in editor ── */
.editor-body h1 { font-size: 1.5rem; font-weight: 700; margin: 0.6rem 0 0.3rem; line-height: 1.3; }
.editor-body h2 { font-size: 1.15rem; font-weight: 600; margin: 0.5rem 0 0.25rem; line-height: 1.3; }
.editor-body p { margin: 0.2rem 0; }
.editor-body ul, .editor-body ol { padding-left: 1.6rem; margin: 0.3rem 0; }
.editor-body li { margin: 0.1rem 0; }
/* ── Nested list indentation (Tab key) ── */
.editor-body li > ul,
.editor-body li > ol {
  padding-left: 1.4rem;
  margin: 0;
}
.editor-body li > ul > li::marker { content: '◦ '; }
.editor-body li > ul > li > ul > li::marker { content: '▪ '; }
.editor-body blockquote {
  border-left: 3px solid var(--accent-dim);
  padding: 0.25rem 0.75rem;
  margin: 0.4rem 0;
  color: var(--text-muted);
  font-style: italic;
}
.editor-body code {
  font-family: 'Consolas', 'Monaco', monospace;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1rem 0.35rem;
  font-size: 0.85em;
}
.editor-body:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}
.editor-body .tag {
  display: inline;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: default;
  white-space: nowrap;
}
.editor-body .tag[data-type="person"] { background: color-mix(in srgb, var(--tag-person) 20%, transparent); color: var(--tag-person); }
.editor-body .tag[data-type="meeting"] { background: color-mix(in srgb, var(--tag-meeting) 20%, transparent); color: var(--tag-meeting); }
.editor-body .tag[data-type="team"] { background: color-mix(in srgb, var(--tag-team) 20%, transparent); color: var(--tag-team); }
.editor-body .tag[data-type="project"] { background: color-mix(in srgb, var(--tag-project) 20%, transparent); color: var(--tag-project); }
.editor-body .tag[data-type="custom"] { background: color-mix(in srgb, var(--tag-custom) 20%, transparent); color: var(--tag-custom); }

/* ── Autosuggest ── */
.autosuggest {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  min-width: 220px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 100;
}
.autosuggest-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.8rem;
  cursor: pointer;
  font-size: 0.88rem;
  transition: background 0.1s;
}
.autosuggest-item:hover,
.autosuggest-item.active {
  background: var(--surface2);
}
.autosuggest-type {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: auto;
}

/* ── Note tags bar ── */
.note-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.6rem 1.2rem;
  border-top: 1px solid var(--border);
  min-height: 2.6rem;
}
.mini-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
}
.mini-tag[data-type="person"] { background: color-mix(in srgb, var(--tag-person) 20%, transparent); color: var(--tag-person); }
.mini-tag[data-type="meeting"] { background: color-mix(in srgb, var(--tag-meeting) 20%, transparent); color: var(--tag-meeting); }
.mini-tag[data-type="team"] { background: color-mix(in srgb, var(--tag-team) 20%, transparent); color: var(--tag-team); }
.mini-tag[data-type="project"] { background: color-mix(in srgb, var(--tag-project) 20%, transparent); color: var(--tag-project); }
.mini-tag[data-type="custom"] { background: color-mix(in srgb, var(--tag-custom) 20%, transparent); color: var(--tag-custom); }

/* ── Occurrence (meeting tags with date) ── */
.tag-with-occurrence {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.occurrence-date {
  font-size: 0.72rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--tag-meeting);
  font-family: inherit;
  outline: none;
  cursor: pointer;
}
.occurrence-date:focus { border-color: var(--tag-meeting); }
.occurrence-date::-webkit-calendar-picker-indicator { filter: invert(0.7) sepia(1) hue-rotate(180deg); }

/* ── Occurrence groups in detail view ── */
.occurrence-group { margin-bottom: 0.6rem; }
.occurrence-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--tag-meeting);
  padding: 0.25rem 0.5rem;
  margin-bottom: 0.2rem;
  border-left: 3px solid var(--tag-meeting);
}

/* ── Buttons ── */
.btn {
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
}
.btn:hover { border-color: var(--accent); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn-primary { background: var(--accent-dim); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); color: #000; }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
  width: 90%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-wide { max-width: 560px; }
.modal h3 { margin-bottom: 1rem; font-size: 1.05rem; }
.modal label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
}
.modal select,
.modal input[type="text"],
.modal input[type="email"],
.modal input[type="date"],
.modal textarea {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
}
.modal select:focus,
.modal input:focus,
.modal textarea:focus { border-color: var(--accent); }
.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.2rem;
}

/* ── Detail modal ── */
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.detail-header h3 { margin-bottom: 0; }
.detail-actions { display: flex; gap: 0.35rem; }
.detail-section { margin-bottom: 1rem; }
.detail-section h4 { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 0.05em; }
.detail-section p { font-size: 0.9rem; }
.detail-linked-notes { list-style: none; }
.detail-linked-notes li {
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem;
  transition: background 0.12s;
}
.detail-linked-notes li:hover { background: var(--surface2); }

/* ── Team member list ── */
.member-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

/* ── Attendees picker ── */
.attendees-container {
  margin-top: 0.3rem;
}
.attendee-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
  min-height: 1.8rem;
}
.attendee-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
}
.attendee-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 0.15rem;
  line-height: 1;
}
.attendee-remove:hover { color: var(--danger); }
.attendee-empty {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}
.attendee-add-row select {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.82rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}
.attendee-add-row select:focus { border-color: var(--accent); }

/* ── Mobile ── */
@media (max-width: 700px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; max-height: 45vh; border-right: none; border-bottom: 1px solid var(--border); }
}
