* {
    box-sizing: border-box;
}

:root {
    --bg: #f8f9fa;
    --surface: #ffffff;
    --surface-2: #f1f3f4;
    --text: #202124;
    --muted: #5f6368;
    --primary: #1a73e8;
    --primary-700: #1557b0;
    --border: #dadce0;
    --chip-bg: #e8f0fe;
    --danger: #d93025;
    --danger-text: #ffffff;
}

.dark {
    --bg: #0b0c0d;
    --surface: #0f1112;
    --surface-2: #171819;
    --text: #e6e6e6;
    --muted: #9aa0a6;
    --primary: #8ab4ff;
    --primary-700: #6d9eff;
    --border: #262626;
    --chip-bg: rgba(138, 180, 255, 0.08);
    --danger: #ff726f;
    --danger-text: #111111;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    transition: background 0.2s ease, color 0.2s ease;
}

.main-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.logo {
    font-size: 22px;
    font-weight: 500;
    color: var(--primary);
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.btn-blogger {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

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

.btn-blogger-secondary {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-blogger-secondary:hover {
    background: var(--surface-2);
}

.container-blogger {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

.container-blogger.editor-layout {
    display: flex;
    gap: 24px;
}

.main-content {
    flex: 1;
    background: var(--surface);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.post-header {
    padding: 24px 24px 16px;
    border-bottom: 1px solid #f1f3f4;
}

#title {
    border: none;
    outline: none;
    font-size: 32px;
    font-weight: 400;
    color: var(--text);
    width: 100%;
    padding: 0;
    background: transparent;
    font-family: inherit;
}

#title::placeholder {
    color: #9aa0a6;
}

.editor-container {
    padding: 0;
}

#editor {
    height: 600px;
}

.CodeMirror {
    border: none !important;
    font-size: 16px !important;
    line-height: 1.6 !important;
    font-family: 'Google Sans', sans-serif !important;
    padding: 24px !important;
    height: 600px !important;
    background: #ffffff !important;
    color: #202124 !important;
}

.editor-toolbar {
    border: none !important;
    background: #f8f9fa !important;
    border-bottom: 1px solid #dadce0 !important;
    padding: 12px 24px !important;
}

.editor-toolbar a {
    color: #5f6368 !important;
    border: none !important;
    border-radius: 4px !important;
    padding: 8px !important;
    margin: 0 2px !important;
}

.editor-toolbar a:hover {
    background: #e8f0fe !important;
    color: #1a73e8 !important;
}

.editor-toolbar a.active {
    background: var(--chip-bg) !important;
    color: var(--primary) !important;
}

.CodeMirror-fullscreen {
    position: fixed !important;
    top: 110px !important;
    left: 50% !important;
    right: auto !important;
    bottom: 0 !important;
    width: 716px !important;
    height: calc(100vh - 110px) !important;
    z-index: 9999 !important;
    background: #ffffff !important;
    padding: 0 !important;
    transform: translateX(-50%) !important;
}

.CodeMirror-fullscreen .CodeMirror-scroll {
    padding: 20px !important;
    margin: 0 !important;
}

.CodeMirror-fullscreen .CodeMirror-sizer {
    margin: 0 !important;
    padding: 0 !important;
}

.CodeMirror-fullscreen .CodeMirror-lines {
    padding: 0 !important;
}

.CodeMirror-sided.CodeMirror-fullscreen {
    width: 716px !important;
    left: calc(50% - 716px) !important;
    transform: none !important;
    box-sizing: border-box !important;
}

.CodeMirror-sided.CodeMirror-fullscreen .CodeMirror-scroll {
    padding: 20px !important;
    margin: 0 !important;
    box-sizing: border-box !important;
}

.editor-toolbar.fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    height: 50px !important;
    z-index: 10000 !important;
    background: var(--bg) !important;
    border-bottom: 1px solid var(--surface-2) !important;
}

.CodeMirror-fullscreen+.editor-preview-side {
    position: fixed !important;
    top: 110px !important;
    left: 50% !important;
    width: 716px !important;
    height: calc(100vh - 110px) !important;
    z-index: 9998 !important;
    background: #ffffff !important;
    color: #202124 !important;
    border-left: 1px solid #dadce0 !important;
    overflow-x: hidden !important;
    word-wrap: break-word !important;
    box-sizing: border-box !important;
    font-family: 'Google Sans', sans-serif !important;
    font-size: 16px !important;
    line-height: 1.6 !important;
    padding: 20px !important;
}

.CodeMirror-fullscreen+.editor-preview-side * {
    max-width: 100% !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
}

.CodeMirror-fullscreen+.editor-preview-side img,
.editor-preview img {
    display: block !important;
    margin: 20px auto !important;
    max-width: 100% !important;
    height: auto !important;
}

.CodeMirror-fullscreen+.editor-preview-side pre,
.CodeMirror-fullscreen+.editor-preview-side code {
    white-space: pre-wrap !important;
    word-break: break-all !important;
}

body:has(.CodeMirror-fullscreen) .main-header {
    display: none !important;
}

body:has(.CodeMirror-fullscreen) .sidebar-blogger {
    display: none !important;
}

body:has(.CodeMirror-fullscreen) .action-buttons {
    display: none !important;
}

body:has(.CodeMirror-fullscreen) #title {
    position: fixed !important;
    top: 50px !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    height: 60px !important;
    z-index: 10001 !important;
    background: var(--surface) !important;
    border: none !important;
    border-bottom: 1px solid var(--surface-2) !important;
    padding: 16px 24px !important;
    margin: 0 !important;
    font-size: 24px !important;
    display: block !important;
    box-sizing: border-box !important;
}

body:has(.CodeMirror-fullscreen) {
    overflow: hidden !important;
}

.editor-side-by-side .CodeMirror {
    width: 50% !important;
}

.editor-side-by-side .editor-preview {
    width: 50% !important;
}

.sidebar-blogger {
    width: 300px;
    background: var(--surface);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    padding: 24px;
    height: fit-content;
}

.sidebar-section {
    margin-bottom: 24px;
}

.sidebar-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 12px;
}

.form-control-blogger {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 12px;
    font-size: 14px;
    width: 100%;
    font-family: inherit;
    transition: border-color 0.2s;
    background: var(--surface);
    color: var(--text);
}

.form-control-blogger:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(138, 180, 255, 0.12);
}

.form-select-blogger {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 12px;
    font-size: 14px;
    width: 100%;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.form-select-blogger:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(138, 180, 255, 0.12);
}

.tag-selection {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.tag-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--muted);
}

.tag-checkbox input[type="checkbox"] {
    accent-color: var(--primary);
}

.form-control,
input,
textarea,
select {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.btn-danger {
    background: var(--danger);
    color: var(--danger-text);
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
}

.btn-danger:hover {
    filter: brightness(0.95);
}

.action-buttons {
    display: flex;
    gap: 12px;
    padding: 16px 24px;
    background: var(--bg);
    border-top: 1px solid var(--surface-2);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--border);
}

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

.username {
    font-weight: 500;
    margin: 0;
    font-size: 14px;
    color: var(--text);
}

.logout-btn {
    font-size: 12px;
    padding: 4px 8px;
    margin-top: 4px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--muted);
    cursor: pointer;
}

.logout-btn:hover {
    background: var(--bg);
}

#imageUpload {
    display: none;
}

.editor-preview {
    font-family: 'Google Sans', sans-serif !important;
    line-height: 1.6 !important;
    padding: 24px !important;
    background: #ffffff !important;
    color: #202124 !important;
}

@media (max-width: 768px) {
    .container-blogger.editor-layout {
        flex-direction: column;
        padding: 16px;
    }

    .sidebar-blogger {
        width: 100%;
        order: -1;
    }

    .main-header {
        padding: 12px 16px;
    }
}

.custom-toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 10002;
}

.custom-toast {
    background: var(--surface);
    color: var(--text);
    padding: 12px 24px;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
    transition: opacity 0.3s ease, transform 0.3s ease;
    border-left: 4px solid var(--primary);
    min-width: 300px;
    opacity: 1;
}

.custom-toast.success {
    border-left-color: #0f9d58;
}

.custom-toast.error {
    border-left-color: var(--danger);
}

.custom-toast.info {
    border-left-color: var(--primary);
}

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

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.modal {
    display: none;
    position: fixed;
    z-index: 10003;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--surface);
    margin: 5% auto;
    padding: 24px;
    border: 1px solid var(--border);
    width: 80%;
    max-width: 1000px;
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    position: relative;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.close-modal {
    color: var(--text-secondary);
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    right: 20px;
    top: 10px;
    cursor: pointer;
    transition: color 0.2s;
}

.close-modal:hover,
.close-modal:focus {
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
}

.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
    margin-top: 20px;
    overflow-y: auto;
    padding-right: 8px;
}

.media-item {
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    background: var(--bg);
    aspect-ratio: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.media-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: var(--primary);
}

.media-item img {
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
    width: 100%;
    height: 100%;
}

.media-item-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 12px;
    padding: 4px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    transition: opacity 0.2s;
}

.media-item:hover .media-item-name {
    opacity: 1;
}

.media-loading {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}