/* 1. المتغيرات والأساسيات */
:root {
    --bg-dark: #000000;
    --bg-panel: #0a0a0a;
    --bg-sidebar: #000000;
    --accent: #00e1ff;
    --text-main: #ffffff;
    --text-muted: #888888;
    --border-color: #222222;
    --sidebar-width: 280px;
}

* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
    -webkit-tap-highlight-color: transparent; 
}

body { 
    font-family: 'Inter', 'Cairo', sans-serif; 
    background: var(--bg-dark); 
    color: var(--text-main); 
    height: 100vh; 
    overflow: hidden; 
}

/* 2. الهيكل الرئيسي */
.main-wrapper { 
    display: flex; 
    height: 100vh; 
    width: 100%; 
    position: relative;
}

/* 3. القائمة الجانبية (Sidebar) */
.sidebar { 
    width: var(--sidebar-width); 
    min-width: var(--sidebar-width); 
    background: var(--bg-sidebar); 
    border-right: 1px solid var(--border-color); 
    display: flex; 
    flex-direction: column; 
    padding: 20px 0; 
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}

.name { padding: 0 20px; margin-bottom: 30px; }
.name h1 { font-size: 30px; letter-spacing: -1px; }

.controls a, .tags a { 
    color: var(--text-muted); 
    text-decoration: none; 
    padding: 12px 20px; 
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500; 
    border-radius: 12px; 
    margin: 4px 15px; 
    transition: all 0.2s ease; 
}

.controls i, .tags i { width: 20px; text-align: center; }

.controls a:hover, .tags a:hover, .active-link { 
    background: #111; 
    color: #fff; 
    box-shadow: inset 0 0 0 1px #333;
}

.active-link {
    background: #1a1a1a !important;
    border-left: 3px solid var(--accent);
}

.custom-line { height: 1px; background: var(--border-color); margin: 15px 20px; }
.title { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; padding: 0 25px 10px; }

#tags-list { flex-grow: 1; overflow-y: auto; padding-bottom: 20px; }

.sidebar-bottom { 
    padding: 20px; 
    display: flex; 
    gap: 10px; 
    background: var(--bg-sidebar);
    margin-bottom: 5px;
}

.button { 
    background: var(--text-main); 
    color: #000; 
    border: none; 
    padding: 12px 15px; 
    flex: 1; 
    border-radius: 10px; 
    font-weight: 700; 
    cursor: pointer; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
}

.deletebtn { 
    background: #ff222222; 
    border: 1px solid #ff2222; 
    width: 45px; 
    border-radius: 10px; 
    color: #ff2222; 
    cursor: pointer; 
    transition: 0.3s;
}

/* 4. منطقة المحتوى (Content Area) */
.content { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    padding: 30px; 
    height: 100vh;
}

.header-area { 
    display: flex; 
    flex-wrap: wrap; 
    justify-content: space-between; 
    align-items: center; 
    gap: 15px;
    margin-bottom: 25px; 
}

#titletag { font-size: clamp(1.5rem, 5vw, 2rem); }

.editor-controls { 
    display: flex; 
    flex-wrap: wrap;
    gap: 8px; 
    background: #111; 
    padding: 6px; 
    border-radius: 12px; 
    border: 1px solid #222; 
}

.control-box { 
    display: flex; 
    align-items: center; 
    gap: 8px; 
    padding: 4px 10px;
    border-right: 1px solid #222; 
}

.control-box:last-child { border: none; }
.control-box label { font-size: 11px; color: #666; font-weight: bold; }

.control-box button { 
    background: #222; 
    border: none; 
    color: #fff; 
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    cursor: pointer; 
    border-radius: 8px; 
}

.control-box select {
    background: transparent;
    color: white;
    border: none;
    outline: none;
    font-size: 14px;
    cursor: pointer;
}

/* 5. منطقة النوت (Note Container) */
.note-container { 
    flex: 1; 
    position: relative; 
    min-height: 300px;
    margin-bottom: 20px;
}

textarea { 
    width: 100%; 
    height: 100%; 
    background: var(--bg-panel); 
    color: #eee; 
    border: 1px solid var(--border-color); 
    border-radius: 20px; 
    padding: 25px; 
    line-height: 1.6;
    resize: none; 
    outline: none; 
    transition: border 0.3s;
}

::-webkit-scrollbar{
    width: 5px;
    border-radius: 20px;
}
::-webkit-scrollbar-track{
    background-color: #000000;
}
::-webkit-scrollbar-thumb{
    background-color: #242424;
    border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover{
    background-color: #363636;
}
textarea:focus { border-color: #444; }

/* 6. نافذة إضافة التاج (Tag Form) */
/* تحسين شكل نافذة تعديل التاج */
.tagform { 
    display: none; 
    position: fixed; 
    top: 50%; 
    left: 50%; 
    transform: translate(-50%, -50%); 
    background: #111111; 
    padding: 32px; 
    border-radius: 28px; 
    border: 1px solid #333; 
    z-index: 3000; 
    width: 90%; 
    max-width: 380px; 
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
    text-align: center;
}

.tagform h1 {
    font-size: 20px;
    margin-bottom: 20px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.5px;
}

/* شكل حقل الإدخال */
.tag-input-group { 
    display: flex; 
    flex-direction: column;
    gap: 12px; 
    margin-bottom: 25px; 
}

.tag-input-group input { 
    background: #000; 
    border: 1px solid #222; 
    padding: 14px 18px; 
    border-radius: 12px; 
    color: #fff; 
    font-size: 16px;
    transition: all 0.3s ease;
}

.tag-input-group input:focus {
    border-color: #00e1ff;
    box-shadow: 0 0 0 4px rgba(0, 225, 255, 0.1);
    outline: none;
}

/* زر التأكيد */
.tag-input-group button { 
    background: #fff; 
    color: #000; 
    border: none; 
    padding: 14px; 
    border-radius: 12px; 
    font-weight: 800; 
    cursor: pointer;
    font-size: 15px;
    transition: transform 0.2s active;
}

.tag-input-group button:active {
    transform: scale(0.96);
}

/* شبكة اختيار الألوان */
.color-picker-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    margin-top: 10px;
    background: #000;
    padding: 15px;
    border-radius: 15px;
}

.color-dot { 
    width: 100%; 
    aspect-ratio: 1; 
    border-radius: 50%; 
    border: 3px solid transparent; 
    cursor: pointer; 
    transition: all 0.2s ease;
}

.color-dot:hover {
    transform: scale(1.1);
}

/* زر الإغلاق */
.x { 
    position: absolute; 
    top: 18px; 
    right: 18px; 
    background: #222; 
    border: none; 
    color: #fff; 
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px; 
    cursor: pointer; 
    transition: background 0.2s;
}

.x:hover {
    background: #ff2222;
}

/* تحسين شكل حاوية اختيار الخط */
#font-picker {
    background: #1a1a1a;
    color: #efefef;
    border: 1px solid #333;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    outline: none;
    transition: all 0.3s ease;
    appearance: none; /* إخفاء السهم الافتراضي لعمل سهم مخصص */
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
    min-width: 140px;
}

#color-picker {
    background: #1a1a1a;
    color: #efefef;
    border: 1px solid #333;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    outline: none;
    transition: all 0.3s ease;
    appearance: none; /* إخفاء السهم الافتراضي لعمل سهم مخصص */
    background-image: url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
    min-width: 140px;
}

#font-picker:hover {
    border-color: #00e1ff;
    background-color: #222;
}

#font-picker optgroup {
    background: #111;
    color: #888;
    font-style: normal;
    font-weight: bold;
    padding: 10px;
}

#font-picker option {
    background: #1a1a1a;
    color: #fff;
    padding: 10px;
}

/* تعديل الـ control-box ليشمل الأيقونة بشكل أفضل */
.control-box i {
    color: #00e1ff;
    font-size: 14px;
}

/* إزالة الحد الأخير */
.no-border {
    border: none !important;
}

.color-dot { width: 100%; aspect-ratio: 1; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }

/* 7. زر الموبايل (Mobile Menu Button) */
#mobile-menu-btn { 
    display: none; 
    position: fixed; 
    bottom: 25px; 
    right: 25px; 
    z-index: 2500; 
    background: var(--accent); 
    border: none; 
    width: 56px; 
    height: 56px; 
    border-radius: 50%; 
    color: #000; 
    font-size: 20px;
    box-shadow: 0 8px 25px rgba(0, 225, 255, 0.3);
    cursor: pointer;
}

.sidebar h6{
    color: #ffffff;
    box-sizing: border-box;
    margin-left: 5px;
    margin-bottom: 5px;
}



/* 8. إعدادات الشاشات الصغيرة (Media Queries) */
@media (max-width: 900px) {
    .editor-controls { order: 2; width: 100%; justify-content: space-around; }
    .header-area { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 768px) {
    #mobile-menu-btn { display: block; }

    .sidebar { 
        position: fixed; 
        left: 0; 
        top: 0;
        transform: translateX(-100%);
        height: 100vh; 
        box-shadow: 20px 0 50px rgba(0,0,0,0.8);
    }

    .sidebar.active { transform: translateX(0); }

    .content { padding: 20px; padding-top: 60px; }
    
    .control-box label { display: none; } /* إخفاء الليبل لتوفير مساحة */
    
    .tagform { width: 95%; padding: 20px; }
}

/* تحسين شكل الـ AI Loader */
#ai-loader {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

/* تنسيقات الـ Light Mode المحسنة */
body.light-mode {
    --bg-dark: #f0f2f5;
    --bg-panel: #ffffff;
    /* لون أبيض هادي مش ناصع للـ Sidebar */
    --bg-sidebar: #f8f9fa; 
    --text-main: #1a1a1a;
    --text-muted: #666666;
    --border-color: #e0e0e0;
}

/* تعديل زرار الـ Add Note في الـ Light Mode */
body.light-mode .button {
    background: #ffffff; /* يقلب أسود شيك */
    color: #000000;      /* والخط أبيض */
    border: 1px solid #333;
}

/* تعديل الـ textarea والتحكم */
body.light-mode textarea {
    color: #1a1a1a;
    background: #ffffff;
    border-color: #ddd;
}

body.light-mode .editor-controls {
    background: #fdfdfd;
    border-color: #eee;
}

body.light-mode .control-box button {
    background: #eee;
    color: #000;
}

body.sidebar h6,
body.light-mode .controls a{
    color: #000;
}

body.light-mode .tags a {
    color: #ffffff;
}

body.light-mode .controls a:hover, body.light-mode .tags a:hover {
    background: #ececec;
}

body.light-mode .sidebar h6 {
    color: #1a1a1a !important;
}