/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --yellow:    #fbbc04;
  --yellow-dk: #f9a800;
  --surface:   #ffffff;
  --surface2:  #f8f9fa;
  --border:    #e0e0e0;
  --text:      #202124;
  --text-2:    #5f6368;
  --danger:    #d93025;
  --radius:    12px;
  --sidebar-w: 240px;
  --shadow:    0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.15);
}

/* ── Dark mode ────────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --surface:   #1e1e1e;
  --surface2:  #121212;
  --border:    #3a3a3a;
  --text:      #e8eaed;
  --text-2:    #9aa0a6;
  --shadow:    0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.5);
}
[data-theme="dark"] .nav-item.active { background: #2d2b1e; color: #fdd663; }
[data-theme="dark"] .tag-item.active { background: #2d2b1e; color: #fdd663; }
[data-theme="dark"] .filter-bar      { background: #2d2b1e; }
[data-theme="dark"] .tag-chip        { background: #2d2b1e; color: #fdd663; }
[data-theme="dark"] .tag-chip:hover  { background: #3d3820; }
[data-theme="dark"] #search-input    { background: #2a2a2a; }
[data-theme="dark"] #search-input:focus { background: #1e1e1e; }

/* ── Note colors ──────────────────────────────────────────────────────────── */
.note-color-red    { background: #fce8e6 !important; border-color: #f5c6c2 !important; }
.note-color-orange { background: #fef3e2 !important; border-color: #fddcaa !important; }
.note-color-yellow { background: #fef9e3 !important; border-color: #fde68a !important; }
.note-color-green  { background: #e6f4ea !important; border-color: #b7dfbf !important; }
.note-color-teal   { background: #e8f5f4 !important; border-color: #b2dfdb !important; }
.note-color-blue   { background: #e8f0fe !important; border-color: #b8cffe !important; }
.note-color-purple { background: #f3e8fd !important; border-color: #d7b8fb !important; }

[data-theme="dark"] .note-color-red    { background: #4a2020 !important; border-color: #6b3030 !important; }
[data-theme="dark"] .note-color-orange { background: #4a3010 !important; border-color: #6b4820 !important; }
[data-theme="dark"] .note-color-yellow { background: #3d3000 !important; border-color: #5a4800 !important; }
[data-theme="dark"] .note-color-green  { background: #1a3a22 !important; border-color: #2d5a38 !important; }
[data-theme="dark"] .note-color-teal   { background: #1a3535 !important; border-color: #2d5050 !important; }
[data-theme="dark"] .note-color-blue   { background: #1a2a4a !important; border-color: #2d4070 !important; }
[data-theme="dark"] .note-color-purple { background: #2d1a45 !important; border-color: #4a2d6b !important; }

/* ── Color picker ─────────────────────────────────────────────────────────── */
.color-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}

.color-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
  flex-shrink: 0;
}
.color-dot:hover  { transform: scale(1.2); }
.color-dot.active { border-color: var(--text); }

.color-default { background: var(--surface); border-color: var(--border) !important; }
.color-default.active { border-color: var(--text) !important; }
.color-red     { background: #fce8e6; }
.color-orange  { background: #fef3e2; }
.color-yellow  { background: #fef9e3; }
.color-green   { background: #e6f4ea; }
.color-teal    { background: #e8f5f4; }
.color-blue    { background: #e8f0fe; }
.color-purple  { background: #f3e8fd; }

/* ── Modal toolbar ────────────────────────────────────────────────────────── */
.modal-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 0;
}

.autosave-status {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-2);
  min-width: 48px;
  text-align: right;
}

/* ── Pin button ───────────────────────────────────────────────────────────── */
.pin-btn { color: var(--text-2); }
.pin-btn.pinned { color: var(--yellow-dk); }
.pin-btn.pinned svg { fill: var(--yellow-dk); }

/* ── Pin indicator on card ────────────────────────────────────────────────── */
.note-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}
.note-card-header .note-card-title { flex: 1; }

.pin-indicator {
  color: var(--yellow-dk);
  flex-shrink: 0;
  margin-top: 2px;
}

html, body { height: 100%; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; font-size: 15px; color: var(--text); background: var(--surface2); }
a { color: var(--yellow-dk); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font: inherit; border: none; background: none; }
input, textarea { font: inherit; }

.hidden { display: none !important; }

/* ── Auth pages ───────────────────────────────────────────────────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--surface2);
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.auth-card h1 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 24px;
  color: var(--text);
}

.form-error {
  background: #fce8e6;
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 14px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-2);
}

.hint {
  font-weight: 400;
  color: #aaa;
}

.field input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s;
  background: var(--surface);
  color: var(--text);
}

.field input:focus {
  border-color: var(--yellow);
}

.auth-link {
  margin-top: 20px;
  text-align: center;
  font-size: 14px;
  color: var(--text-2);
}

/* ── Shared buttons ───────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--yellow);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 600;
  transition: background .15s;
}
.btn-primary:hover { background: var(--yellow-dk); }

.btn-secondary {
  background: transparent;
  color: var(--text-2);
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 500;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--surface2); }

.btn-danger {
  color: var(--danger);
  background: transparent;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 500;
  transition: background .15s;
}
.btn-danger:hover { background: #fce8e6; }

.btn-full { width: 100%; }

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: background .15s;
}
.btn-icon:hover { background: var(--surface2); }

/* ── App layout ───────────────────────────────────────────────────────────── */
.app-page {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  transition: transform .2s ease;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 12px;
  font-size: 16px;
  font-weight: 600;
}

.sidebar-nav { padding: 4px 8px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 0 24px 24px 0;
  margin-right: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s;
}
.nav-item:hover { background: var(--surface2); }
.nav-item.active { background: #fef9e3; color: #7a6000; }

.sidebar-section-title {
  padding: 16px 20px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-2);
}

.tag-list {
  list-style: none;
  padding: 0 8px;
  flex: 1;
}

.tag-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 0 24px 24px 0;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  transition: background .15s;
  user-select: none;
}
.tag-item:hover { background: var(--surface2); }
.tag-item.active { background: #fef9e3; color: #7a6000; }

.tag-item-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--yellow);
  flex-shrink: 0;
}

.tag-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn-tag-delete {
  opacity: 0;
  color: var(--text-2);
  border-radius: 50%;
  width: 20px; height: 20px;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, background .15s;
}
.tag-item:hover .btn-tag-delete { opacity: 1; }
.btn-tag-delete:hover { background: var(--border); }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.username {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  font-size: 13px;
  color: var(--text-2);
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  transition: background .15s;
}
.btn-logout:hover { background: var(--surface2); }

/* ── Main area ────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-width: 0;
}

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
}

.sidebar-toggle { display: none; }

.search-wrap {
  flex: 1;
  max-width: 600px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-2);
  pointer-events: none;
}

#search-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 24px;
  padding: 9px 16px 9px 40px;
  outline: none;
  background: var(--surface2);
  color: var(--text);
  font-size: 14px;
  transition: border-color .15s, background .15s;
}
#search-input:focus { border-color: var(--yellow); background: var(--surface); }

/* ── Composer ─────────────────────────────────────────────────────────────── */
.composer {
  max-width: 600px;
  margin: 24px auto 0;
  width: calc(100% - 32px);
}

.composer-collapsed {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  cursor: text;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-2);
  font-size: 15px;
  transition: box-shadow .15s;
}
.composer-collapsed:hover { box-shadow: var(--shadow-lg); }

.composer-type-btns { display: flex; gap: 4px; }

.composer-expanded {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

#composer-title, #modal-title {
  width: 100%;
  border: none;
  outline: none;
  padding: 16px 16px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
}

#composer-content, #modal-content {
  width: 100%;
  border: none;
  outline: none;
  padding: 10px 16px;
  resize: none;
  font-size: 14px;
  color: var(--text);
  background: transparent;
  line-height: 1.6;
  min-height: 80px;
}

.composer-footer, .modal-footer {
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  gap: 8px;
  flex-wrap: wrap;
}

.tag-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 140px;
}
.tag-input-wrap svg { color: var(--text-2); flex-shrink: 0; }
.tag-input-wrap input {
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--text-2);
  background: transparent;
  width: 100%;
}
.tag-input-wrap input::placeholder { color: #bbb; }

.composer-actions, .modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Checklist ────────────────────────────────────────────────────────────── */
.checklist {
  list-style: none;
  padding: 8px 16px;
}

.checklist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}

.checklist-item input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--yellow-dk);
  cursor: pointer;
  flex-shrink: 0;
}

.checklist-item input[type="text"] {
  flex: 1;
  border: none;
  border-bottom: 1px solid transparent;
  outline: none;
  font-size: 14px;
  color: var(--text);
  background: transparent;
  padding: 2px 0;
  transition: border-color .15s;
}
.checklist-item input[type="text"]:focus { border-bottom-color: var(--border); }
.checklist-item input[type="text"].checked-text { text-decoration: line-through; color: var(--text-2); }

.checklist-item .btn-remove-item {
  opacity: 0;
  color: var(--text-2);
  font-size: 16px;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s;
}
.checklist-item:hover .btn-remove-item { opacity: 1; }

.btn-add-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-2);
  padding: 6px 16px;
  transition: color .15s;
}
.btn-add-item:hover { color: var(--text); }

/* ── Filter bar ───────────────────────────────────────────────────────────── */
.filter-bar {
  max-width: 600px;
  margin: 12px auto 0;
  width: calc(100% - 32px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-2);
  background: #fef9e3;
  border-radius: 8px;
  padding: 8px 14px;
}
.btn-clear-filter {
  font-size: 13px;
  color: var(--text-2);
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .15s;
}
.btn-clear-filter:hover { background: var(--border); }

/* ── Notes grid ───────────────────────────────────────────────────────────── */
.notes-grid {
  column-count: 3;
  column-gap: 16px;
  padding: 20px 16px 32px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

@media (max-width: 860px) { .notes-grid { column-count: 2; } }
@media (max-width: 560px) { .notes-grid { column-count: 1; } }

/* ── Note card ────────────────────────────────────────────────────────────── */
.note-card {
  break-inside: avoid;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.note-card:hover { box-shadow: var(--shadow-lg); border-color: #ccc; }

.note-card-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  word-break: break-word;
}

.note-card-content {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
  max-height: 200px;
  overflow: hidden;
}

.note-card-items {
  list-style: none;
  font-size: 13px;
  color: var(--text-2);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.note-card-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.note-card-item-check {
  width: 14px; height: 14px;
  border: 1.5px solid var(--border);
  border-radius: 3px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.note-card-item-check.checked {
  background: var(--yellow);
  border-color: var(--yellow);
}
.note-card-item-check.checked::after {
  content: '';
  width: 7px; height: 4px;
  border-left: 2px solid var(--text);
  border-bottom: 2px solid var(--text);
  transform: rotate(-45deg) translate(1px, -1px);
}
.note-card-item-text.checked { text-decoration: line-through; color: #aaa; }

.note-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.tag-chip {
  background: #fef9e3;
  color: #7a6000;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.tag-chip:hover { background: #fde68a; }

.note-card-date {
  font-size: 11px;
  color: #bbb;
  margin-top: 2px;
}

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 64px 16px;
  color: #ccc;
}
.empty-state p { margin-top: 16px; font-size: 15px; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#modal-content {
  min-height: 120px;
  max-height: 300px;
}

.modal-footer {
  position: sticky;
  bottom: 0;
  background: var(--surface);
}

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

/* ── Sort select ───���──────────────────────────────────────────────────────── */
#sort-wrap { flex-shrink: 0; }

.sort-select {
  font-size: 13px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  outline: none;
}
.sort-select:hover  { border-color: #bbb; }
.sort-select:focus  { border-color: var(--yellow); }

/* ── Share bar ─────���──────────────────────────────────────────────────────── */
.share-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

.share-url-input {
  flex: 1;
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.btn-sm {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  cursor: pointer;
}

/* Share button active state (note is currently shared) */
#modal-share-btn.active svg { stroke: #1a73e8; }

/* ── Settings modal ──────────────────────────��────────────────────────────── */
.settings-modal {
  max-width: 400px;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 0;
}

.settings-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.settings-section {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-label {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
}

.settings-section input[type="password"] {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.settings-section input[type="password"]:focus { border-color: var(--yellow); }

.settings-error {
  font-size: 13px;
  color: var(--danger);
  padding: 4px 0;
}

.settings-actions {
  padding-top: 4px;
}

/* ── Restore button ───────────────────────────────────────────────────────── */
.btn-restore {
  background: #1e8e3e !important;
}
.btn-restore:hover { background: #1a7a35 !important; }

/* ── Danger link style ─────────���──────────────────────────────────────────── */
.btn-danger-link {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}
.btn-danger-link:hover { background: rgba(217,48,37,.08); }

/* ── Modal share/export toolbar buttons ───────────────────────────────────── */
.modal-toolbar .btn-icon {
  flex-shrink: 0;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
  .notes-grid { column-count: 1; }
}
