@font-face {
    font-family: 'Idiqlat';
    src: url('Idiqlat-Regular.woff2') format('woff');
    font-weight: normal;
    font-style: normal;
}

:root {
    --primary: #f44242;
    --bg-gray: #F0F2F5;
    --border-color: #dadce0;
    --text-color: #202124;
    --icon-color: #5f6368;
    --a4-height: 1123px;
    /* Approx A4 height at 96dpi */
    --a4-width: 794px;
}

body {
    margin: 0;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-gray);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- DASHBOARD VIEW --- */
#dashboard-view {
    padding: 40px;
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    box-sizing: border-box;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.doc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    padding-bottom: 40px;
}

.doc-card,
.new-doc-card {
    border-radius: 8px;
    height: 250px;
    cursor: pointer;
    position: relative;
    background: white;
    transition: box-shadow 0.2s, transform 0.1s;
}

.new-doc-card {
    border: 2px dashed var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
}

.new-doc-card:hover {
    border-color: var(--primary);
    background: rgba(66, 133, 244, 0.05);
}

.doc-card {
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.doc-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.doc-preview {
    flex: 1;
    padding: 20px;
    font-size: 18px;
    overflow: hidden;
    color: #888;
    border-bottom: 1px solid #f1f1f1;
    direction: rtl;
    text-align: right;
    font-family: 'Idiqlat', sans-serif;
    background: white;
    border-radius: 8px 8px 0 0;
}

.doc-info {
    padding: 12px;
    background: white;
    border-radius: 0 0 8px 8px;
}

.doc-title {
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-date {
    font-size: 12px;
    color: #888;
}

.delete-btn {
    position: absolute;
    bottom: 10px;
    right: 10px;
    color: #d93025;
    background: white;
    border: 1px solid #dadce0;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.doc-card:hover .delete-btn {
    opacity: 1;
}

/* --- EDITOR VIEW --- */
#editor-view {
    display: none;
    flex-direction: column;
    height: 100%;
}

/* Toolbar */
.toolbar {
    background: white;
    height: 48px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    gap: 15px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    z-index: 20;
    flex-shrink: 0;
}

.subtoolbar {
    background: rgb(240, 244, 249);
    height: 36px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 5px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    z-index: 19;
    flex-shrink: 0;
}

.doc-title-input {
    border: none;
    font-size: 18px;
    padding: 4px 8px;
    border-radius: 4px;
    color: var(--text-color);
    width: 200px;
}

.doc-title-input:hover {
    background-color: #f1f3f4;
    border: 1px solid transparent;
}

.doc-title-input:focus {
    outline: 2px solid var(--primary);
    background: white;
}

/* Custom Tooltip Button */
.tool-btn {
    background: none;
    border: none;
    border-radius: 4px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--icon-color);
    position: relative;
    transition: background 0.1s;
}

.tool-btn:hover {
    background-color: rgba(0, 0, 0, 0.08);
    color: #202124;
}

.tool-btn.active {
    background-color: #e8f0fe;
    color: var(--primary);
}

.tool-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Tooltip CSS */
.tool-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: #202124;
    color: white;
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 9999;
}

.tool-btn:hover::after {
    opacity: 1;
    transition-delay: 0.5s;
}

.separator {
    width: 1px;
    height: 24px;
    background: #dadce0;
    margin: 0 4px;
}

.spacer {
    flex: 1;
}

.save-status {
    font-size: 12px;
    color: #888;
    margin-left: 10px;
    margin-right: auto;
    min-width: 60px;
}

/* Editor Area */
.editor-container {
    flex: 1;
    overflow-y: scroll;
    background-color: #edeff1;
    padding: 20px 0;
    display: flex;
    justify-content: center;
    scroll-behavior: smooth;
}

/* Visual Page Representation */
.page-bg {
    /* This gradient creates the visual "gap" between pages */
    background-image: linear-gradient(to bottom,
            white 0px,
            white calc(var(--a4-height) - 1px),
            #edeff1 calc(var(--a4-height) - 1px),
            #edeff1 calc(var(--a4-height) + 10px));
    background-size: 100% calc(var(--a4-height) + 10px);
    background-repeat: repeat-y;

    width: var(--a4-width);
    min-height: var(--a4-height);
    box-shadow: 0 1px 3px 0 rgba(60, 64, 67, 0.3);
    margin-bottom: 50px;
}

#paper {
    width: 100%;
    min-height: var(--a4-height);
    /* Padding mimics the page margins */
    padding: 25mm 25mm;
    box-sizing: border-box;
    outline: none;
    direction: rtl;
    text-align: right;
    font-family: 'Idiqlat', 'Estrangelo Edessa', sans-serif;
    font-size: 22px;
    line-height: 1.5;
    cursor: text;
    white-space: pre-wrap;
    word-break: break-word;
}

/* On-Screen Keyboard */
#keyboard-wrapper {
    background: white;
    border-top: 1px solid #dadce0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    z-index: 100;
    transition: height 0.3s ease;
    display: block;
}

#keyboard-wrapper.hidden {
    display: none;
}

.keyboard-layout {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 900px;
    margin: 10px auto;
    padding: 10px;
}

.kb-row {
    display: flex;
    justify-content: center;
    gap: 4px;
}

.key {
    background: #f1f3f4;
    border: 1px solid #dadce0;
    border-radius: 4px;
    width: 42px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    user-select: none;
    color: #3c4043;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
    font-family: 'Idiqlat', sans-serif;
    font-size: 38px;
    transition: all 0.1s;
}

.key:hover {
    background: #e8eaed;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    z-index: 2;
}

.key:active {
    background: #dadce0;
    transform: translateY(1px);
}

/* Special Keys styling */
.key.wide {
    width: 60px;
    font-size: 24px;
    font-weight: 500;
}

.key.extra-wide {
    width: 350px;
    font-size: 24px;
    font-weight: 500;
}

.key.control {
    background: #dadce0;
    font-size: 24px;
}

/* Counter */
#counter {
    color:#5f6368; 
    margin:8px 0;
    font-size: 12px;
}

/* Context Menu */
.context-menu {
    position: absolute;
    background-color: white;
    border: 1px solid #dadce0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    border-radius: 4px;
    width: 150px;
    z-index: 10000;
    padding: 5px 0;
}

.context-menu-item {
    padding: 8px 15px;
    font-size: 14px;
    cursor: pointer;
    color: #202124;
}

.context-menu-item:hover {
    background-color: #f1f3f4;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10001;
}

.modal-content {
    background: white;
    padding: 20px;
    border-radius: 8px;
    width: 400px;
    max-width: 90%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.modal-close-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
}

.modal-close-btn:hover {
    background: #d93025;
}

/* Print Styles */
@media print {
    @page {
        margin: 0; /* Let the body margins handle the spacing */
        size: auto;
    }

    body {
        background: white;
        height: auto;
        overflow: visible;
    }

    /* Hide UI */
    #dashboard-view,
    .toolbar,
    .subtoolbar,
    #keyboard-wrapper,
    .save-status,
    #counter,
    #custom-context-menu,
    .modal-overlay {
        display: none !important;
    }

    #editor-view {
        display: block;
        height: auto;
        overflow: visible;
    }

    .editor-container {
        background: white;
        padding: 0;
        margin: 0;
        overflow: visible;
        display: block;
        height: auto;
    }

    /* CRITICAL FIX: 
       1. Remove min-height so it doesn't force a 2nd page if empty.
       2. Remove the background gradient (the visual page gap).
    */
    .page-bg {
        background: none !important;
        box-shadow: none;
        margin: 0;
        width: 100%;
        min-height: 0 !important; /* Fixes the 2-page blank issue */
        height: auto !important;
    }

    #paper {
        /* Add physical padding for the paper here */
        padding: 2.5cm !important; 
        width: 100%;
        min-height: 0 !important; /* Fixes the 2-page blank issue */
        overflow: visible;
    }

}



