:root {
    --background-color: #ffffff;
    --text-color: #1a1a1a;
    --border-color: #e0e0e0;
    --header-bg: #1a1a1a;
    --header-text-color: #f0f0f0;
    --header-icon-color: #a0a0a0;
    --header-icon-hover-color: #ffffff;
    --divider-color: #dcdcdc;
    --pro-bg: #e0e0e0;
    --pro-text: #333;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    background-color: var(--background-color);
    color: var(--text-color);
    overflow: hidden;
}

#app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    padding-top: env(safe-area-inset-top);
    background-color: var(--header-bg);
    color: var(--header-text-color);
    flex-shrink: 0;
    min-height: 40px;
    box-sizing: border-box;
}

.header-section {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-left {
    gap: 15px;
    flex: 1;
}

.header-right {
    gap: 10px;
    height: 100%;
}

.logo-container {
    display: flex;
    align-items: center;
}

.logo-link {
    text-decoration: none;
    color: var(--header-text-color);
    transition: text-decoration 0.2s ease;
}

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

.logo-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--header-text-color);
    line-height: 1;
    display: flex;
    align-items: center;
}

.header-button {
    display: flex;
    align-items: center;
    background: none;
    border: none;
    color: var(--header-icon-color);
    cursor: pointer;
    padding: 5px 8px;
    border-radius: 5px;
    font-size: 13px;
    line-height: 1;
    transition: all 0.2s ease;
}

.header-button:hover {
    color: var(--header-icon-hover-color);
    background-color: rgba(255, 255, 255, 0.1);
}

.header-button svg {
    width: 18px;
    height: 18px;
}

.header-button.active {
    color: var(--header-icon-hover-color);
    background-color: rgba(255, 255, 255, 0.15);
}

.header-button.private-active {
    color: #ffc107 !important;
    background-color: rgba(255, 193, 7, 0.15);
}

.header-button.private-active:hover {
    color: #ffb300 !important;
    background-color: rgba(255, 193, 7, 0.25);
}

.header-button.private-active svg {
    color: #ffc107 !important;
    stroke: #ffc107 !important;
}

.header-button.private-active:hover svg {
    color: #ffb300 !important;
    stroke: #ffb300 !important;
}

.sync-scroll-control,
.column-toggle {
    display: flex;
    align-items: center;
    font-size: 13px;
    color: var(--header-icon-color);
    padding: 5px 8px;
    cursor: pointer;
    border-radius: 5px;
}

.sync-scroll-control:hover,
.column-toggle:hover {
    color: var(--header-icon-hover-color);
    background-color: rgba(255, 255, 255, 0.1);
}

/* Share popover */
.share-container {
    position: relative;
    display: flex;
    align-items: center;
    align-self: stretch;
}

#share-button {
    align-self: stretch;
    padding-top: 0;
    padding-bottom: 0;
    position: relative;
}

/* Loading indicator - spinning circle */
#share-button.is-saving span {
    position: relative;
}

#share-button.is-saving span::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 50%;
    margin-top: -8px; /* Half of height to center */
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* Unsaved changes indicator */
#share-button.has-unsaved-changes::after {
    content: '•';
    color: white;
    font-size: 16px;
    margin-left: 4px;
    opacity: 0.9;
}

#share-button.has-unsaved-changes::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 2px;
    background-color: #ffc107;
}

#share-popover {
    position: absolute;
    top: calc(100% - 2px);
    left: 0;
    width: 240px;
    background-color: var(--background-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    padding: 12px;
    padding-top: 14px;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 0.2s ease, visibility 0s 0.2s, transform 0.2s ease;
    pointer-events: none;
}

/* Invisible bridge area between button and popover */
#share-popover::before {
    content: '';
    position: absolute;
    top: -30px;
    left: 0;
    right: 0;
    height: 32px;
    pointer-events: none;
}

.share-container:hover #share-popover,
#share-popover:hover,
#share-popover.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
    transition: opacity 0.2s ease, visibility 0s, transform 0.2s ease;
}

.popover-options {
    list-style: none;
    margin: 0;
    padding: 0;
}

.popover-options li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-color);
}

.popover-options li:hover {
    background-color: #f5f5f5;
}

.popover-options li .check-mark {
    visibility: hidden;
    color: #007bff;
}

.popover-options li.selected .check-mark {
    visibility: visible;
}

.popover-pro-tag {
    font-size: 11px;
    font-weight: 600;
    background-color: var(--pro-bg);
    color: var(--pro-text);
    padding: 2px 6px;
    border-radius: 4px;
}

.popover-unsaved-warning {
    padding: 8px 12px;
    background-color: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 6px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.popover-unsaved-warning .warning-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.popover-unsaved-warning .warning-text {
    font-size: 13px;
    font-weight: 600;
    color: #856404;
}

.popover-expiry {
    padding: 8px 12px;
    background-color: #f8f9fa;
    border-radius: 6px;
    margin-bottom: 8px;
}

.expiry-label {
    display: block;
    font-size: 11px;
    color: #6c757d;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.expiry-date {
    display: block;
    font-size: 13px;
    color: var(--text-color);
    font-weight: 500;
}

.popover-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 8px 0;
}

.popover-section-title {
    font-size: 11px;
    color: #6c757d;
    margin-bottom: 6px;
    padding: 0 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.popover-delete-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    padding: 10px 12px;
    border: none;
    background-color: #dc3545;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.2s ease;
}

.popover-delete-btn:hover {
    background-color: #c82333;
}

.popover-delete-btn svg {
    width: 16px;
    height: 16px;
}

/* Cover image input */
#cover-image-container {
    padding: 10px 15px;
    background: #f8f8f8;
    border-bottom: 1px solid var(--border-color);
    display: none;
}

#cover-image-container.visible {
    display: block;
}

#cover-image-input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
}

/* Main content */
.main-content {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
}

.panel {
    flex: 1 1 50%;
    height: 100%;
    overflow-y: auto;
    box-sizing: border-box;
}

/* Editor */
#editor-container {
    padding: 0;
    display: flex;
    flex-direction: column;
}

#editor-left {
    width: 100%;
    height: 100%;
    border: none;
    resize: none;
    padding: 10px;
    font-family: monospace;
    font-size: 16px;
    box-sizing: border-box;
}

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

/* Preview */
#preview {
    padding: 10px;
}

#preview-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 0px;
}

/* Override markdown-body max-width for images - already handled by markdown-body */
#preview-content.markdown-body {
    box-sizing: border-box;
}

.divider {
    width: 5px;
    background-color: var(--divider-color);
    cursor: col-resize;
    flex-shrink: 0;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: white;
    padding: 30px;
    border-radius: 8px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 20px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
}

.modal-close:hover {
    color: #333;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
}

.form-group input:focus {
    outline: none;
    border-color: #007bff;
}

.btn {
    width: 100%;
    padding: 10px;
    background-color: #1a1a1a;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

.btn:hover {
    background-color: #333;
}

.modal-footer {
    text-align: center;
    margin-top: 15px;
    font-size: 14px;
    color: #1a1a1a;
}

.modal-footer a {
    color: #1a1a1a;
    cursor: pointer;
    text-decoration: underline;
    font-weight: 500;
}

.modal-footer a:hover {
    color: #333;
}

/* Confirm modal */
.confirm-modal {
    max-width: 400px;
}

.confirm-modal p {
    margin: 20px 0;
    font-size: 15px;
    line-height: 1.5;
}

.confirm-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.confirm-buttons .btn {
    width: auto;
    padding: 10px 20px;
}

.btn-secondary {
    background-color: #f5f5f5;
    color: #1a1a1a;
    border: 1px solid #e0e0e0;
}

.btn-secondary:hover {
    background-color: #e0e0e0;
}

/* Mobile */
.mobile-toggle {
    display: none;
}

.desktop-only {
    display: flex;
}

@media (max-width: 768px) {
    header {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE and Edge */
        gap: 0;
    }

    header::-webkit-scrollbar {
        display: none; /* Chrome, Safari, Opera */
    }

    .header-section {
        flex-shrink: 0;
        gap: 8px;
    }

    .header-left,
    .header-right {
        gap: 8px;
        height: 100%;
    }

    .header-left {
        flex: 0 0 auto;
    }

    .header-right {
        flex: 0 0 auto;
    }

    .logo-text {
        font-size: 14px;
    }

    /* Mobile header buttons */
    .header-button {
        flex: 0 0 auto;
        justify-content: center;
        padding: 5px 8px;
        font-size: 13px;
    }

    .logo-container {
        flex: 0 0 auto;
        margin-right: 8px;
    }

    .share-container {
        flex: 0 0 auto;
        display: flex;
        justify-content: center;
        align-self: stretch;
    }

    #share-button {
        align-self: stretch;
        padding-top: 0;
        padding-bottom: 0;
    }

    /* Mobile popover backdrop */
    body.popover-open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
    }

    /* Mobile popover positioning */
    #share-popover {
        position: fixed !important;
        top: calc(40px + env(safe-area-inset-top) - 2px) !important;
        left: 50% !important;
        width: calc(100vw - 40px);
        max-width: 320px;
        z-index: 99999 !important;
        transform: translateX(-50%) !important;
        -webkit-transform: translateX(-50%) !important;
        transition: opacity 0.2s ease !important;
        will-change: transform;
        padding-top: 14px !important;
    }

    #share-popover.active {
        opacity: 1 !important;
        visibility: visible !important;
        display: block !important;
        transform: translateX(-50%) !important;
        -webkit-transform: translateX(-50%) !important;
    }

    .desktop-only {
        display: none !important;
    }

    .main-content {
        position: relative;
        z-index: 1; /* Keep main content below popover */
    }

    .panel {
        width: 100%;
        position: absolute;
    }

    #editor-container {
        display: none;
        opacity: 0;
        z-index: 2;
        padding: 0;
    }

    #preview {
        display: block;
        opacity: 1;
        z-index: 3;
        padding: 20px;
        padding-bottom: 120px; /* Extra space for mobile toggle pill */
    }

    #editor-container .CodeMirror {
        padding-bottom: 120px; /* Extra space for mobile toggle pill */
    }

    #editor-container .CodeMirror-scroll {
        padding-bottom: 120px; /* Extra space for mobile toggle pill */
    }

    .divider {
        display: none;
    }

    .mobile-toggle {
        display: flex;
        position: fixed;
        bottom: calc(20px + env(safe-area-inset-bottom));
        left: 50%;
        transform: translateX(-50%);
        background-color: rgba(26, 26, 26, 0.9);
        border-radius: 30px;
        padding: 5px;
        z-index: 100;
        backdrop-filter: blur(10px);
    }

    .toggle-button {
        padding: 8px 20px;
        border: none;
        background: transparent;
        color: #ccc;
        border-radius: 25px;
        cursor: pointer;
        font-weight: 500;
    }

    .toggle-button.active {
        background: #fff;
        color: #1a1a1a;
    }
}

/* Toast notifications */
#toast-container {
    position: fixed;
    top: 60px;
    right: 20px;
    z-index: 9999;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    background: white;
    color: var(--text-color);
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.3s ease, fadeOut 0.5s ease 2.5s forwards;
    border-left: 4px solid #007bff;
    margin-bottom: 10px;
}

.toast.success {
    border-left-color: #28a745;
}

.toast.warning {
    border-left-color: #ffc107;
}

.toast.error {
    border-left-color: #dc3545;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

/* Code block copy button */
#preview-content pre {
    position: relative;
}

#preview-content pre code {
    white-space: pre-wrap;
    word-wrap: break-word;
}

#preview-content .copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

#preview-content pre:hover .copy-btn {
    opacity: 1;
}

#preview-content .copy-btn:hover {
    background: white;
    border-color: #007bff;
}

/* Upgrade Banner in Popover */
.popover-upgrade-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background-color: #1a1a1a;
    border-radius: 6px;
    margin-top: 8px;
    text-decoration: none;
    transition: background-color 0.2s ease;
    cursor: pointer;
}

.popover-upgrade-banner:hover {
    background-color: #333;
}

.popover-upgrade-banner .upgrade-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.popover-upgrade-banner .upgrade-text {
    color: white;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
}

/* Upgrade Modal */
.upgrade-modal {
    max-width: 450px;
}

.upgrade-modal-body {
    margin-bottom: 20px;
}

.upgrade-description {
    font-size: 15px;
    color: #1a1a1a;
    margin-bottom: 16px;
    line-height: 1.5;
}

.upgrade-features {
    background-color: #f5f5f5;
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    border: 1px solid #e0e0e0;
}

.upgrade-feature {
    font-size: 14px;
    color: #1a1a1a;
    margin-bottom: 6px;
    font-weight: 500;
}

.upgrade-feature:last-child {
    margin-bottom: 0;
}

.upgrade-steps {
    font-size: 14px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 8px;
    margin-top: 16px;
}

.upgrade-steps-list {
    font-size: 14px;
    color: #1a1a1a;
    padding-left: 20px;
    margin: 0;
}

.upgrade-steps-list li {
    margin-bottom: 6px;
}

.upgrade-inline-link {
    color: #1a1a1a;
    text-decoration: underline;
    font-weight: 600;
}

.upgrade-inline-link:hover {
    color: #333;
}

.upgrade-modal-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.upgrade-modal-buttons .btn {
    flex: 1;
    min-width: 120px;
}

.upgrade-modal-buttons .btn-primary {
    background-color: #1a1a1a;
    color: white;
    text-decoration: none;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.upgrade-modal-buttons .btn-primary:hover {
    background-color: #333;
}

/* My Documents Modal */
.my-documents-modal-content {
    max-width: 650px;
    max-height: 75vh;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.my-documents-modal-content .modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.my-documents-modal-content .modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.documents-list {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    min-height: 350px;
    counter-reset: doc-counter;
}

.documents-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: #999;
    gap: 16px;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e0e0e0;
    border-top-color: #1a1a1a;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

.documents-empty {
    text-align: center;
    padding: 80px 20px;
    color: #999;
}

.documents-empty h3 {
    margin: 0 0 8px 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-color);
}

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

.document-item {
    position: relative;
    padding: 14px 20px 14px 52px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s;
    counter-increment: doc-counter;
}

.document-item::before {
    content: counter(doc-counter) ".";
    position: absolute;
    left: 20px;
    top: 14px;
    font-size: 13px;
    font-weight: 600;
    color: #ccc;
    min-width: 24px;
}

.document-item:hover {
    background-color: #fafafa;
}

.document-item:last-child {
    border-bottom: none;
}

.document-title {
    font-size: 14px;
    font-weight: 500;
    margin: 0 0 8px 0;
    color: var(--text-color);
    text-decoration: none;
    display: block;
    line-height: 1.4;
}

.document-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: #6B7280;
    line-height: 1.5;
}

.document-meta-item {
    white-space: nowrap;
}

.meta-dot {
    color: #D1D5DB;
    font-size: 10px;
    margin: 0 2px;
}

/* Expire Badge */
.expire-badge {
    display: inline-flex;
    align-items: center;
    background-color: #F3F4F6;
    color: #374151;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}

.expire-badge.soon {
    background-color: #FEF2F2;
    color: #B91C1C;
}

.expire-badge.expired {
    background-color: #FEE;
    color: #DC2626;
    font-weight: 600;
}

.expire-label {
    font-size: 10px;
    opacity: 0.65;
    margin-right: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

@media (max-width: 768px) {
    .my-documents-modal-content {
        max-width: 94%;
        max-height: 85vh;
    }

    .my-documents-modal-content .modal-header {
        padding: 16px 20px;
    }

    .documents-list {
        padding: 0;
        min-height: 250px;
    }

    .document-item {
        padding: 12px 20px 12px 48px;
    }

    .document-item::before {
        left: 20px;
        font-size: 12px;
        min-width: 20px;
    }

    .document-meta {
        gap: 8px;
        font-size: 11px;
    }

    .expire-badge {
        font-size: 10px;
        padding: 2px 6px;
    }

    .expire-label {
        font-size: 9px;
    }
}

/* Mobile Actions Menu */
.mobile-actions-menu {
    position: fixed;
    top: 50px; /* Below header */
    right: 10px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1001;
    min-width: 160px;
    overflow: hidden;
}

.mobile-action-btn {
    display: block;
    width: 100%;
    padding: 14px 16px;
    background: transparent;
    border: none;
    border-bottom: 1px solid #f0f0f0;
    text-align: left;
    font-size: 15px;
    color: var(--text-color);
    cursor: pointer;
    transition: background-color 0.2s;
}

.mobile-action-btn:last-child {
    border-bottom: none;
}

.mobile-action-btn:active {
    background-color: #f5f5f5;
}

.mobile-action-btn.danger {
    color: #dc2626;
}

.mobile-action-btn.danger:active {
    background-color: #fef2f2;
}

/* Mobile-only button */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }
}
