body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f4f7f6;
    color: #333;
    margin: 0;
}
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}
nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
nav h2 { margin: 0; }
nav a {
    text-decoration: none;
    color: #007bff;
    margin-left: 15px;
}
nav span { margin-left: 15px; color: #666; }
nav button { margin-left: 15px; }

main {
    margin-top: 20px;
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

main h3 {
    margin-top: 0;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #f1f1f1;
}

.filters {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    flex-direction: column; 
    align-items: flex-start; 
}
.filters label { font-weight: 600; }

input[type="date"], input[type="text"], select, button {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}
button {
    background-color: #007bff;
    color: white;
    border: none;
    cursor: pointer;
}
button:hover { background-color: #0056b3; }

.hidden { display: none; }
#loading-spinner {
    font-size: 1.2em;
    color: #007bff;
    text-align: center;
    padding: 40px;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}
th, td {
    border: 1px solid #ddd;
    padding: 12px;
    text-align: left;
}
th { background-color: #f9f9f9; }
tfoot td { background-color: #f1f1f1; }

/* Style for the main, clickable publisher row */
.publisher-row {
    cursor: pointer;
    font-weight: bold;
    background-color: #f9f9f9; 
}

/* Add a hover effect to show it's clickable */
.publisher-row:hover {
    background-color: #f1f1f1;
}

/* Style for the hidden data rows */
.data-row {
    /* background-color: #fafafa; */ 
}

/* A simple +/- indicator for collapsed/expanded state */
.publisher-row .toggle-icon::before {
    content: '[+] ';
    font-family: monospace;
}

.publisher-row.expanded .toggle-icon::before {
    content: '[-] ';
    font-family: monospace;
}


/* --- Filter / Tom Select Styles --- */

.filters-row {
    display: flex;
    gap: 15px;
    align-items: center;
    width: 100%; 
    margin-bottom: 15px; 
}

main .filters .filters-row .ts-wrapper {
    flex-grow: 1;
    flex-basis: 0;
}

.ts-control .ts-input > input::placeholder {
    color: #888;
}


.filters-row label {
    white-space: nowrap; 
}

.ts-dropdown {
    z-index: 9999; 
}

/* --- Logo Styles --- */
.logo-title {
    display: flex;
    align-items: center;
    gap: 10px; 
}

.logo {
    height: 32px; 
    width: 32px;  
}

.login-title {
    justify-content: center;
}

.login-title h1 {
    margin: 0;
    font-size: 1.75em; 
}


/* --- Instruction Box Styles --- */
.instructions {
    background-color: #f4f7f6; 
    border: 1px solid #ddd;
    border-left: 5px solid #007bff; 
    border-radius: 6px;
    padding: 15px 20px;
    margin-bottom: 25px; 
}

.instructions h4 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #333;
}

.instructions p {
    margin-top: 0;
    font-size: 0.95em;
}

.instructions ol {
    padding-left: 20px;
    margin-bottom: 0;
}

.instructions li {
    margin-bottom: 8px;
    font-size: 0.95em;
}

.instructions code {
    background-color: #e9ecef;
    padding: 3px 6px;
    border-radius: 4px;
    font-family: monospace;
    color: #c7254e; 
    word-break: break-all; 
}

/* --- Settings Page: Add Account Form --- */
.add-account-layout {
    display: flex;
    flex-direction: row; 
    flex-wrap: wrap; 
    align-items: center; 
    gap: 15px; 
    margin-bottom: 25px; 
}

.add-account-layout input[type="text"] {
    flex-grow: 1;
    min-width: 200px; 
}

/* --- Settings Page: Account List Styles --- */
#account-list-container h4 {
    font-size: 1.2em;
    color: #333;
    border-bottom: 2px solid #f4f7f6; 
    padding-bottom: 10px;
    margin-bottom: 20px;
}

#account-list-container table {
    margin-top: 0; 
}

#account-list-container th:last-child {
    text-align: center; 
}

#account-list-container td:last-child {
    text-align: center; 
}


/* --- Login Page Styles --- */
body.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

body.login-page .container {
    max-width: 420px;
    background-color: #fff;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    text-align: center;
}

body.login-page .logo {
    height: 64px;
    width: 64px;
    margin-bottom: 24px;
}

body.login-page h2 {
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 1.75em;
}

body.login-page p {
    color: #666;
    font-size: 1.1em;
    margin-bottom: 30px;
}

body.login-page button {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    font-weight: 600;
}

/* --- Chart Styles --- */
#chart-container {
    margin-bottom: 20px;
}

#chart-container h3 {
    border-bottom: none; 
    margin-bottom: 0; 
}

.clickable-header {
    cursor: pointer;
    font-weight: bold;
    padding-bottom: 10px; 
    border-bottom: 1px solid #f1f1f1; 
    margin-bottom: 15px; 
}

.clickable-header:hover {
    color: #0056b3; 
}

.clickable-header .toggle-icon::before {
    content: '[+] ';
    font-family: monospace;
}

.clickable-header.expanded .toggle-icon::before {
    content: '[-] ';
    font-family: monospace;
}

#chart-canvas-wrapper {
    height: 400px;
    margin-bottom: 20px; 
}

/* --- Report Header & Export Button --- */
.report-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.report-header h3 {
    margin: 0; 
    border-bottom: none;
    padding-bottom: 0;
}

#export-button {
    background-color: #28a745; /* Green */
    color: #ffffff; /* White text */
    border: none;
    font-weight: 600;
}

#export-button:hover {
    background-color: #218838; /* Darker green on hover */
}

/* --- START: Mobile Responsive Styles --- */

/* This query applies all styles inside it to screens 768px wide or less */
@media (max-width: 768px) {

    /* --- General & Navigation --- */
    .container {
        padding: 10px; /* Reduce padding on small screens */
    }

    nav {
        flex-direction: column; /* Stack logo and links vertically */
        align-items: flex-start; /* Align items to the left */
        gap: 15px; /* Add space between stacked items */
    }

    nav div {
        /* This targets both the logo-title div and the links div */
        display: flex;
        flex-direction: column; /* Stack links vertically */
        align-items: flex-start;
        gap: 10px;
        width: 100%; /* Make them take full width */
    }

    nav span, nav button, nav a {
        margin-left: 0; /* Remove left margin on nav items */
    }

    /* --- Dashboard Page: Filters --- */
    .filters-row {
        flex-direction: column; /* Stack filter items vertically */
        align-items: stretch; /* Make inputs full-width */
        gap: 10px;
    }

    /* --- Settings Page: Add Account Form --- */
    .add-account-layout {
        flex-direction: column; /* Stack form items vertically */
        align-items: stretch; /* Make inputs full-width */
    }

    .add-account-layout input[type="text"] {
        min-width: 0; /* Reset min-width for mobile */
    }

    /* --- Table Scrolling (for both pages) --- */
    #report-container,
    #account-list-container {
        /* This makes the tables scroll horizontally, so they don't
           squish and break the layout. */
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }

    /* --- Login Page --- */
    body.login-page .container {
        padding: 20px; /* Reduce padding for smaller screens */
        box-shadow: none; /* Optional: remove shadow for a flatter look */
        border: 1px solid #ddd;
    }

    /* --- Chart Toggle --- */
    #chart-canvas-wrapper {
        height: 300px; /* Make chart a bit shorter on mobile */
    }
}
/* --- END: Mobile Responsive Styles --- */

/* --- START: Table Sorting Styles --- */
#report-table thead th.sortable {
    cursor: pointer;
    user-select: none;
}

#report-table thead th.sortable:hover {
    background-color: #f1f1f1;
}

#report-table thead th.sortable span {
    font-size: 0.8em;
    float: right;
    opacity: 0.3;
}

/* Show a faint up arrow on all sortable columns */
#report-table thead th.sortable span::after {
    content: ' \25B2'; /* Up Triangle */
}

/* Make the arrow solid for the active sorted column (ascending) */
#report-table thead th.sortable.asc span::after {
    content: ' \25B2'; /* Up Triangle */
    opacity: 1;
}

/* Change the arrow to down for descending sort */
#report-table thead th.sortable.desc span::after {
    content: ' \25BC'; /* Down Triangle */
    opacity: 1;
}
/* --- END: Table Sorting Styles --- */


/* --- START: Settings Page Button Styles (FIXED) --- */

/* This was the original rule that caused the conflict. We remove it. */
/*
#account-list button {
    background-color: #dc3545;
}
*/

/* Default for all buttons in the actions column */
#account-list-container table button {
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    margin-right: 8px;
    font-weight: 600;
}
/* Last button doesn't need margin */
#account-list-container table button:last-child {
    margin-right: 0;
}

/* Style for the "Test" button (Yellow) */
#account-list-container table button.test-btn {
    background-color: #ffc107; /* Yellow */
    color: #333; /* Dark text */
    border: 1px solid #e0a800;
}
#account-list-container table button.test-btn:hover {
    background-color: #e0a800; /* Darker yellow */
}

/* Style for the "Delete" button (Red) */
#account-list-container table button.delete-btn {
    background-color: #dc3545; /* Red */
    color: white;
}
#account-list-container table button.delete-btn:hover {
    background-color: #c82333; /* Darker red */
}

/* Style for when the button is disabled (e.g., "Testing...") */
#account-list-container table button:disabled {
    background-color: #6c757d; /* Gray */
    color: white;
    border: none;
    cursor: not-allowed;
}

/* --- END: Settings Page Button Styles (FIXED) --- */

/* --- START: Updates for Sales Rep & Edit Functionality --- */

/* Sales Rep Manager Chips */
.sales-rep-manager {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    margin-bottom: 25px;
    border: 1px solid #ddd;
}

.sales-rep-input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

#rep-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.rep-chip {
    background-color: #e9ecef;
    border-radius: 16px;
    padding: 5px 12px;
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #333;
}

.rep-chip button {
    background: none;
    border: none;
    color: #999;
    margin-left: 8px;
    font-weight: bold;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.rep-chip button:hover {
    color: #dc3545;
}

/* Form Updates */
.add-account-layout {
    align-items: flex-start; /* Align top for textarea */
}

.add-account-layout .form-group {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-width: 200px;
}

.add-account-layout textarea {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    resize: vertical;
    min-height: 38px;
}

/* Search Bar */
.search-bar-container {
    margin-bottom: 15px;
}

#account-search {
    width: 100%;
    max-width: 400px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
}

/* Edit Mode Button State */
button.btn-warning {
    background-color: #ffc107;
    color: #333;
}
button.btn-warning:hover {
    background-color: #e0a800;
}

/* Edit/Delete Button Spacing */
#account-list-container table button {
    margin-bottom: 4px; /* Stack nicely if they wrap */
}
/* --- END: Updates --- */

/* --- Fix for Multiline RevShare --- */

/* This class tells the browser: "If there is a new line in the text, actually show it" */
.preserve-line-breaks {
    white-space: pre-wrap;       /* Preserves new lines */
    word-break: break-word;      /* Prevents long text from breaking the layout */
    min-width: 150px;            /* Ensures column isn't too narrow */
    max-width: 400px;            /* Prevents it from being too wide */
    vertical-align: top;         /* Aligns text to top of cell for better readability */
}

/* --- Error Toast Notification Styles --- */
#error-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 350px;
    background-color: #fff;
    border-left: 5px solid #dc3545; /* Red warning border */
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-radius: 4px;
    padding: 15px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    animation: slideIn 0.3s ease-out;
}

#error-toast.hidden {
    display: none;
}

#error-toast-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    color: #dc3545;
}

#error-toast-body {
    font-size: 0.9em;
    color: #333;
    max-height: 100px;
    overflow-y: auto;
    background: #f8f9fa;
    padding: 8px;
    border-radius: 4px;
    font-family: monospace;
}

#error-toast-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

#error-toast-actions button {
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    border-radius: 4px;
    border: none;
}

#btn-toast-copy {
    background-color: #e2e6ea;
    color: #333;
}
#btn-toast-copy:hover {
    background-color: #dae0e5;
}

#btn-toast-close {
    background-color: #dc3545;
    color: white;
}
#btn-toast-close:hover {
    background-color: #c82333;
}

@keyframes slideIn {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}