/* --- Global & Layout --- */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background-color: #f4f4f9; color: #333; font-size: 14px; }
.dashboard-layout { display: grid; grid-template-columns: 350px 1fr; height: calc(100vh - 60px); }
.sidebar { background-color: #fff; border-right: 1px solid #ddd; padding: 15px; display: flex; flex-direction: column; gap: 20px; overflow-y: auto; }
.main-content { padding: 20px; overflow-y: auto; }

/* --- Header --- */
header { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; background-color: #ffffff; border-bottom: 1px solid #ddd; height: 60px; }
header h1 { font-size: 1.2em; margin: 0; }
.logout-btn { padding: 8px 15px; border: 1px solid #ccc; border-radius: 4px; background-color: #333; color: #fff; cursor: pointer; text-decoration: none; }

/* --- Sidebar Sections --- */
.sidebar-section h2 { font-size: 1.1em; margin-bottom: 10px; border-bottom: 1px solid #eee; padding-bottom: 8px; }
.create-project-form { display: flex; gap: 10px; }
.create-project-form input { flex-grow: 1; }
.project-list, .saved-item-list { list-style: none; padding: 0; }
.project-list li, .saved-item-list li { padding: 10px 8px; border-bottom: 1px solid #eee; transition: background-color 0.2s; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.project-list li:hover, .saved-item-list li:hover { background-color: #f0f0f0; }
.project-list li.active { background-color: #e0eafc; font-weight: bold; }
.project-list li .project-name, .saved-item-list .item-main-content { flex-grow: 1; cursor: pointer; }
.saved-item-list .thumbnail { width: 50px; height: 30px; object-fit: cover; border-radius: 3px; }
.saved-item-list .item-info { display: flex; flex-direction: column; }
.saved-item-list .placeholder { color: #888; text-align: center; padding: 20px 0; }

/* --- Main Content Forms (Chart Generator) --- */
.config-panel { background: #fff; padding: 20px; border: 1px solid #ddd; border-radius: 8px; margin-bottom: 20px; }
fieldset { border: 1px solid #ddd; border-radius: 4px; padding: 20px; margin-bottom: 20px; }
legend { font-weight: bold; padding: 0 10px; margin-left: 10px; color: #333; }
.input-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 15px; margin-bottom: 20px; }
.dataset-picker-header { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 15px; }
.dataset-picker { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 15px; margin-bottom: 10px; }

/* --- Buttons --- */
button { padding: 8px 15px; border: 1px solid #ccc; border-radius: 4px; background-color: #f0f0f0; color: #333; cursor: pointer; font-size: 14px; }
.delete-btn { background-color: #f8d7da; color: #721c24; border-color: #f5c6cb; border-radius: 50%; width: 28px; height: 28px; padding: 0; font-size: 16px; flex-shrink: 0; }
.generate-chart-container { display: flex; justify-content: center; align-items: center; gap: 20px; margin: 20px 0; padding: 20px; border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; background: #fdfdfd; }
#generate-chart-btn { padding: 12px 20px; font-size: 16px; font-weight: bold; background-color: #28a745; color: white; border-color: #28a745; }
#save-to-project-btn { padding: 12px 20px; font-size: 16px; background-color: #007bff; color: white; border-color: #007bff; }
#save-to-project-btn:disabled { background-color: #ccc; border-color: #ccc; cursor: not-allowed; }

/* --- Chart Display --- */
.chart { background: #fff; padding: 20px; border-radius: 8px; border: 1px solid #ddd; margin-top: 20px; }

/* --- Modal Styles --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); display: flex; justify-content: center; align-items: center; z-index: 1000; }
.modal-content { background: #fff; padding: 25px; border-radius: 8px; max-width: 90%; max-height: 90%; overflow-y: auto; position: relative; min-width: 600px; }
.modal-close-btn { position: absolute; top: 10px; right: 15px; background: none; border: none; font-size: 24px; cursor: pointer; }
.modal-body h2 { margin-bottom: 5px; }
.modal-body h3 { margin-top: 20px; margin-bottom: 10px; }
.modal-body p { margin-bottom: 20px; color: #666; }
.modal-body .saved-image-container img { max-width: 100%; border: 1px solid #ccc; }

/* --- UNIFIED TABLE STYLES (THIS IS THE FIX) --- */
/* Wrapper for the generated table on the main page */
#data-table-container {
    margin-top: 20px;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 20px;
    position: relative;
    overflow-x: auto;
}

/* Wrapper for the saved table inside the modal */
.modal-body .saved-table-container {
    margin-top: 15px;
    position: relative;
    max-height: 350px;
    overflow: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* Styles for ALL tables in the application */
#data-table-container table,
.saved-table-container table {
    width: 100%;
    border-collapse: collapse;
}

/* Styles for ALL table cells (th, td) */
#data-table-container th, #data-table-container td,
.saved-table-container th, .saved-table-container td {
    padding: 8px 12px;
    border: 1px solid #ddd;
    text-align: left;
    white-space: nowrap;
}

/* Styles for ALL table headers (thead) */
#data-table-container thead th,
.saved-table-container thead th {
    background-color: #f2f2f2;
    font-weight: bold;
    position: sticky;
    top: 0;
}

/* Styles for ALL copy buttons */
.copy-table-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #fff;
    border: 1px solid #ccc;
    z-index: 10;
    width: auto;
    font-size: 16px;
    line-height: 1;
    padding: 5px 8px;
}
.copy-table-btn:hover { background-color: #f0f0f0; }