:root {
    --bg: #f3f6f9;
    --surface: #ffffff;
    --surface-alt: #eef2f6;
    --text: #0f172a;
    --muted: #475569;
    --border: #cbd5e1;
    --primary: #0b7285;
    --primary-hover: #0a5f6f;
    --danger: #b91c1c;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    font-family: "Segoe UI", "Trebuchet MS", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top right, #d7f3f5 0%, transparent 40%),
        radial-gradient(circle at bottom left, #fce6d3 0%, transparent 45%),
        var(--bg);
}

a {
    color: inherit;
}

.muted {
    color: var(--muted);
    margin-top: 0;
}

.hint {
    color: var(--muted);
    font-size: 0.9rem;
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(420px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.1);
}

.login-card h1 {
    margin: 0 0 8px;
}

.login-form {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.login-form input,
.login-form button {
    border-radius: 10px;
    border: 1px solid var(--border);
    font: inherit;
    padding: 10px 12px;
}

.login-form button {
    margin-top: 6px;
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    cursor: pointer;
}

.login-form button:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.error-message {
    background: #fee2e2;
    border: 1px solid #fecaca;
    color: var(--danger);
    border-radius: 10px;
    padding: 10px;
    margin: 12px 0;
}

.app-body {
    height: 100vh;
    display: grid;
    grid-template-rows: auto auto 1fr;
    overflow: hidden;
}

.reference-body {
    grid-template-rows: auto 1fr;
}

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

.brand {
    font-size: 1.1rem;
    font-weight: 700;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

button,
select,
input[type="color"] {
    font: inherit;
}

button,
.logout-link {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 8px;
    padding: 8px 10px;
    text-decoration: none;
    cursor: pointer;
}

button:hover,
.logout-link:hover {
    border-color: #94a3b8;
    background: #f8fafc;
}

#btnImport,
#btnSave,
#btnExport,
#btnDeleteCurrent,
#btnOpenTrash,
#btnToggleView,
#btnSplitView,
#btnFormatDoc,
#btnUndoEdit,
.logout-link {
    background: #fff;
}

#btnDeleteCurrent {
    border-color: #fca5a5;
    color: #7f1d1d;
    background: #fff5f5;
}

button.is-active {
    background: #d6f5f8;
    border-color: #7fcdd5;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
    padding: 10px 16px;
}

.tool-label {
    font-size: 0.9rem;
    color: var(--muted);
}

#textColor {
    width: 40px;
    height: 35px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2px;
}

.layout {
    min-height: 0;
    height: 100%;
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 12px;
    padding: 12px;
    overflow: hidden;
}

.files-panel,
.editor-panel {
    min-height: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.files-panel {
    display: grid;
    grid-template-rows: auto 1fr;
    padding: 12px;
    gap: 10px;
    overflow: hidden;
}

.files-panel .hint code {
    white-space: normal;
    overflow-wrap: anywhere;
}

.files-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.files-header h2 {
    font-size: 1rem;
    margin: 0;
}

.files-header #btnRefreshFiles {
    width: 100%;
    text-align: center;
}

.file-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
    display: grid;
    grid-auto-rows: max-content;
    align-content: start;
    align-items: start;
    gap: 8px;
}

.file-list button {
    width: 100%;
    text-align: left;
    background: #f8fafc;
}

.doc-item {
    min-width: 0;
    border: 1px solid #dbe6ef;
    border-radius: 10px;
    padding: 8px;
    background: #f8fafc;
}

.doc-main-btn {
    font-weight: 600;
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
}

.doc-current-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 6px;
}

.doc-version-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
    align-items: start;
}

.doc-delete-btn {
    font-size: 0.78rem;
    border-color: #fca5a5;
    color: #7f1d1d;
    background: #fff5f5;
}

.doc-meta {
    margin: 6px 0;
    font-size: 0.82rem;
    color: var(--muted);
}

.doc-versions summary {
    cursor: pointer;
    font-size: 0.85rem;
    color: #334155;
    margin-bottom: 6px;
    white-space: normal;
    overflow-wrap: anywhere;
}

.doc-version-list {
    display: grid;
    gap: 6px;
}

.doc-version-btn {
    font-size: 0.82rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.editor-panel {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    overflow: hidden;
}

#markdownEditor,
.markdown-preview {
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
    border-radius: 12px;
    padding: 16px;
    overflow: auto;
    grid-column: 1;
    grid-row: 1;
}

#markdownEditor {
    resize: none;
    font-family: Consolas, "Courier New", monospace;
    font-size: 15px;
    line-height: 1.5;
    outline: none;
}

.markdown-preview {
    overflow: auto;
    line-height: 1.6;
    background: #fff;
}

.markdown-preview img {
    max-width: 100%;
    height: auto;
}

.markdown-preview .emoji-inline {
    width: 1.15em;
    height: 1.15em;
    max-width: none;
    vertical-align: -0.2em;
}

.markdown-preview pre {
    background: #0f172a;
    color: #f8fafc;
    padding: 12px;
    border-radius: 8px;
    overflow: auto;
}

.markdown-preview code {
    background: #e2e8f0;
    padding: 2px 4px;
    border-radius: 4px;
}

.markdown-preview pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
    color: inherit;
}

.markdown-preview .code-block {
    margin: 12px 0;
    border: 1px solid #1e293b;
    border-radius: 10px;
    overflow: hidden;
    background: #0f172a;
}

.markdown-preview .code-block-title {
    margin: 0;
    padding: 8px 12px;
    border-bottom: 1px solid #27354c;
    background: #111b2f;
    color: #e2e8f0;
    font-size: 0.82rem;
    font-family: Consolas, "Courier New", monospace;
}

.markdown-preview .code-block pre {
    margin: 0;
    border-radius: 0;
    border: 0;
}

.markdown-preview .code-block code {
    display: block;
}

.markdown-preview .code-line {
    display: block;
    padding: 0 4px;
    margin: 0 -4px;
}

.markdown-preview .code-line.is-highlight {
    background: rgba(59, 130, 246, 0.18);
}

.markdown-preview .code-line.is-ins {
    background: rgba(22, 163, 74, 0.2);
}

.markdown-preview .code-line.is-del {
    background: rgba(220, 38, 38, 0.2);
}

.markdown-preview .code-text-mark {
    border-radius: 4px;
    padding: 0 2px;
}

.markdown-preview .code-text-highlight {
    background: rgba(250, 204, 21, 0.45);
    color: #f8fafc;
}

.markdown-preview .code-text-ins {
    background: rgba(22, 163, 74, 0.55);
    color: #f8fafc;
}

.markdown-preview .code-text-del {
    background: rgba(220, 38, 38, 0.55);
    color: #f8fafc;
}

.markdown-preview table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.markdown-preview th,
.markdown-preview td {
    border: 1px solid #cbd5e1;
    padding: 8px 10px;
    text-align: left;
}

.markdown-preview thead th {
    background: #eef2f6;
}

.markdown-preview hr {
    border: 0;
    border-top: 1px solid #cbd5e1;
    margin: 14px 0;
}

.editor-panel.is-split {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr auto;
    gap: 8px;
    padding: 8px;
}

.editor-panel.is-split #markdownEditor {
    grid-column: 1;
}

.editor-panel.is-split .markdown-preview {
    grid-column: 2;
}

.editor-stats {
    grid-column: 1 / -1;
    grid-row: 2;
    border-top: 1px solid var(--border);
    background: #f8fafc;
    color: var(--muted);
    font-size: 0.82rem;
    padding: 8px 12px;
}

.is-hidden {
    display: none;
}

.status-message {
    position: fixed;
    right: 16px;
    bottom: 16px;
    max-width: min(420px, calc(100vw - 32px));
    padding: 10px 12px;
    background: #0f172a;
    color: #fff;
    border-radius: 8px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

.status-message.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.status-message.error {
    background: #7f1d1d;
}

.modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(15, 23, 42, 0.5);
    z-index: 80;
}

.modal.is-hidden {
    display: none;
}

.modal-panel {
    width: min(860px, 100%);
    max-height: calc(100vh - 40px);
    overflow: auto;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
}

.modal-panel-confirm {
    width: min(520px, 100%);
}

.confirm-modal-message {
    margin: 10px 0 0;
    line-height: 1.45;
}

.confirm-modal-actions {
    justify-content: flex-end;
    gap: 8px;
}

.confirm-delete-btn {
    border-color: #fca5a5;
    color: #7f1d1d;
    background: #fff5f5;
}

.confirm-delete-btn:hover {
    border-color: #ef4444;
    background: #fee2e2;
}

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

.modal-header h3 {
    margin: 0;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 10px;
}

.syntax-issue-list {
    list-style: none;
    margin: 10px 0 0;
    padding: 0;
    display: grid;
    gap: 10px;
}

.syntax-issue {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    background: #f8fafc;
}

.syntax-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.syntax-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
}

.syntax-issue p {
    margin: 0 0 8px;
}

.syntax-issue-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.syntax-severity-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.72rem;
    border: 1px solid transparent;
}

.syntax-severity-error {
    background: #fee2e2;
    color: #7f1d1d;
    border-color: #fca5a5;
}

.syntax-severity-warning {
    background: #fef3c7;
    color: #78350f;
    border-color: #fcd34d;
}

.syntax-severity-suggestion {
    background: #dbeafe;
    color: #1e3a8a;
    border-color: #93c5fd;
}

.syntax-issue-error {
    border-color: #fecaca;
    background: #fff8f8;
}

.syntax-issue-warning {
    border-color: #fde68a;
    background: #fffbeb;
}

.syntax-issue-suggestion {
    border-color: #bfdbfe;
    background: #f8fbff;
}

.syntax-diff-label {
    margin: 0 0 4px;
    font-size: 0.8rem;
    color: #334155;
}

.syntax-diff {
    margin: 0 0 8px;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid #dbe6ef;
    background: #ffffff;
    white-space: pre-wrap;
    word-break: break-word;
}

.syntax-diff-before {
    background: #fff1f2;
    border-color: #fecdd3;
}

.syntax-diff-after {
    background: #ecfdf5;
    border-color: #a7f3d0;
}

.syntax-issue code {
    display: inline-block;
    max-width: 100%;
    overflow: auto;
    padding: 4px 6px;
    border-radius: 6px;
    background: #e2e8f0;
}

.syntax-issue-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.trash-list {
    list-style: none;
    margin: 10px 0 0;
    padding: 0;
    display: grid;
    gap: 10px;
    max-height: 52vh;
    overflow: auto;
}

.trash-section-title {
    margin: 10px 0 6px;
    font-size: 0.95rem;
}

.trash-item {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    background: #f8fafc;
}

.trash-item-title {
    margin: 0 0 6px;
    font-weight: 600;
}

.trash-item-meta {
    margin: 0 0 8px;
    font-size: 0.84rem;
    color: var(--muted);
    white-space: normal;
    overflow-wrap: anywhere;
}

.trash-item-actions {
    display: flex;
    justify-content: flex-end;
}

#emojiSearch {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.emoji-grid {
    display: block;
    max-height: 56vh;
    overflow: auto;
}

.emoji-theme {
    margin: 0 0 12px;
}

.emoji-theme-title {
    margin: 0 0 8px;
    font-size: 0.9rem;
    color: #0f172a;
}

.emoji-grid-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
    gap: 8px;
}

.emoji-grid-list.is-shortcode-mode {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.emoji-btn {
    min-height: 52px;
    padding: 6px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    line-height: 1.2;
    text-align: center;
}

.emoji-btn:hover {
    background: #ffffff;
}

.emoji-btn.is-shortcode {
    min-height: 46px;
    padding: 4px 6px;
}

.emoji-btn.has-preview {
    min-height: 58px;
}

.emoji-preview {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.emoji-label {
    font-size: 11px;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-open {
    overflow: hidden;
}

.reference-layout {
    min-height: 0;
    overflow: auto;
    padding: 14px;
    display: grid;
    gap: 14px;
}

.reference-card {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
}

.reference-header h1 {
    margin: 0 0 6px;
    font-size: 1.2rem;
}

.reference-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: 10px 0 12px;
}

.reference-tools input,
.reference-tools select {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    min-width: 200px;
}

.syntax-grid {
    display: grid;
    gap: 10px;
}

.syntax-card {
    border: 1px solid #d8e2ec;
    border-radius: 10px;
    padding: 10px;
    background: #f8fafc;
}

.syntax-title-row {
    display: flex;
    gap: 10px;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.syntax-title-row h2 {
    margin: 0;
    font-size: 1rem;
}

.syntax-support {
    border-radius: 999px;
    padding: 4px 10px;
    border: 1px solid #cbd5e1;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    background: #e2e8f0;
}

.syntax-support-yes {
    background: #dcfce7;
    border-color: #86efac;
    color: #14532d;
}

.syntax-support-partial {
    background: #fef3c7;
    border-color: #fcd34d;
    color: #78350f;
}

.syntax-support-no {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #7f1d1d;
}

.syntax-examples {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.syntax-examples h3 {
    margin: 0 0 6px;
    font-size: 0.9rem;
}

.syntax-examples pre {
    margin: 0;
    overflow: auto;
    border: 1px solid #dbe6ef;
    border-radius: 8px;
    background: #ffffff;
    padding: 8px;
}

.syntax-result-frame {
    width: 100%;
    min-height: 120px;
    border: 1px solid #dbe6ef;
    border-radius: 8px;
    background: #ffffff;
}

.icon-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.icon-summary-chip {
    display: inline-flex;
    align-items: center;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    background: #eef2f6;
    padding: 4px 10px;
    font-size: 0.8rem;
    color: #334155;
}

.reference-icons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
    max-height: 58vh;
    overflow: auto;
}

.icon-tile {
    min-height: 86px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    border: 1px solid #d8e2ec;
    border-radius: 10px;
    background: #f8fafc;
    text-align: center;
    padding: 8px;
}

.icon-tile img {
    width: 22px;
    height: 22px;
    object-fit: contain;
}

.icon-tile span {
    font-size: 0.82rem;
    font-family: Consolas, "Courier New", monospace;
}

.icon-tile small {
    color: #64748b;
    font-size: 0.74rem;
}

.error-message-inline {
    color: #7f1d1d;
}

@media (max-width: 1024px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .files-panel {
        min-height: 180px;
        max-height: 260px;
    }

    #markdownEditor,
    .markdown-preview {
        min-height: 0;
    }

    .editor-panel.is-split {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr auto;
    }

    .editor-panel.is-split #markdownEditor {
        grid-column: 1;
        grid-row: 1;
    }

    .editor-panel.is-split .markdown-preview {
        grid-column: 1;
        grid-row: 2;
    }

    .editor-panel.is-split .editor-stats {
        grid-row: 3;
    }
}

@media (max-width: 680px) {
    .topbar,
    .toolbar {
        padding: 10px;
    }

    .brand {
        width: 100%;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar-actions {
        width: 100%;
    }

    .topbar-actions > * {
        flex: 1;
        text-align: center;
    }

    .modal {
        padding: 10px;
    }

    .modal-panel {
        max-height: calc(100vh - 20px);
        padding: 10px;
    }

    .reference-tools input,
    .reference-tools select {
        min-width: 0;
        width: 100%;
    }

    .syntax-examples {
        grid-template-columns: 1fr;
    }

    .reference-icons-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        max-height: 52vh;
    }

    .syntax-toolbar {
        align-items: stretch;
    }

    .syntax-toolbar select {
        width: 100%;
    }

    .syntax-actions > button {
        width: 100%;
        text-align: center;
    }

    .doc-current-actions {
        justify-content: stretch;
    }

    .doc-current-actions .doc-delete-btn {
        width: 100%;
        text-align: center;
        white-space: normal;
    }

    .doc-version-row {
        grid-template-columns: 1fr;
    }

    .doc-version-row .doc-delete-btn {
        width: 100%;
        text-align: center;
    }
}
