:root {
  --bg: #ffffff;
  --bg-sidebar: #f7f8fa;
  --bg-hover: #eef0f4;
  --bg-active: #e6e9f5;
  --border: #e2e5ea;
  --text: #1f2937;
  --text-muted: #6b7280;
  --placeholder: #b6bbc4;
  --accent: #4f46e5;
  --accent-contrast: #ffffff;
  --danger: #dc2626;
  --danger-bg: #fde8e8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.hidden {
  display: none !important;
}

/* ================= Auth screen ================= */
.auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-sidebar);
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  box-shadow: 0 8px 30px rgba(17, 24, 39, 0.06);
}

.auth-title {
  margin: 0 0 4px;
  font-size: 22px;
}

.auth-sub {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.field input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  outline: none;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.auth-error {
  margin: 0;
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: 8px;
  padding: 8px 12px;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:hover {
  opacity: 0.92;
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
}

.auth-switch {
  margin: 18px 0 0;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover {
  text-decoration: underline;
}

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

/* ---------- Sidebar ---------- */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

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

.sidebar-header h1 {
  font-size: 18px;
  margin: 0;
}

.btn-new {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-new:hover {
  opacity: 0.9;
}

.btn-new:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.note-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}

.note-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.note-item:hover {
  background: var(--bg-hover);
}

.note-item.active {
  background: var(--bg-active);
  font-weight: 600;
}

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

.note-item-del {
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}

.note-item:hover .note-item-del {
  opacity: 0.6;
}

.note-item-del:hover {
  opacity: 1;
  background: var(--danger-bg);
}

.note-list-empty {
  padding: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

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

.user-email {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Main ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ---------- Tab bar ---------- */
.tab-bar {
  display: flex;
  align-items: stretch;
  gap: 2px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  min-height: 40px;
}

.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-right: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  background: transparent;
  white-space: nowrap;
  max-width: 200px;
}

.tab:hover {
  background: var(--bg-hover);
}

.tab.active {
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: inherit;
  padding: 2px 5px;
  border-radius: 4px;
}

.tab-close:hover {
  background: rgba(0, 0, 0, 0.1);
}

/* ---------- Editor ---------- */
.editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px;
  gap: 12px;
  min-height: 0;
}

.note-title {
  border: none;
  outline: none;
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  width: 100%;
}

.note-title::placeholder {
  color: var(--placeholder);
}

.note-content {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: transparent;
  width: 100%;
  font-family: inherit;
}

.note-content::placeholder {
  color: var(--placeholder);
}

.editor-status {
  font-size: 12px;
  color: var(--text-muted);
  min-height: 16px;
}

/* ---------- Empty state ---------- */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 4px;
  padding: 24px;
  text-align: center;
}

.empty-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.empty-sub {
  font-size: 13px;
  margin: 0;
}

/* ---------- Editor toolbar + tombol share ---------- */
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.btn-ghost:hover {
  background: var(--bg-hover);
}

/* ---------- Dialog (share) ---------- */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.dialog {
  background: var(--bg);
  border-radius: 12px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

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

.dialog-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog-desc {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.share-link-row {
  display: flex;
  gap: 8px;
}

.share-link-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg-sidebar);
}

.share-perm {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
}

.share-perm-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.link-btn.danger {
  color: var(--danger);
  align-self: flex-start;
}

/* ---------- Halaman note yang dibagikan ---------- */
.shared-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.shared-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sidebar);
}

.shared-brand {
  font-weight: 700;
}

.shared-badge {
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 999px;
}

.shared-badge.view {
  background: #eef2ff;
  color: #4338ca;
}

.shared-badge.edit {
  background: #dcfce7;
  color: #15803d;
}

.shared-status {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
}

.shared-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  min-height: 0;
}

.shared-error {
  padding: 32px 24px;
  text-align: center;
  color: var(--text-muted);
}

/* ---------- Toolbar format (rich text) ---------- */
.format-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.fmt-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  line-height: 1;
}

.fmt-btn:hover {
  background: var(--bg-hover);
}

.fmt-divider {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 2px;
}

/* ---------- Editor contenteditable ---------- */
.note-content {
  overflow-y: auto;
  min-height: 0;
}

.note-content:focus {
  outline: none;
}

/* Placeholder buat contenteditable yang masih kosong */
.note-content:empty:before {
  content: attr(data-placeholder);
  color: var(--placeholder);
  pointer-events: none;
}

.note-content ul,
.note-content ol {
  padding-left: 24px;
  margin: 6px 0;
}

/* Baris stempel tanggal & jam */
.timestamp {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-top: 4px;
}
