/* Professional System Fonts & Base */
html, body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 
    background-color: #f4f6f8; 
    margin: 0; 
    padding: 0; 
    color: #333;
}
.page { padding: 20px; }
.ghost-box { 
    text-align: center; 
    margin-top: 20%; 
    background: white; 
    padding: 40px; 
    border-radius: 12px; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.05); 
    max-width: 400px; 
    margin-left: auto; 
    margin-right: auto; 
}

/* PROFESSIONAL HEADER WITH FLAGS */
.header-container { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 25px;
    flex-shrink: 0;
}
.header { 
    margin: 0; /* Removes old margin since container handles spacing */
    font-size: 1.5em; 
    color: #2c3e50; 
    flex-grow: 1;
    text-align: center;
}
.flag-btn { 
    background: transparent; 
    border: 2px solid transparent; 
    font-size: 1.5em; 
    cursor: pointer; 
    padding: 5px;
    border-radius: 8px;
    transition: all 0.2s;
    line-height: 1;
}
.flag-btn:hover { 
    background: #f0f0f0; 
    border-color: #ddd; 
    transform: scale(1.1);
}
.flag-btn:active { 
    transform: scale(0.95); 
}

/* USER PAGE LAYOUT */
#user-page { 
    display: flex; 
    flex-direction: column; 
    height: 100vh; 
    box-sizing: border-box; 
    overflow: hidden; /* Prevents whole screen from scrolling */
}
#user-page .header-container { flex-shrink: 0; }
#user-page .book-grid { 
    flex-grow: 1; 
    overflow-y: auto; /* ONLY the books scroll */
    padding-bottom: 80px; /* Adds space so books don't hide behind the fixed bottom bar */
}

/* PHYSICALLY LOCKED BOTTOM BAR */
#user-page .return-section { 
    position: fixed; /* Glues it to the screen */
    bottom: 0; 
    left: 0; 
    right: 0;
    width: 100%; 
    background: white; 
    padding: 15px 20px; 
    border-radius: 16px 16px 0 0; 
    box-shadow: 0 -4px 20px rgba(0,0,0,0.08); 
    border-top: 1px solid #e1e4e8;
    z-index: 100; 
    box-sizing: border-box;
}
.toggle-btn { 
    background: none; 
    border: none; 
    font-size: 1.1em; 
    width: 100%; 
    text-align: center; 
    cursor: pointer; 
    font-weight: 600; 
    color: #007bff; 
    padding: 0;
    display: flex;
    justify-content: space-between; /* Puts arrows on far sides */
    align-items: center;
}
.return-explanation {
    font-size: 0.9em;
    color: #6c757d;
    margin: 10px 0 15px 0;
}
.return-input-row { display: flex; gap: 10px; }
.return-input-row input { flex: 1; padding: 10px; border: 1px solid #ced4da; border-radius: 6px; font-size: 1em; box-sizing: border-box;}
.return-input-row button { padding: 10px 20px; background: #17a2b8; color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: 500; }
.msg { width: 100%; margin-top: 10px; font-weight: 500; font-size: 0.9em; text-align: center;}

/* Book Grid */
.book-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
@media (max-width: 600px) { .book-grid { grid-template-columns: repeat(2, 1fr); gap: 15px; } }

/* Book Card */
.book-card { background: white; padding: 12px; border-radius: 10px; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.04); display: flex; flex-direction: column; }
.book-card img { width: 100%; height: 220px; object-fit: cover; border-radius: 6px; margin-bottom: 12px; background-color: #e9ecef; }
.book-title { font-weight: 600; font-size: 1em; margin: 0 0 8px 0; line-height: 1.3; color: #2c3e50; }
.availability { font-size: 0.85em; margin-bottom: 12px; font-weight: 500; }
.available { color: #28a745; }
.unavailable { color: #dc3545; }
.borrow-btn { background: #007bff; color: white; border: none; padding: 10px 16px; border-radius: 6px; cursor: pointer; width: 100%; font-weight: 500; font-size: 0.95em; box-sizing: border-box;}
.borrow-btn:disabled { background: #e9ecef; color: #6c757d; cursor: not-allowed; }

/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); display: flex; justify-content: center; align-items: center; z-index: 1000; }
.modal-content { background: white; padding: 30px; border-radius: 12px; width: 90%; max-width: 400px; text-align: center; box-shadow: 0 20px 40px rgba(0,0,0,0.15); }
.modal-content input { width: 100%; padding: 12px; margin: 15px 0; border: 1px solid #ced4da; border-radius: 6px; box-sizing: border-box; font-size: 1em; }
.warning { color: #6c757d; font-size: 0.8em; margin-bottom: 20px; line-height: 1.4; }
.modal-buttons { display: flex; gap: 10px; justify-content: center; }
.modal-buttons button { padding: 10px 20px; border: none; border-radius: 6px; cursor: pointer; font-weight: 500; }
#cancel-borrow { background: #e9ecef; color: #495057; }
#accept-borrow { background: #007bff; color: white; }

/* Success State */
.success-box { background: #f8fdf9; padding: 20px; border-radius: 10px; }
.modal-overlay.success-mode { background: rgba(40, 167, 69, 0.2); backdrop-filter: blur(4px); }
.success-img { width: 100px; height: auto; border-radius: 6px; margin-bottom: 20px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
.success-text { color: #155724; font-weight: 500; line-height: 1.5; margin: 0; font-size: 1em; }

/* Hourglass */
.hourglass { border: 4px solid rgba(0,0,0,0.1); border-left-color: #007bff; border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; margin: 0 auto 15px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Admin Styles */
.admin-panel { background: white; padding: 20px; margin-bottom: 20px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.04); }
.admin-panel input { display: block; width: 100%; margin-bottom: 10px; padding: 10px; box-sizing: border-box; border: 1px solid #ced4da; border-radius: 6px; }
.admin-panel button { padding: 10px; background: #28a745; color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: 500; }
.admin-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid #f1f3f5; font-size: 0.95em; }
.log-list { max-height: 400px; overflow-y: auto; font-size: 0.85em; font-family: monospace; background: #f8f9fa; padding: 15px; border-radius: 6px; }
.log-entry { padding: 8px 0; border-bottom: 1px solid #e9ecef; color: #495057;}

/* Admin Grid & Card Specifics */
#admin-book-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}
@media (max-width: 600px) { 
    #admin-book-list { grid-template-columns: repeat(2, 1fr); gap: 15px; } 
}

.admin-book-code {
    font-size: 0.85em;
    color: #6c757d;
    margin: 0 0 5px 0;
    font-family: monospace;
    background: #e9ecef;
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
}
.admin-borrower {
    font-size: 0.85em;
    color: #dc3545;
    font-weight: 600;
    margin: 0 0 10px 0;
    min-height: 1.2em; /* Prevents layout jumping if empty */
}
.admin-btn-row {
    display: flex;
    gap: 5px;
    margin-top: auto; /* Pushes buttons to bottom of card */
}
.admin-action-btn {
    flex: 1;
    padding: 8px 5px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85em;
}
.edit-btn { background: #ffc107; color: #333; }
.del-btn { background: #dc3545; color: white; }