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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --bg: #ffffff;
  --bg-secondary: #f3f4f6;
  --text: #111827;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --shadow: rgba(0, 0, 0, 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.screen {
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Loading Screen */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 1rem;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--bg-secondary);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-text {
  color: var(--text-secondary);
  font-size: 1rem;
}

/* Login Screen */
.login-container {
  max-width: 400px;
  margin: 0 auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100vh;
}

.login-container h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  text-align: center;
  display: block;
}

.subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

#login-form input,
#register-form input {
  width: 100%;
  padding: 0.875rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 1rem;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  width: 100%;
  padding: 0.875rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  margin-bottom: 0.5rem;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

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

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text);
}

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

.btn-danger {
  background: var(--danger);
  color: white;
}

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

.btn-small {
  width: auto;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  margin-left: 0.5rem;
}

.error-message {
  color: var(--danger);
  text-align: center;
  margin-top: 1rem;
  font-size: 0.875rem;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  padding: 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 60px;
}

.header-title-input {
  flex: 1;
  font-size: 1.25rem;
  text-align: center;
  border: none;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  padding: 0.5rem 1rem;
  margin: 0;
  outline: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.header-title-input:not([readonly]) {
  background: var(--bg-secondary);
  border-radius: 0.5rem;
  cursor: text;
}

.header-title-input[readonly] {
  cursor: default;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
  color: var(--text);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Drawer */
.drawer {
  position: fixed;
  top: 0;
  left: -300px;
  width: 300px;
  height: 100vh;
  background: var(--bg);
  box-shadow: 2px 0 10px var(--shadow);
  transition: left 0.3s ease;
  z-index: 200;
  display: flex;
  flex-direction: column;
}

.drawer.open {
  left: 0;
}

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

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.workspace-selector {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
}

.workspace-select {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  background: var(--bg);
}

.workspace-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.workspace-form input[type="text"] {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.875rem;
}

.workspace-form input[type="color"] {
  width: 50px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
}

.workspaces-list {
  max-height: 400px;
  overflow-y: auto;
}

.workspace-item {
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
}

.workspace-item-view {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.workspace-item-edit {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
}

.workspace-edit-name {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.875rem;
}

.workspace-edit-color {
  width: 100%;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  cursor: pointer;
}

.workspace-edit-actions {
  display: flex;
  gap: 0.5rem;
}

.workspace-item-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

.workspace-color {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
}

.workspace-name {
  font-weight: 500;
}

.workspace-default {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-left: 0.5rem;
}

.workspace-actions {
  display: flex;
  gap: 0.25rem;
}

.search-container {
  margin-top: 1rem;
}

.notes-search {
  width: 100%;
  padding: 0.625rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  background: var(--bg);
  transition: border-color 0.2s;
}

.notes-search:focus {
  outline: none;
  border-color: var(--primary);
}

.notes-list {
  flex: 1;
  margin-top: 0.75rem;
  overflow-y: auto;
}

.note-item {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: background 0.2s;
}

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

.note-item-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.note-item-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.drawer-footer {
  padding: 1rem 0 0;
  border-top: 1px solid var(--border);
}

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
  display: none;
}

.overlay.show {
  display: block;
}

/* Editor */
.editor-container {
  position: fixed;
  top: 60px;
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  padding: 0;
}

#editor {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 0.5rem;
  gap: 0.5rem;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 2rem;
  gap: 2rem;
}

.empty-state-message {
  color: var(--text-secondary);
  font-size: 1.125rem;
  text-align: center;
}

.workspace-shortcuts {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 400px;
}

.workspace-shortcut-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border: none;
  border-radius: 0.75rem;
  font-size: 1rem;
  font-weight: 500;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 4px var(--shadow);
  text-align: left;
}

.workspace-shortcut-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px var(--shadow);
}

.workspace-shortcut-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px var(--shadow);
}

.shortcut-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
}

.shortcut-text {
  flex: 1;
}

.note-title-input {
  width: 100%;
  font-size: 1.5rem;
  font-weight: 600;
  border: none;
  padding: 0.5rem 0;
  margin-bottom: 1rem;
  outline: none;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  margin-bottom: 0;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--bg-secondary);
  border-radius: 0.5rem;
}

.toolbar-spacer {
  flex: 1;
}

.note-type-select,
.code-language-select {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 0.875rem;
  background: var(--bg);
}

.rich-toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0;
  padding: 0.5rem;
  background: var(--bg-secondary);
  border-radius: 0.5rem;
}

.toolbar-btn {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  background: var(--bg);
  cursor: pointer;
  font-size: 0.875rem;
}

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

.note-content,
.note-content-rich {
  width: 100%;
  flex: 1;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-family: inherit;
  font-size: 1rem;
  resize: none;
}

.rich-editor-wrapper {
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.note-content-rich {
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  overflow: hidden;
}

.note-content-rich .ql-toolbar {
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.note-content-rich .ql-container {
  flex: 1;
  border: none;
  font-size: 1rem;
  font-family: inherit;
}

.note-content-rich .ql-editor {
  padding: 0.75rem;
  min-height: 100%;
}

.note-content-code {
  width: 100%;
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  overflow: hidden;
}

.note-content-code .CodeMirror {
  height: 100%;
  font-size: 0.875rem;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
}

.editor-status {
  margin-top: 0.5rem;
  text-align: right;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--bg);
  border-radius: 0.5rem;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 1.5rem;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.versions-list {
  overflow-y: auto;
}

.version-item {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: background 0.2s;
}

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

.version-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.version-number {
  font-weight: 600;
}

.version-date {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.version-title {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Share Modal */
.modal-large {
  max-width: 800px;
}

.share-form {
  margin-bottom: 2rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.share-form h3 {
  margin-bottom: 1rem;
  font-size: 1.25rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 1rem;
}

.share-type-select {
  width: 100%;
}

.shares-list-section h3 {
  margin-bottom: 1rem;
  font-size: 1.25rem;
}

.shares-list {
  max-height: 400px;
  overflow-y: auto;
}

.share-item {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  background: var(--bg-secondary);
}

.share-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.share-type {
  font-weight: 600;
  font-size: 0.875rem;
}

.share-url {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.share-url input {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-family: monospace;
  background: var(--bg);
}

.share-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.btn-small {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  background: var(--primary);
  color: white;
  transition: background 0.2s;
}

.btn-small:hover {
  background: var(--primary-dark);
}

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

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

.share-badge {
  background: var(--primary);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
}

/* Share page specific styles */
.share-brand-bar {
  background: linear-gradient(135deg, rgb(61, 145, 104) 0%, rgb(45, 120, 85) 100%);
  padding: 0.75rem 1rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 101;
}

.brand-bar-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 100%;
}

.brand-name {
  color: white;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.5px;
  margin-left: auto;
}

.share-brand-bar .header-left,
.share-brand-bar .header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.share-brand-bar .header-icon-btn {
  color: white;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 0.375rem;
  transition: background-color 0.2s;
}

.share-brand-bar .header-icon-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.share-brand-bar .share-indicator:hover {
  background: rgba(255, 255, 255, 0.15);
}

.share-title-header {
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  z-index: 100;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.share-title-header .header-title-input {
  width: 100%;
  max-width: 800px;
}

.note-type-badge {
  font-size: 0.75rem;
  padding: 0.25rem 0.625rem;
  background: var(--bg-secondary);
  border-radius: 1rem;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.share-brand-bar .note-type-badge {
  background: rgba(255, 255, 255, 0.25);
  color: white;
}

/* Share page editor container - different from main app */
#share-app .editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  height: 100%;
  position: relative;
  top: auto;
  left: auto;
  right: auto;
  bottom: auto;
  padding: 0;
  margin-top: 0.5rem;
}
.note-container {
  position: fixed;
  top: calc(64px + 60px);
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.note-header {
  display: none;
}

.note-meta {
  display: none;
}

.note-textarea {
  flex: 1;
  width: 100%;
  padding: 1.5rem;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.6;
  resize: none;
  background: var(--bg);
  color: var(--text);
  overflow-y: auto;
}

#rich-editor,
#code-editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 1rem;
  width: 100%;
  height: 100%;
}

#quill-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  overflow: hidden;
}

#quill-editor .ql-toolbar {
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

#quill-editor .ql-container {
  flex: 1;
  border: none;
  overflow-y: auto;
}

#quill-editor .ql-editor {
  min-height: 100%;
  padding: 1rem;
}

#code-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  overflow: hidden;
}

.CodeMirror {
  height: 100% !important;
  font-size: 14px;
}

/* Share page header icon buttons - uniform size */
#share-app .header-icon-btn {
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  font-size: 1.5rem;
  cursor: pointer;
  border-radius: 0.375rem;
  transition: background-color 0.2s;
  color: var(--text);
  text-decoration: none;
  padding: 0;
  line-height: 1;
}

#share-app .header-icon-btn:hover {
  background-color: var(--bg-secondary);
}

#share-app .header-icon-btn.share-indicator {
  cursor: default;
  color: var(--primary);
}

#share-app .header-icon-btn.share-indicator:hover {
  background-color: transparent;
}

#share-app #home-link {
  display: none;
}

#share-app #home-link.visible {
  display: inline-flex;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 2rem;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
  z-index: 1000;
}

.toast.show {
  opacity: 1;
  visibility: visible;
}

/* Password form styling */
#password-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
}

#password-form input[type="password"] {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

#password-form input[type="password"]:focus {
  border-color: var(--primary);
}

#password-error {
  color: #ef4444;
  font-size: 0.875rem;
  margin-top: 0.5rem;
  min-height: 1.25rem;
}

/* Mobile optimizations */
@media (max-width: 768px) {
  .drawer {
    width: 80vw;
    left: -80vw;
  }
  
  .modal-content {
    max-height: 90vh;
  }
  
  /* Mobile adjustments for share page */
  .share-brand-bar {
    padding: 0.5rem;
  }
  
  .brand-name {
    font-size: 0.875rem;
  }
  
  .share-brand-bar .note-type-badge {
    display: none;
  }
  
  .share-title-header {
    top: 56px;
    height: 50px;
    padding: 0.5rem;
  }
  
  .share-title-header .header-title-input {
    font-size: 1.125rem;
  }
  
  #share-app .note-container {
    top: calc(56px + 50px);
  }
  
  #share-app #rich-editor,
  #share-app #code-editor-container {
    padding: 0.5rem;
  }
  
  #share-app .note-textarea {
    padding: 1rem;
  }
}

/* PWA specific */
@media (display-mode: standalone) {
  .header {
    padding-top: calc(1rem + env(safe-area-inset-top, 0px));
    height: calc(60px + env(safe-area-inset-top, 0px));
  }
  
  .editor-container {
    top: calc(60px + env(safe-area-inset-top, 0px));
  }
  
  .drawer {
    padding-top: env(safe-area-inset-top, 0px);
  }
}
