@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap");

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-2: #22263a;
    --border: #2e3248;
    --text: #e8eaf0;
    --muted: #6b7280;
    --primary: #6c8fff;
    --primary-hover: #5a7aff;
    --danger: #ff5c6c;
    --danger-hover: #e84a5a;
    --success: #4ade80;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --radius: 12px;
}

html {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

body {
    margin: 0;
    padding: 0;
    width: 100%;
    font-family: "DM Sans", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    overflow-x: hidden;
}

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

::-webkit-scrollbar {
    width: 7px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

/* LOGIN */
.container {
    min-height: 100dvh;
    width: 100%;
    max-width: 100vw;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 60% 40%, #1a2040 0%, var(--bg) 70%);
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 40px 36px;
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.card img {
    margin-bottom: 8px;
    filter: drop-shadow(0 0 16px rgba(108, 143, 255, 0.3));
}

.card h2 {
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

/* INPUTS */
input,
textarea {
    width: 100%;
    padding: 11px 14px;
    margin: 5px 0;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    font-size: 14px;
    transition: border-color 0.2s;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
}

input::placeholder,
textarea::placeholder {
    color: var(--muted);
}

textarea {
    min-height: 260px;
    resize: vertical;
    font-family: "DM Mono", monospace;
    font-size: 13px;
    line-height: 1.6;
}

/* BUTTONS */
button {
    padding: 10px 18px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    transition:
        background 0.2s,
        transform 0.1s;
    width: 100%;
}

button:hover {
    background: var(--primary-hover);
}
button:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover {
    background: var(--border);
}

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

.btn-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-shrink: 0;
}
.btn-row button {
    width: auto;
    flex: 1;
}

.small-btn {
    width: auto;
    padding: 6px 14px;
    font-size: 13px;
}

/* MAIN */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}

/* TOPBAR */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.topbar-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.topbar .meta {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

.topbar .btn-danger {
    width: auto;
    padding: 8px 16px;
    font-size: 13px;
}

/* TABLE / DOCS GRID */
.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.table-header h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 12px;
}

.table-header button {
    width: auto;
    padding: 8px 16px;
    font-size: 13px;
}

/* Grid Layout */
.docs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

/* Document Card */
.doc-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    transition: all 0.2s;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.doc-card:hover {
    border-color: var(--primary);
    box-shadow: 0 8px 24px rgba(108, 143, 255, 0.15);
    transform: translateY(-2px);
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.char-count {
    font-size: 12px;
    color: var(--muted);
    background: var(--surface-2);
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
}

.card-preview {
    flex: 1;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.5;
    margin-bottom: 12px;
    min-height: 65px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-preview em {
    color: var(--muted);
    opacity: 0.6;
}

.card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.author {
    font-weight: 500;
}

.date {
    font-size: 11px;
}

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

.card-actions button {
    flex: 1;
    padding: 8px 12px;
    font-size: 12px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
}

.empty-state p {
    margin: 0 0 8px;
    font-size: 16px;
}

.empty-state .hint {
    font-size: 13px;
    color: var(--muted);
    opacity: 0.7;
}

/* EDITOR */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.editor-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 160px);
    max-height: calc(100vh - 160px);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-shrink: 0;
}

.panel-header strong {
    font-size: 15px;
    font-weight: 600;
}

.editable-title {
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.editable-title::after {
    content: "✎";
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s;
    color: var(--primary);
}

.editable-title:hover {
    background: var(--surface-2);
    color: var(--primary);
}

.editable-title:hover::after {
    opacity: 1;
}

.title-input {
    font-size: 15px;
    font-weight: 600;
    padding: 6px 10px;
    background: var(--surface-2);
    border: 2px solid var(--primary);
    border-radius: 6px;
    color: var(--text);
    font-family: inherit;
    flex: 1;
    min-width: 150px;
}

.title-input:focus {
    outline: none;
    border-color: var(--primary-hover);
    box-shadow: 0 0 0 3px rgba(108, 143, 255, 0.15);
}

.panel-header-actions {
    display: flex;
    gap: 8px;
}

.panel-header-actions button {
    width: auto;
    padding: 7px 14px;
    font-size: 13px;
}

/* Mobile Tabs (Hidden on Desktop) */
.mobile-tabs {
    display: none;
    gap: 8px;
    margin-bottom: 12px;
}

.tab {
    flex: 1;
    padding: 8px 12px;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--text);
    border-color: var(--primary);
}

.tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Split Editor Layout */
.split-editor {
    display: grid;
    gap: 16px;
    flex: 1;
    min-height: 0;
    margin-bottom: 12px;
    overflow: hidden;
    height: 100%;
    position: relative;
}

.split-editor.with-cheatsheet {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(260px, 0.9fr);
}

.split-editor.without-cheatsheet {
    grid-template-columns: 1fr 1fr;
}

.editor-section,
.preview-section,
.cheatsheet-section {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.editor-section {
    padding: 0;
}

.editor-section textarea {
    flex: 1;
    width: 100%;
    border: none;
    resize: none;
    margin: 0 !important;
    padding: 12px;
    background: var(--surface-2);
    color: var(--text);
    font-family: "DM Mono", monospace;
    font-size: 13px;
    line-height: 1.6;
    overflow-y: scroll;
    overflow-x: auto;
    border-radius: 8px;
}

.editor-section textarea:focus {
    outline: none;
}

.preview-section {
    padding: 0;
}

.split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-top: 14px;
}

.rendered {
    flex: 1;
    width: 100%;
    height: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    color: var(--text);
    font-size: 14px;
    line-height: 1.7;
    overflow-y: scroll;
    overflow-x: hidden;
    box-sizing: border-box;
}

.rendered h1 {
    font-size: 20px;
    margin-bottom: 10px;
}
.rendered h2 {
    font-size: 17px;
    margin: 14px 0 8px;
}
.rendered p {
    margin: 8px 0;
}

.rendered ul,
.rendered ol {
    margin: 10px 0 10px 20px;
    padding-left: 10px;
}

.rendered ul {
    list-style: disc;
}

.rendered ol {
    list-style: decimal;
}

.rendered li {
    margin: 4px 0;
}

.rendered .olist,
.rendered .ulist {
    margin: 10px 0;
}

.rendered .olist > ol {
    margin: 10px 0 10px 20px;
    padding-left: 10px;
}

.rendered li ul,
.rendered li ol {
    margin-top: 4px;
}

.rendered code {
    font-family: "DM Mono", monospace;
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

/* Cheatsheet Panel */
.cheatsheet-section {
    padding: 0;
}

.cheatsheet-content {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.command-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.command-group h4 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.08em;
    margin: 0;
    margin-bottom: 2px;
}

.cmd-btn {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 11px;
    border-radius: 6px;
    font-size: 12px;
    line-height: 1.35;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    font-family: "DM Mono", monospace;
    white-space: normal;
}

.cmd-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateX(1px);
}

.cheatsheet-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 0;
    border-bottom: 1px solid var(--border);
    padding: 12px 14px;
}

.cheatsheet-header h3 {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
}

.error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 8px;
}
.hint {
    font-size: 12px;
    color: var(--muted);
    margin-top: 6px;
}

/* TITLE MODAL */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow), 0 20px 60px rgba(0, 0, 0, 0.5);
    padding: 28px 32px;
    width: 90%;
    max-width: 420px;
    animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

.modal-input {
    width: 100%;
    padding: 11px 14px;
    margin-bottom: 20px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    font-size: 14px;
    transition: border-color 0.2s;
}

.modal-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(108, 143, 255, 0.1);
}

.modal-input::placeholder {
    color: var(--muted);
}

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

.modal-buttons button {
    flex: 1;
    padding: 10px 16px;
    font-size: 14px;
    border-radius: 8px;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

@media (max-width: 900px) {
    .mobile-tabs {
        display: flex;
    }

    .split-editor {
        grid-template-columns: 1fr;
        gap: 0;
        height: 100%;
    }

    .editor-section,
    .preview-section,
    .cheatsheet-section {
        display: none;
    }

    .editor-section.active,
    .preview-section.active,
    .cheatsheet-section.active {
        display: flex;
        height: 100%;
        min-height: 0;
    }

    .rendered {
        height: 100%;
        min-height: unset;
    }

    .docs-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }
}

/* Desktop: Show cheatsheet as third column only when tabs not active */
@media (min-width: 901px) {
    .cheatsheet-section {
        display: flex !important;
    }
    
    .cheatsheet-section.active {
        display: flex;
    }
}

@media (max-width: 700px) {
    .docs-grid {
        grid-template-columns: 1fr;
    }
    
    .doc-card {
        padding: 16px;
    }
    
    .card-header h3 {
        font-size: 15px;
    }
    
    .split {
        grid-template-columns: 1fr;
    }
}
