/* iOS Dark Theme */

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #000;
  color: #fff;
  height: 100vh;
  overflow: hidden;
}

/* Screens */
.screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
}

/* Login Screen */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 20px;
  background: #000;
}

.login-header {
  text-align: center;
  margin-bottom: 40px;
}

.login-header h1 {
  font-size: 32px;
  margin: 0;
  font-weight: 600;
}

.login-header p {
  font-size: 16px;
  color: #999;
  margin: 8px 0 0 0;
}

.login-form {
  width: 100%;
  max-width: 300px;
}

.login-form input {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 12px;
  border: none;
  border-radius: 8px;
  background: #1a1a1a;
  color: #fff;
  font-size: 16px;
}

.login-form input::placeholder {
  color: #666;
}

.error-message {
  color: #ff3b30;
  font-size: 13px;
  margin-top: 8px;
  text-align: center;
}

/* App Layout */
.app-container {
  --sidebar-width: 320px;
  display: grid;
  grid-template-columns: var(--sidebar-width) 8px 1fr;
  grid-template-rows: 44px 1fr;
  height: 100vh;
  background: #000;
}

.header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: #1a1a1a;
  border-bottom: 1px solid #333;
  height: 44px;
}

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

/* Sidebar */
.sidebar {
  grid-row: 2;
  grid-column: 1;
  display: flex;
  flex-direction: column;
  background: #0a0a0a;
  border-right: 1px solid #333;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar-resize-handle {
  grid-row: 2;
  grid-column: 2;
  cursor: col-resize;
  background: linear-gradient(to right, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
  border-left: 1px solid #1e1e1e;
  border-right: 1px solid #1e1e1e;
}

.sidebar-resize-handle:hover,
.sidebar-resize-handle.dragging {
  background: linear-gradient(to right, rgba(10, 132, 255, 0.18), rgba(10, 132, 255, 0.35), rgba(10, 132, 255, 0.18));
}

.sidebar-header {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid #333;
}

.sidebar-search {
  flex: 1;
  min-width: 0;
  border: 1px solid #2a2a2a;
  background: #111;
  color: #ddd;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  -webkit-user-select: text;
  user-select: text;
}

.sidebar-search::placeholder {
  color: #7a7a7a;
}

.btn-ghost {
  background: #111;
  color: #b9c6d9;
  border: 1px solid #273445;
  padding: 8px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.file-tree {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0;
}

.tree-item {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  border-left: 3px solid transparent;
  gap: 8px;
  font-size: 14px;
  min-width: 100%;
  width: max-content;
}

.tree-item:active {
  background: rgba(255, 255, 255, 0.1);
}

.tree-item.active {
  border-left-color: #0a84ff;
  background: rgba(10, 132, 255, 0.1);
  color: #0a84ff;
}

.tree-item.folder {
  font-weight: 500;
  cursor: grab;
}

.tree-item.folder.dragging {
  opacity: 0.45;
}

.tree-item.folder.drop-before {
  box-shadow: inset 0 2px 0 #0a84ff;
}

.tree-item.folder.drop-after {
  box-shadow: inset 0 -2px 0 #0a84ff;
}

.tree-item-icon {
  width: 20px;
  text-align: center;
}

.tree-item-toggle {
  width: 14px;
  color: #888;
  display: inline-flex;
  justify-content: center;
  transition: transform 0.18s ease;
}

.tree-item.folder:not(.collapsed) .tree-item-toggle {
  transform: rotate(90deg);
}

.tree-item-name {
  flex: 0 0 auto;
  white-space: nowrap;
}

.tree-item-menu {
  opacity: 0;
  font-size: 16px;
  cursor: pointer;
}

.tree-item-action {
  opacity: 0;
  font-size: 16px;
  cursor: pointer;
}

.search-meta {
  padding: 8px 16px;
  font-size: 12px;
  color: #88a0b8;
}

.search-result {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding-top: 10px;
  padding-bottom: 10px;
}

.search-result .tree-item-name {
  width: 100%;
}

.search-path {
  font-size: 11px;
  color: #7294b8;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-snippet {
  font-size: 11px;
  color: #969696;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-item:hover .tree-item-menu {
  opacity: 1;
}

.tree-item:hover .tree-item-action {
  opacity: 1;
}

.tree-children {
  padding-left: 16px;
}

/* Editor Container */
.editor-container {
  grid-row: 2;
  grid-column: 3;
  display: flex;
  flex-direction: column;
  background: #000;
  overflow: hidden;
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #333;
  background: #1a1a1a;
}

.editor-header h2 {
  margin: 0;
  font-size: 16px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-controls {
  display: flex;
  gap: 8px;
}

.editor-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.format-toolbar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid #333;
  background: #111;
  overflow-x: auto;
}

.format-toolbar .btn {
  min-width: 48px;
  padding: 6px 10px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid #2b3a4a;
  background: #111923;
  color: #b8d2ee;
  cursor: pointer;
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}

.attachment-chip:hover {
  background: #162537;
}

.attachment-chip-emoji {
  font-size: 14px;
}

.markdown-preview {
  flex: 1;
  overflow: auto;
  padding: 16px 22px 32px;
  line-height: 1.55;
  color: #f2f2f2;
}

.markdown-preview[contenteditable="true"] {
  outline: none;
  cursor: text;
  -webkit-user-select: text;
  user-select: text;
}

.markdown-preview[contenteditable="true"]:focus {
  box-shadow: inset 0 0 0 1px rgba(10, 132, 255, 0.25);
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3 {
  color: #ffffff;
  margin-top: 1.1em;
}

.markdown-preview code {
  background: #121212;
  border: 1px solid #2b2b2b;
  border-radius: 6px;
  padding: 1px 6px;
}

.markdown-preview pre {
  background: #0d0d0d;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  padding: 10px;
  overflow-x: auto;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  text-align: center;
  padding: 20px;
}

/* Editor */
#noteEditor {
  flex: 1;
  width: 100%;
  height: 100%;
}

.ace_editor {
  background: #000 !important;
  color: #fff !important;
  font-family: 'Monaco', 'Courier New', monospace !important;
  font-size: 14px !important;
}

.ace_gutter {
  background: #0a0a0a !important;
  color: #666 !important;
}

.ace_cursor {
  color: #0a84ff !important;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: #1a1a1a;
  border-radius: 12px;
  padding: 20px;
  width: min(360px, calc(100% - 32px));
  border: 1px solid #2a2a2a;
}

.modal-content h3 {
  margin: 0 0 16px 0;
  font-size: 18px;
  font-weight: 600;
}

.modal-content input {
  width: 100%;
  padding: 12px;
  margin-bottom: 16px;
  border: none;
  border-radius: 8px;
  background: #0a0a0a;
  color: #fff;
  font-size: 16px;
  -webkit-user-select: text;
  user-select: text;
}

.modal-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.modal-buttons-triple {
  grid-template-columns: 1fr 1fr 1fr;
}

.upload-modal-content {
  max-width: min(560px, calc(100% - 32px));
}

.upload-info-text {
  margin: 0 0 12px 0;
  color: #a9b8c8;
  font-size: 13px;
  line-height: 1.4;
}

.upload-preview-area {
  min-height: 100px;
  max-height: 48vh;
  overflow: auto;
  border: 1px solid #2a2a2a;
  background: #0f0f0f;
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 14px;
}

.upload-preview-area img,
.upload-preview-area video {
  max-width: 100%;
  max-height: 42vh;
  border-radius: 8px;
}

.upload-preview-area audio {
  width: 100%;
}

.upload-preview-fallback {
  color: #9a9a9a;
  font-size: 13px;
}

/* Buttons */
.btn {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: #0a84ff;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: opacity 0.2s;
}

.btn:active {
  opacity: 0.8;
}

.btn-icon {
  padding: 8px 12px;
  background: transparent;
  color: #0a84ff;
  font-size: 16px;
}

.btn-small {
  padding: 8px 12px;
  font-size: 12px;
}

.btn-secondary {
  background: #3a3a3a;
  color: #fff;
}

.btn-danger {
  background: transparent;
  color: #ff3b30;
  padding: 6px 10px;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #444;
}

/* Responsive */
@media (max-width: 768px) {
  .app-container {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: absolute;
    left: 0;
    top: 44px;
    width: 100%;
    height: calc(100vh - 44px);
    z-index: 50;
    max-width: 260px;
  }

  .editor-container {
    grid-column: 1;
  }

  .sidebar-resize-handle {
    display: none;
  }
}

/* iPhone notch support */
@supports (padding: max(0px)) {
  .header {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  .sidebar {
    padding-bottom: env(safe-area-inset-bottom);
  }
}
