:root {
  --navy: #001f3f;
  --navy-light: #003366;
  --navy-mid: #0A2E4D;
  --bg-soft: #F4F6F8;
  --white: #FFFFFF;
  --accent: #00B8A9;
  --accent-dark: #009688;
  --text-main: #1A1A1A;
  --text-secondary: #6C757D;
  --border: #DEE2E6;
  --success: #28A745;
  --danger: #DC3545;
  --warning: #FFC107;
  --info: #17A2B8;
  --sidebar-width: 300px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

.global-error {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--danger);
  color: var(--white);
  font-size: 13px;
  text-align: center;
  padding: 8px 16px;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-main);
  background: var(--bg-soft);
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--navy);
  color: var(--white);
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow: hidden;
  transition: width 0.18s ease, padding 0.18s ease;
}

.sidebar.is-collapsed {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  border: none;
}

.sidebar-show-btn {
  position: fixed;
  top: 8px;
  left: 16px;
  z-index: 40;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--navy);
  cursor: pointer;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  display: none;
}

.sidebar.is-collapsed ~ .content .editor-topbar {
  padding-left: 60px;
}

.sidebar.is-collapsed ~ .content .empty-state {
  padding-top: 64px;
}

.sidebar-show-btn.is-visible {
  display: block;
}

.sidebar-show-btn:hover {
  background: var(--bg-soft);
}

.sidebar-top {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 12px;
}

.sidebar-hide-btn {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  font-size: 14px;
}

.sidebar-hide-btn:hover {
  background: var(--navy-light);
  color: var(--white);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  padding: 8px;
  flex: 1;
  min-width: 0;
}

.brand-logo-wrap {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  display: block;
}

.brand-logo-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy-mid);
  border: 1px dashed rgba(255,255,255,0.4);
  font-size: 18px;
  color: rgba(255,255,255,0.7);
}

.brand-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.sidebar-header h1 {
  font-size: 20px;
  margin: 4px 0 14px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.count {
  font-size: 12px;
  font-weight: 400;
  color: rgba(255,255,255,0.55);
}

.btn-cta {
  background: var(--accent);
  color: var(--white);
  border: none;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-cta:hover {
  background: var(--accent-dark);
}

.search-box {
  margin-top: 14px;
}

.search-box input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--navy-light);
  background: var(--navy-mid);
  color: var(--white);
  font-size: 13px;
}

.search-box input::placeholder {
  color: rgba(255,255,255,0.5);
}

.search-box input:focus {
  outline: 2px solid var(--accent);
}

.notes-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.note-item {
  background: var(--navy-mid);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  position: relative;
}

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

.note-item.active {
  background: var(--navy-light);
  border-color: var(--accent);
}

.note-item-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 20px;
}

.note-item-preview {
  font-size: 12px;
  color: rgba(255,255,255,0.55);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item-meta {
  font-size: 10.5px;
  color: rgba(255,255,255,0.4);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.note-item-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.4);
  cursor: pointer;
  font-size: 12px;
  display: none;
  padding: 2px 4px;
  border-radius: 4px;
}

.note-item:hover .note-item-delete {
  display: block;
}

.note-item-delete:hover {
  color: var(--danger);
  background: rgba(255,255,255,0.08);
}

.empty-list {
  color: rgba(255,255,255,0.45);
  font-size: 13px;
  text-align: center;
  padding: 24px 8px;
}

.sidebar-account {
  padding-top: 12px;
  border-top: 1px solid var(--navy-light);
  margin-top: 12px;
}

.account-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.account-hint {
  font-size: 11.5px;
  color: rgba(255,255,255,0.5);
  line-height: 1.4;
}

.btn-account {
  background: var(--navy-mid);
  color: var(--white);
  border: 1px solid var(--navy-light);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}

.btn-account:hover {
  background: var(--navy-light);
}

.account-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.account-username {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-role {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: rgba(0, 184, 169, 0.15);
  padding: 2px 7px;
  border-radius: 999px;
  flex-shrink: 0;
}

.account-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.account-link {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.65);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  padding: 4px 2px;
}

.account-link:hover {
  color: var(--white);
}

/* ---------- Content ---------- */

.content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
}

.empty-state {
  margin: auto;
  max-width: 460px;
  text-align: center;
  padding: 40px;
}

.empty-state h2 {
  font-size: 26px;
  margin-bottom: 10px;
}

.empty-state p {
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
}

.editor {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.editor-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}

.guest-badge {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.editor-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
}

.save-status {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.save-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
}

.save-status.is-saved .save-dot {
  background: var(--success);
}

.autosave-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  margin-left: auto;
}

.autosave-toggle input {
  display: none;
}

.toggle-slider {
  width: 34px;
  height: 18px;
  background: var(--border);
  border-radius: 999px;
  position: relative;
  transition: background 0.15s ease;
  flex-shrink: 0;
}

.toggle-slider::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--white);
  top: 2px;
  left: 2px;
  transition: left 0.15s ease;
}

.autosave-toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.autosave-toggle input:checked + .toggle-slider::after {
  left: 18px;
}

.btn-save {
  background: var(--navy);
  color: var(--white);
  border: none;
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
}

.btn-save:hover {
  background: var(--navy-light);
}

.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 15px;
  padding: 6px;
  border-radius: 6px;
  color: var(--text-secondary);
}

.btn-icon:hover {
  background: var(--bg-soft);
  color: var(--danger);
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 3px;
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.toolbar button {
  background: transparent;
  border: none;
  min-width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-main);
}

.toolbar button:hover:not(:disabled) {
  background: var(--bg-soft);
  color: var(--accent-dark);
}

.toolbar button.is-active {
  background: rgba(0, 184, 169, 0.15);
  color: var(--accent-dark);
}

.toolbar button:disabled {
  color: var(--border);
  cursor: not-allowed;
}

.toolbar select {
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--text-main);
  background: var(--white);
  padding: 0 6px;
}

.color-swatch {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: pointer;
}

.color-swatch:hover {
  background: var(--bg-soft);
}

.color-swatch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.more-group {
  position: relative;
}

.more-menu {
  position: absolute;
  top: 34px;
  right: 0;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  display: flex;
  flex-direction: column;
  min-width: 180px;
  z-index: 20;
  padding: 6px;
}

.more-menu button {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 6px;
}

.more-menu button:hover {
  background: var(--bg-soft);
}

.editor-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 32px 48px 80px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 31, 63, 0.22) transparent;
}

.editor-body::-webkit-scrollbar {
  width: 6px;
}

.editor-body::-webkit-scrollbar-track {
  background: transparent;
}

.editor-body::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 999px;
}

.editor-body:hover::-webkit-scrollbar-thumb {
  background: rgba(0, 31, 63, 0.22);
}

.editor-body::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 31, 63, 0.4);
}

.note-page {
  max-width: 820px;
  width: 100%;
  min-height: calc(100% - 4px);
  margin: 0 auto;
  padding: 48px 56px 64px;
  background: var(--white);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0, 31, 63, 0.06), 0 12px 32px rgba(0, 31, 63, 0.14);
}

.note-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 6px;
  outline: none;
  color: var(--text-main);
}

.note-subtitle {
  font-size: 16px;
  font-weight: 400;
  margin-bottom: 18px;
  outline: none;
  color: var(--text-secondary);
}

.note-content {
  font-size: 15px;
  line-height: 1.7;
  outline: none;
  color: var(--text-main);
  min-height: 300px;
}

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

.note-content a {
  color: var(--accent-dark);
}

[contenteditable][data-placeholder]:empty::before {
  content: attr(data-placeholder);
  color: var(--text-secondary);
  pointer-events: none;
}

.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 4px 0;
}

.checklist-item input[type="checkbox"] {
  margin-top: 4px;
}

.checklist-item.checked .checklist-text {
  text-decoration: line-through;
  color: var(--text-secondary);
}

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 31, 63, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  background: var(--white);
  border-radius: 12px;
  padding: 24px;
  width: 360px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-card-wide {
  width: 440px;
}

.modal-subheading {
  font-size: 14px;
  color: var(--navy);
  margin: 20px 0 4px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.modal-error {
  background: rgba(220, 53, 69, 0.1);
  color: var(--danger);
  font-size: 12.5px;
  padding: 8px 10px;
  border-radius: 6px;
  margin: 10px 0 0;
}

.users-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.users-list li {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.users-list li:last-child {
  border-bottom: none;
}

.user-row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-row-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.user-row-info span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.users-list .user-role-tag {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--accent-dark);
  background: rgba(0, 184, 169, 0.12);
  padding: 2px 7px;
  border-radius: 999px;
  flex: none;
}

.user-row-actions {
  display: flex;
  gap: 4px;
  flex: none;
}

.user-row-actions button {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-muted, #667);
}

.user-row-actions button:hover {
  background: rgba(0, 0, 0, 0.06);
}

.user-delete-btn:hover {
  color: var(--danger);
}

.user-edit-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px dashed var(--border);
}

.user-edit-form select,
.user-edit-form input {
  font-size: 12px;
  padding: 4px 6px;
}

.user-edit-form input[type="password"] {
  flex: 1;
  min-width: 120px;
}

.user-edit-error {
  color: var(--danger);
  font-size: 11px;
  width: 100%;
}

.modal-card h2 {
  margin-top: 0;
  font-size: 18px;
  color: var(--navy);
}

.modal-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 16px 0 6px;
}

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

.logo-preview-box {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg-soft);
}

.logo-preview-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.logo-preview-box span {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
}

.logo-upload-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.logo-upload-actions input[type="file"] {
  font-size: 12px;
  max-width: 190px;
}

.modal-card input[type="text"],
.modal-card input[type="password"],
.modal-card select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.modal-card input[type="text"]:focus,
.modal-card input[type="password"]:focus,
.modal-card select:focus {
  outline: 2px solid var(--accent);
}

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

.btn-secondary {
  background: var(--white);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}

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

@media (max-width: 720px) {
  .sidebar {
    position: absolute;
    z-index: 30;
    height: 100%;
  }
  .editor-body {
    padding: 16px 12px 40px;
  }
  .note-page {
    padding: 28px 22px 40px;
  }
}
