:root {
  --primary: #313c4b;
  --surface: #ffffffb3;
  --background: #f8f9fa;
  --text: #202124;
  --text-secondary: #5f6368;
  --border: #dadce0;

  --user-1-bg: #cbf0f8;
  /* Needs to be light for text readability */
  --user-1-border: #1a73e8;
  --user-2-bg: #fce8e6;
  --user-2-border: #d93025;
  --user-3-bg: #e6f4ea;
  --user-3-border: #188038;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  margin: 0;
  padding: 0;
  outline: none;
}

button {
  outline: none !important;
  border: none;
  -webkit-appearance: none;
  appearance: none;
}

body {
  margin: 0;
  padding: 0;
  font-family: "Inter", sans-serif;
  background-color: var(--background);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Prevent body scroll, handle in editor */
}

/* App Shell mimicking mobile */
.app-screen {
  width: 100%;
  height: 100vh;
  background: -webkit-linear-gradient(90deg, #5297ae,#7199be,#959ac4);/* Chrome 10-25, Safari 5.1-6 */ 
  background: linear-gradient(90deg, #5297ae,#7199be,#959ac4);/* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Header */
.app-header {
  height: 60px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
  color: white;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  overflow: hidden;
}

.editor[contenteditable]:empty:before {
  content: attr(data-placeholder);
  color: #999;
  pointer-events: none;
}

.icon-doc {
  font-size: 24px;
}

.doc-title-input {
  font-size: 18px;
  font-weight: 500;
  margin: 0;
  outline: none;
  border: none;
  background: transparent;
  width: 200px;
  font-family: inherit;
  text-overflow: ellipsis;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.doc-title-input::placeholder {
  color: rgba(255, 255, 255, 0.7);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 24px;
  padding: 8px;
  cursor: pointer;
  border-radius: 50%;
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  outline: none;
}

.icon-btn:active {
  background: rgba(255, 255, 255, 0.2);
}

.icon-btn:focus {
  outline: none;
  box-shadow: none;
}


.user-avatar-container {
  position: relative;
  cursor: pointer;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #eee;
}

.user-badge {
  position: absolute;
  bottom: -4px;
  right: -4px;
  background: var(--text);
  color: white;
  font-size: 10px;
  padding: 2px 4px;
  border-radius: 4px;
}

/* Toolbar */
/* Toolbar handled near end of file for sticky overrides */

.toolbar-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 16px;
  scrollbar-width: none;
}

.toolbar-scroll::-webkit-scrollbar {
  display: none;
}

.tool-btn {
  background: #f1f3f4;
  border: none;
  border-radius: 8px;
  min-width: 40px;
  height: 40px;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.tool-btn:active {
  background: #e8eaed;
}

.tool-btn[data-active="true"] {
  background: #e8f0fe;
  color: var(--primary);
}

.separator {
  width: 1px;
  background: var(--border);
  height: 24px;
  margin: 8px 4px;
}

/* Content Area with Glassmorphism */
.content-area {
  flex: 1;
  margin-top: 10px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  overflow-y: auto;
  padding: 24px 16px;
  box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.05);
}

.editor {
  background: transparent;
  min-height: 100%;
  outline: none;
  line-height: 1.6;
  font-size: 16px;
  color: #1a202c;
}

/* Typography in Editor */
.editor h1 {
  font-size: 2em;
  margin-bottom: 0.5em;
}

.editor h2 {
  font-size: 1.5em;
  margin-bottom: 0.5em;
}

.editor h3 {
  font-size: 1.17em;
  margin-bottom: 0.5em;
}

/* Highlights & Comments */
.comment-highlight {
  background-color: #ffe082;
  /* Default comment yellow */
  border-bottom: 2px solid #ffca28;
  cursor: pointer;
}

.comment-highlight.active {
  background-color: #ffd54f;
  outline: 2px solid #ffa000;
}

/* Multi-user edits highlighting */
.user-edit-1 {
  background-color: var(--user-1-bg);
}

.user-edit-2 {
  background-color: var(--user-2-bg);
}

.user-edit-3 {
  background-color: var(--user-3-bg);
}

/* Floating Action Button */
.floating-action-btn {
  position: absolute;
  /* positioned via JS based on selection */
  background: var(--text);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 24px;
  font-weight: 500;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  z-index: 100;
  cursor: pointer;
  white-space: nowrap;
  transform: translateX(-50%);
  /* Enter from bottom */
  animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from {
    transform: translateX(-50%) scale(0.8);
    opacity: 0;
  }

  to {
    transform: translateX(-50%) scale(1);
    opacity: 1;
  }
}

/* Bottom Sheet / Comment Overlay */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.bottom-sheet {
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }

  to {
    transform: translateY(0);
  }
}

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

.comments-list {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.new-comment-area {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: #f8f9fa;
}

textarea {
  width: 100%;
  min-height: 80px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  resize: none;
  margin-bottom: 8px;
}

.primary-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  width: 100%;
  font-weight: 600;
  font-size: 16px;
}

/* Comment Item Styling */
.comment-thread {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  background: white;
}

.comment-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.comment-body {
  font-size: 14px;
  margin-bottom: 8px;
}

.reply-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 12px;
  padding: 0;
  cursor: pointer;
}

.replies-container {
  margin-top: 8px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
}

.reply-item {
  margin-top: 8px;
  font-size: 13px;
  background: #f8f9fa;
  padding: 8px;
  border-radius: 4px;
}

/* Modals */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  /* Center vertically for user modal */
  justify-content: center;
}

.modal-content {
  background: var(--surface);
  padding: 24px;
  border-radius: 16px;
  width: 90%;
  max-width: 400px;
}

.modal-content.full-height {
  height: 90vh;
  display: flex;
  flex-direction: column;
}

.user-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
}

.user-option:hover {
  background: #f1f3f4;
}

.user-option.active {
  border-color: var(--primary);
  background: #e8f0fe;
}

/* Landing Page */
.landing-container {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  text-align: center;
  padding: 20px;
}

.landing-content {
  background: white;
  padding: 40px;
  border-radius: 20px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  max-width: 400px;
  width: 100%;
}

.landing-icon {
  font-size: 64px;
  display: block;
  margin-bottom: 20px;
}

.landing-content h1 {
  margin: 0 0 10px 0;
  color: var(--text);
  font-size: 24px;
}

.landing-content p {
  color: var(--text-secondary);
  margin-bottom: 30px;
  line-height: 1.5;
}

.large-btn {
  width: 100%;
  padding: 16px;
  font-size: 18px;
  border-radius: 12px;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 4px 6px rgba(26, 115, 232, 0.3);
  transition: transform 0.2s;
}

.large-btn:active {
  transform: scale(0.98);
}

/* App Container Layout Fix */
#appContainer {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Sticky Toolbar Fix */
.toolbar {
  background: var(--surface);
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  /* Ensure it stays above scrolling content if needed, but flex handles it currently */
  z-index: 10;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  /* Visual separation */
}

/* History List */
.history-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  /* Prevent container scroll */
}

.history-list {
  flex: 0 0 120px;
  /* Fixed height for list */
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.history-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.history-item.active {
  background-color: #e8f0fe;
}

.history-time {
  font-weight: 500;
  font-size: 14px;
}

.history-preview {
  flex: 1;
  /* Takes remaining space */
  padding: 16px;
  overflow-y: auto;
  /* Scrolls internally */
  background: #fdfdfd;
  position: relative;
  font-size: 14px;
  line-height: 1.6;
}

.restore-bar {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  background: var(--surface);
  flex-shrink: 0;
  /* Keep fixed */
}

.diff-added {
  background-color: #ccffcc;
  cursor: help;
  text-decoration: none;
  position: relative;
}

.diff-removed {
  background-color: #ffcccc;
  text-decoration: line-through;
  color: #999;
}

/* Tooltip for original text */
.diff-added:hover::after {
  content: attr(data-original);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Comment Context (Selected Text) */
.comment-context {
  font-size: 12px;
  color: #5f6368;
  border-left: 3px solid #dfe1e5;
  padding: 4px 8px;
  margin-bottom: 8px;
  background: #f1f3f4;
  border-radius: 0 4px 4px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Delete Buttons */
.delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: #999;
  padding: 4px;
  line-height: 1;
}

.delete-btn:hover {
  color: #d93025;
  /* Red on hover */
  background: #fce8e6;
  border-radius: 4px;
}

/* Comment Reply input wrapper */
.reply-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.send-reply-icon-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  flex-shrink: 0;
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Expiration Badge */
.expiration-badge {
  background: #e6f4ea;
  color: #188038;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
  margin-right: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.3s ease;
  cursor: help;
}

.expiration-badge::before {
  content: "⏳";
  font-size: 12px;
}

.expiration-badge.warn {
  background: #fef7e0;
  color: #b06000;
}

.expiration-badge.critical {
  background: #fce8e6;
  color: #c5221f;
  animation: pulse 2s infinite;
}

.expiration-badge.decay {
  background: #000;
  color: #ff4444;
  border: 1px solid #ff4444;
  font-family: "Roboto Mono", monospace;
}

@keyframes pulse {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
  100% {
    opacity: 1;
  }
}

/* Document Decay Effect */
.editor.decay-mode {
  filter: grayscale(100%) contrast(1.2) sepia(0.2);
  background-color: #f8f8f8;
  pointer-events: none; /* Block editing */
  user-select: none;
  position: relative;
  overflow: hidden;
}

.editor.decay-mode::after {
  content: "ДОКУМЕНТ УНИЧТОЖАЕТСЯ";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-45deg);
  font-size: 48px;
  font-weight: 900;
  color: rgba(255, 0, 0, 0.1);
  white-space: nowrap;
  pointer-events: none;
}

/* Side Menu / Burger Menu */
.side-menu {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    background: white;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    box-shadow: 5px 0 25px rgba(0,0,0,0.15);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
}

.side-menu.hidden {
    transform: translateX(-100%);
    pointer-events: none;
}

/* Menu Overlay */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 2500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.menu-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.side-menu-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text);
}

.side-menu-content {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.menu-item-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border: none;
    background: none;
    border-radius: 8px;
    font-size: 16px;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: background 0.2s;
}

.menu-item-btn:active {
    background: #f1f3f4;
}

.menu-item-btn .icon {
    font-size: 20px;
    width: 24px;
    text-align: center;
}

.menu-section-title {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin: 16px 0 8px 16px;
    letter-spacing: 0.5px;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text);
}

.side-menu .user-avatar-container {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
}

.side-menu .user-avatar-container:active {
    background: #f1f3f4;
}

/* Mobile Adjustments Overrides */
@media (max-width: 600px) {
    .app-header {
        height: 60px;
        flex-direction: row;
        align-items: center;
        padding: 0 16px;
        gap: 0;
    }

    .header-left {
        justify-content: flex-start;
        width: auto;
    }

    .doc-title-input {
        width: 150px;
        text-align: left;
    }

    .header-right {
        justify-content: flex-end;
        width: auto;
    }

    .floating-action-btn {
        margin-top: 0;
        bottom: 100px;
    }
}
