/** CSS Variables & Base Setup **/
:root {
    --primary-color: #4F46E5;
    --primary-hover: #4338CA;
    --bg-color: #F3F4F6;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --border-color: #E5E7EB;
    --surface-color: #FFFFFF;
    --danger: #DC2626;
    --ok: #059669;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
}

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

html, body {
    height: 100%;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

button, input {
    font-family: inherit;
}

/** Auth **/
.auth-screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background:
        radial-gradient(circle at top left, rgba(79, 70, 229, 0.18), transparent 32%),
        radial-gradient(circle at bottom right, rgba(14, 165, 233, 0.16), transparent 28%),
        rgba(243, 244, 246, 0.96);
}

.auth-screen[hidden] {
    display: none;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 1.25rem;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--primary-color);
    font-weight: 700;
    margin-bottom: 1.25rem;
}

.auth-card h1 {
    font-size: 1.5rem;
    letter-spacing: -0.03em;
    margin-bottom: 0.4rem;
}

.auth-subtitle {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.auth-card label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.auth-card input {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 0.8rem 0.9rem;
    font-size: 1rem;
    margin-bottom: 1rem;
    outline: none;
    background: #FAFAFA;
}

.auth-card input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12);
    background: white;
}

.auth-error {
    color: var(--danger);
    font-size: 0.9rem;
    margin-bottom: 0.9rem;
}

.auth-card button[type="submit"] {
    width: 100%;
    border: 0;
    background: var(--primary-color);
    color: white;
    font-weight: 600;
    padding: 0.9rem;
    border-radius: 0.75rem;
    cursor: pointer;
}

.auth-card button[type="submit"]:hover {
    background: var(--primary-hover);
}

.auth-card button[type="submit"]:disabled {
    opacity: 0.65;
    cursor: wait;
}

/** Layout **/
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.app-container[hidden] {
    display: none;
}

body:has(#auth-screen:not([hidden])) .app-container {
    pointer-events: none;
    user-select: none;
}

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary-color);
    min-width: 0;
}

.logo h1 {
    font-size: 1.1rem;
    font-weight: 650;
    color: var(--text-primary);
    letter-spacing: -0.025em;
}

.save-status {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.save-status.saved {
    color: var(--ok);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.status {
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
}

.status::before {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #D1D5DB;
}

.status.connected {
    color: var(--text-primary);
}

.status.connected::before {
    background-color: #10B981;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.status.reconnecting::before {
    background-color: #F59E0B;
}

.active-users {
    display: flex;
    align-items: center;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
    border: 2px solid var(--surface-color);
    margin-left: -8px;
    transition: transform 0.2s;
    user-select: none;
    position: relative;
}

.user-avatar:hover {
    transform: translateY(-2px);
    z-index: 10;
}

.user-avatar:hover::after {
    content: attr(title);
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: #374151;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
}

.user-avatar:first-child {
    margin-left: 0;
}

.ghost-btn {
    border: 1px solid var(--border-color);
    background: white;
    color: var(--text-primary);
    border-radius: 999px;
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

.ghost-btn:hover {
    background: #F9FAFB;
}

.editor-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1.25rem 1.5rem 1.5rem;
    overflow: hidden;
    position: relative;
    min-height: 0;
}

#editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.ql-toolbar.ql-snow {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
    padding: 0.65rem 0.85rem;
    font-family: 'Inter', sans-serif;
    flex-shrink: 0;
}

.ql-container.ql-snow {
    flex: 1;
    min-height: 0;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-top: none;
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
    font-family: inherit;
    font-size: 1.05rem;
    box-shadow: var(--shadow-sm);
    overflow-y: auto;
}

.ql-editor {
    padding: 1.75rem 2.25rem 3rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.ql-editor.ql-blank::before {
    color: #9CA3AF;
    font-style: normal;
}

.ql-editor p {
    margin-bottom: 0.75rem;
}

.ql-editor img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    margin: 1rem 0;
}

.ql-snow .ql-attachment {
    width: 28px;
}

.ql-snow .ql-attachment::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    vertical-align: middle;
    background-color: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48'/%3E%3C/svg%3E") center / contain no-repeat;
}

.ql-attachment-card {
    margin: 0.85rem 0;
}

.file-card {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    border: 1px solid var(--border-color);
    background: #F9FAFB;
    border-radius: 0.85rem;
    padding: 0.85rem 1rem;
    max-width: 520px;
}

.file-card video,
.file-card audio {
    width: 100%;
    border-radius: 0.6rem;
    background: #111827;
}

.file-card-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.file-card-meta {
    min-width: 0;
}

.file-card-meta strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-card-meta span {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.file-card a {
    flex-shrink: 0;
    background: var(--primary-color);
    color: white !important;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.45rem 0.8rem;
    border-radius: 999px;
}

.progress-track {
    width: min(320px, 80%);
    height: 8px;
    background: var(--border-color);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 0.85rem;
}

.progress-bar {
    height: 100%;
    width: 0;
    background: var(--primary-color);
    transition: width 0.15s linear;
}

.upload-percent {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.upload-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 50;
}

.upload-overlay.active {
    display: flex;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

.ql-cursor-name {
    font-family: 'Inter', sans-serif !important;
    font-size: 11px !important;
    font-weight: 500 !important;
    padding: 2px 6px !important;
    border-radius: 4px !important;
    box-shadow: var(--shadow-sm);
}

.toast {
    position: fixed;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    background: #111827;
    color: white;
    padding: 0.7rem 1rem;
    border-radius: 999px;
    font-size: 0.9rem;
    z-index: 80;
    box-shadow: var(--shadow-lg);
}

.toast[hidden] {
    display: none;
}

@media (max-width: 720px) {
    .navbar {
        align-items: flex-start;
        flex-direction: column;
        padding: 0.85rem 1rem;
    }

    .user-info {
        width: 100%;
        justify-content: space-between;
    }

    .editor-wrapper {
        padding: 0.75rem;
    }

    .ql-editor {
        padding: 1.1rem 1rem 2.5rem;
    }

    .ql-toolbar.ql-snow {
        overflow-x: auto;
        white-space: nowrap;
    }
}
