/* --- GLOBAL RESET & VARIABLES --- */
* { box-sizing: border-box; }

:root {
    --bg: #f8f9fa;
    --text: #2d3748;
    --card-bg: #ffffff;
    --card-border: rgba(0,0,0,0.02);
    --input-bg: #f8fafc;
    --input-border: #e2e8f0;
    --input-text: #4a5568;
    --input-focus: #a3bffa;
    --primary: #667eea;
    --secondary: #764ba2;
    --label-color: #a0aec0;
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --header-bg: rgba(248, 249, 250, 0.95);
    --btn-act-hover: #edf2f7;
}

/* Dark Mode Override - The Shadow Realm */
body.dark-mode {
    --bg: #1a202c;
    --text: #e2e8f0;
    --card-bg: #2d3748;
    --card-border: rgba(255,255,255,0.05);
    --input-bg: #171923;
    --input-border: #4a5568;
    --input-text: #cbd5e0;
    --input-focus: #667eea;
    --label-color: #718096;
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --header-bg: rgba(26, 32, 44, 0.95);
    --btn-act-hover: #4a5568;
}

body {
    font-family: 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 100px 20px 40px 20px; 
    display: flex; flex-direction: column; align-items: center;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
    overflow-x: hidden; 
}

/* --- HEADER & COMMANDS --- */
.fixed-header-group {
    position: fixed; top: 0; left: 0; right: 0;
    background: var(--header-bg);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--card-border);
    z-index: 1000;
    display: flex; justify-content: center;
    padding: 0 20px;
    transition: background 0.3s;
}

.header-inner {
    width: 100%;
    max-width: 1600px;
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 10px 0;
    gap: 20px;
}

h1 {
    font-size: 1.4rem; font-weight: 800; margin: 0;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    white-space: nowrap; letter-spacing: -0.5px;
}

.command-bar {
    display: flex; gap: 8px; 
    background: var(--card-bg); 
    padding: 6px 10px; 
    border-radius: 14px;
    border: 1px solid var(--card-border);
    align-items: center;
    box-shadow: var(--shadow-card);
    transition: background 0.3s;
    flex-shrink: 0;
    height: 48px;
}

.utility-group, .format-group {
    display: flex; background: var(--input-bg); 
    padding: 3px; border-radius: 50px; gap: 2px;
    border: 1px solid var(--input-border);
    align-items: center;
}

.fmt-btn {
    border: none; background: transparent; 
    padding: 5px 12px; border-radius: 50px;
    font-size: 0.75rem; font-weight: 800; color: var(--label-color);
    cursor: pointer; transition: all 0.2s;
}
.fmt-btn.active {
    background: var(--primary); color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.cmd-btn {
    border: none; padding: 0 16px; border-radius: 50px; height: 32px;
    font-weight: 700; font-size: 0.85rem;
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; 
    transition: all 0.2s; position: relative; overflow: hidden;
    white-space: nowrap; line-height: 1;
}
.btn-act { background: transparent; color: var(--text); } 
.btn-act:hover { background: var(--btn-act-hover); }

.btn-pri { 
    background: #2d3748; color: white; 
    box-shadow: none !important; 
} 
body.dark-mode .btn-pri { background: #4a5568; }
.btn-pri:hover { background: #000; }
body.dark-mode .btn-pri:hover { background: #cbd5e0; color: #1a202c; }

.icon-btn {
    background: transparent; border: none; cursor: pointer; 
    font-size: 0.9rem; width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; color: var(--label-color);
}
.icon-btn:hover { background: var(--card-bg); color: var(--text); transform: scale(1.1); }
.btn-danger-icon:hover { background: rgba(252, 129, 129, 0.15); color: #f56565; }

.divider { width: 1px; height: 20px; background: var(--input-border); margin: 0 2px; }

/* --- TABLE / LIST VIEW --- */
#mainLayout { 
    width: 100%; 
    max-width: 1600px; 
    display: flex; 
    flex-direction: column; 
}

.list-header {
    display: flex; padding: 10px 45px 10px 20px;
    font-weight: 700; color: var(--label-color); font-size: 0.8rem; letter-spacing: 0.05em;
    border-bottom: 2px solid var(--input-border); margin-bottom: 5px;
}

#editorContainer { display: flex; flex-direction: column; gap: 0; }

.memory-card {
    background: var(--card-bg); border-bottom: 1px solid var(--card-border);
    display: flex; flex-direction: row; 
    align-items: center;
    padding: 8px 12px; 
    position: relative; min-height: 40px;
}
.memory-card:first-child { border-top: 1px solid var(--card-border); border-top-left-radius: 12px; border-top-right-radius: 12px; }
.memory-card:last-child { border-bottom-left-radius: 12px; border-bottom-right-radius: 12px; }

.card-accent-bar { width: 4px; position: absolute; left: 0; top: 0; bottom: 0; height: auto; }

.card-body {
    display: flex; flex-direction: row; gap: 15px; width: 100%; 
    align-items: center; 
    padding-left: 10px; padding-right: 35px;
}
.card-controls { margin-top: 0; cursor: grab; display: flex; gap: 5px; } 

/* Desktop Columns */
.title-wrapper { flex: 2; min-width: 200px; } 
.list-header .col-title { flex: 2; min-width: 200px; padding-left: 35px; }

.video-wrapper { flex: 1; min-width: 150px; display: flex; gap: 8px; align-items: center; }
.list-header .col-video { flex: 1; min-width: 150px; }

.link-wrapper { flex: 2; min-width: 200px; display: flex; gap: 8px; align-items: center; }
.list-header .col-link { flex: 2; min-width: 200px; }

/* Icon Style */
.table-icon-inline { 
    display: block; color: var(--label-color); font-size: 0.9rem; margin-top: 0;
    cursor: pointer; transition: all 0.2s ease; flex-shrink: 0;
}
.table-icon-inline:hover { color: var(--primary); transform: scale(1.2) rotate(-15deg); }

textarea {
    width: 100%; border: 1px solid transparent; background: transparent; 
    font-size: 0.9rem; 
    padding: 6px; resize: none; border-radius: 4px;
    box-sizing: border-box; line-height: 1.4; 
    overflow: hidden; 
    height: auto; display: block;
    font-family: 'Segoe UI', Roboto, sans-serif; color: var(--text);
}
.video-wrapper textarea, .link-wrapper textarea { 
    font-family: monospace; color: var(--input-text); font-size: 0.9rem; 
}
.title-wrapper textarea { font-weight: 700; font-size: 0.9rem; }
textarea:focus { background: var(--input-bg); border: 1px solid var(--input-border); }

.btn-close {
    position: relative; /* Changed from absolute for easier flex control */
    border: none; background: transparent;
    color: var(--label-color); cursor: pointer; font-size: 1.1rem; padding: 0; width: 20px;
    display: flex; align-items: center; justify-content: center;
}
/* Desktop specific positioning for close button */
@media screen and (min-width: 769px) {
     .btn-close { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); }
}

.btn-close:hover { color: #ef4444; }

.drag-handle { cursor: grab; color: var(--label-color); font-size: 0.9rem; padding: 5px; transition: color 0.2s; }
.drag-handle:hover { color: var(--primary); }

/* --- MOBILE RESPONSIVE MAGICK --- */
@media screen and (max-width: 768px) {
    body {
        padding-top: 140px; 
        padding-left: 10px; padding-right: 10px;
    }

    .fixed-header-group {
        min-width: 100%; 
        padding: 5px 10px;
    }

    .header-inner {
        flex-direction: column; 
        gap: 10px;
        align-items: center;
    }

    .command-bar {
        width: 100%;
        overflow-x: auto; 
        justify-content: center; 
        padding-right: 10px;
    }
    .command-bar::-webkit-scrollbar { display: none; }

    .list-header { display: none; }

    .memory-card {
        flex-direction: column;
        align-items: stretch;
        padding: 10px; 
        border-radius: 12px !important; 
        margin-bottom: 15px; 
        border: 1px solid var(--card-border);
        box-shadow: var(--shadow-card);
    }
    
    .card-accent-bar { width: 100%; height: 4px; top: 0; bottom: auto; left: 0; right: 0; }
    
    /* --- CONTROLS MOVED TO TOP CENTER --- */
    .card-controls {
        position: relative; 
        width: 100%;
        justify-content: center; 
        margin-top: 5px;
        margin-bottom: 10px;
        padding-bottom: 5px;
        border-bottom: 1px dashed var(--input-border); 
        gap: 20px; 
    }

    .card-controls .drag-handle { font-size: 1.2rem; }
    .card-controls .btn-close { 
        position: static; 
        transform: none; 
        font-size: 1.2rem; 
        width: auto;
    }

    .card-body { 
        flex-direction: column; 
        gap: 12px; 
        padding: 0; 
    }
    
    .title-wrapper { width: 100%; padding-right: 0; }
    .title-wrapper textarea { font-size: 1rem; text-align: center; } 

    .video-wrapper, .link-wrapper {
        width: 100%;
        background: var(--input-bg);
        padding: 10px 12px;
        border-radius: 8px;
        border: 1px solid var(--card-border);
        display: flex; 
        flex-direction: row; 
        align-items: flex-start;
        gap: 12px;
    }
    
    .video-wrapper::before, .link-wrapper::before { content: none; }
    
    .table-icon-inline { 
        display: block; 
        font-size: 1.1rem; 
        margin-top: 4px; 
        color: var(--primary); 
    }
    
    .video-wrapper textarea, .link-wrapper textarea {
        padding: 0; 
        font-size: 0.95rem;
    }
}

body.drag-over::after {
    content: 'Drop File to Open'; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(102, 126, 234, 0.9); color: white; font-size: 2rem; font-weight: bold;
    display: flex; justify-content: center; align-items: center; z-index: 9999; pointer-events: none;
    backdrop-filter: blur(4px);
}
input[type="file"] { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
