/* ============================================
   MODERN DJANGO ADMIN DESIGN
   Enhanced styling for consulting management app
   ============================================ */

/* ============================================
   1. COLOR VARIABLES & BASE STYLES
   ============================================ */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #34495e;
    --accent-color: #3498db;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --light-bg: #ecf0f1;
    --white: #ffffff;
    --text-dark: #2c3e50;
    --text-muted: #7f8c8d;
    --border-color: #bdc3c7;
    --shadow: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
}

/* Base font size increase */
body, .form-row, .module, .dashboard {
    font-size: 15px !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--text-dark);
}

/* ============================================
   2. HEADER & NAVIGATION
   ============================================ */
#header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%) !important;
    box-shadow: var(--shadow-lg);
    padding: 15px 20px !important;
    font-size: 16px !important;
}

#branding h1 {
    font-size: 24px !important;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin: 0;
}

#branding h1 a {
    color: var(--white) !important;
    text-decoration: none;
    transition: opacity 0.3s ease;
}

#branding h1 a:hover {
    opacity: 0.9;
}

#user-tools {
    font-size: 14px !important;
    padding: 8px 0;
}

#user-tools a {
    color: rgba(255, 255, 255, 0.9) !important;
    transition: all 0.3s ease;
    padding: 6px 12px;
    border-radius: 4px;
}

#user-tools a:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--white) !important;
}

/* Custom home link styling */
#user-tools a[href="/"] {
    background: rgba(255, 255, 255, 0.1);
    margin-right: 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#user-tools a[href="/"]:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Breadcrumbs */
.breadcrumbs {
    background: var(--light-bg) !important;
    padding: 12px 20px !important;
    font-size: 14px !important;
    border-bottom: 1px solid var(--border-color);
}

.breadcrumbs a {
    color: var(--accent-color) !important;
    text-decoration: none;
    transition: color 0.3s ease;
}

.breadcrumbs a:hover {
    color: var(--primary-color) !important;
    text-decoration: underline;
}

/* ============================================
   3. MAIN CONTENT AREA
   ============================================ */
#content {
    padding: 25px 30px !important;
    background: #f5f7fa;
}

.module, .dashboard {
    background: var(--white);
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 25px;
    overflow: hidden;
}

.module h2, .module caption, .inline-group h2 {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%) !important;
    color: var(--white) !important;
    font-size: 17px !important;
    font-weight: 600;
    padding: 15px 20px !important;
    margin: 0 !important;
    border: none !important;
}

/* ============================================
   4. FORMS & INPUT FIELDS
   ============================================ */
.form-row {
    padding: 15px 20px;
    border-bottom: 1px solid var(--light-bg);
}

.form-row:last-child {
    border-bottom: none;
}

label, .form-row label {
    font-size: 15px !important;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 8px;
    display: block;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="url"],
input[type="tel"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
textarea,
select {
    font-size: 15px !important;
    padding: 10px 12px !important;
    border: 2px solid var(--border-color) !important;
    border-radius: 6px !important;
    transition: all 0.3s ease;
    background: var(--white);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
input[type="url"]:focus,
input[type="tel"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
textarea:focus,
select:focus {
    border-color: var(--accent-color) !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1) !important;
}

/* ============================================
   5. DROPDOWN FIXES
   ============================================ */
/* Generic select styling - but NOT for action dropdowns */
.form-row select:not([multiple]),
.aligned select:not([multiple]),
.field-payment_status select,
.field-status select,
.field-billing_type select,
.field-payment_method select,
.field-preferred_payment_method select,
#id_status:not([name="action"]),
#id_payment_status:not([name="action"]),
#id_billing_type:not([name="action"]),
#id_payment_method:not([name="action"]),
#id_preferred_payment_method:not([name="action"]),
select[name="status"]:not([name="action"]),
select[name="payment_status"]:not([name="action"]),
select[name="billing_type"]:not([name="action"]),
select[name="payment_method"]:not([name="action"]),
select[name="preferred_payment_method"]:not([name="action"]) {
    min-width: 500px !important;
    width: 500px !important;
    max-width: 500px !important;
    padding-right: 40px !important;
    box-sizing: border-box !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%232c3e50' d='M6 9L1 4h10z'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 12px center !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
}

select option {
    padding: 8px 12px !important;
    font-size: 15px !important;
    white-space: normal !important;
}

/* Select2 styling */
.select2-container {
    min-width: 300px !important;
}

.select2-container--admin-autocomplete .select2-selection--single {
    min-width: 300px !important;
    height: 42px !important;
    padding: 10px 12px !important;
    border: 2px solid var(--border-color) !important;
    border-radius: 6px !important;
}

.select2-container--admin-autocomplete.select2-container--focus .select2-selection--single {
    border-color: var(--accent-color) !important;
}

/* ============================================
   6. TABLES & CHANGE LISTS
   ============================================ */
#changelist {
    background: var(--white);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

#changelist table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: auto !important;
}

#changelist table thead th {
    background: linear-gradient(135deg, #e8f4f8 0%, #d4e9f2 100%) !important;
    color: #2c5366 !important;
    font-size: 15px !important;
    font-weight: 600;
    padding: 15px 12px !important;
    text-align: left;
    border: none !important;
    border-bottom: 2px solid #b8dae8 !important;
}

#changelist table thead th a {
    color: #2c5366 !important;
    text-decoration: none;
}

#changelist table thead th a:hover {
    text-decoration: underline;
    color: #1a3f52 !important;
}

/* Set width for specific header columns */
#changelist table thead th.column-payment_status,
#changelist table thead th.column-billing_type,
#changelist table thead th.column-status {
    min-width: 220px !important;
    width: 220px !important;
}

#changelist table tbody td {
    font-size: 15px !important;
    padding: 14px 12px !important;
    border-bottom: 1px solid var(--light-bg);
    white-space: nowrap !important;
    overflow: visible !important;
}

/* Ensure status/type columns have enough width */
#changelist table tbody td.field-payment_status,
#changelist table tbody td.field-billing_type,
#changelist table tbody td.field-status {
    min-width: 220px !important;
    width: 220px !important;
    white-space: normal !important;
    word-wrap: break-word !important;
}

#changelist table tbody tr {
    transition: background-color 0.2s ease;
}

#changelist table tbody tr:hover {
    background-color: #f8f9fa !important;
}

#changelist table tbody tr:nth-child(even) {
    background-color: #fafbfc;
}

/* ============================================
   7. BUTTONS & ACTIONS
   ============================================ */
.button,
input[type="submit"],
input[type="button"],
.submit-row input,
button[type="submit"] {
    font-size: 15px !important;
    padding: 11px 20px !important;
    border: none !important;
    border-radius: 6px !important;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    text-transform: none;
    box-shadow: var(--shadow);
}

.button.default,
input[type="submit"].default,
.submit-row input[type="submit"] {
    background: linear-gradient(135deg, var(--accent-color) 0%, #2980b9 100%) !important;
    color: var(--white) !important;
}

.button.default:hover,
input[type="submit"].default:hover,
.submit-row input[type="submit"]:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.button.delete-link,
.deletelink-box a.deletelink {
    background: linear-gradient(135deg, var(--danger-color) 0%, #c0392b 100%) !important;
    color: var(--white) !important;
}

.button.delete-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
}

/* Actions dropdown and GO button */
.actions {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    padding: 15px 20px !important;
    background: var(--light-bg);
    border-radius: 8px;
    margin-bottom: 20px;
}

.actions select,
select[name="action"],
.actions select[name="action"] {
    min-width: 550px !important;
    width: 550px !important;
    max-width: 550px !important;
    height: 42px !important;
    line-height: 20px !important;
    font-size: 14px !important;
    padding: 10px 40px 10px 12px !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 6px !important;
    background: white !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05) !important;
    transition: all 0.2s ease !important;
    overflow: visible !important;
    text-overflow: clip !important;
}

/* ============================================
   8. CHANGE-FORM OVERFLOW FIX
   Ensure related-object dropdowns (add/change/delete) and select action
   menus are not clipped on the admin change form. This keeps the small
   related-object action buttons and popup menus visible even when the
   surrounding module uses rounded corners or shadows.
   ============================================ */

/* Allow module content to overflow in the main change form area so
   related widgets and dropdowns are visible. */
#content .module {
    overflow: visible !important;
}

/* Ensure related widget popups and select dropdowns appear above other
   elements. */
.related-widget, .related-widget-wrapper, .related-widget .related-lookup {
    z-index: 9999 !important;
}

/* Add a high z-index for Select2 dropdowns used in admin autocompletes */
.select2-container--open { z-index: 99999 !important; }

/* Ensure fieldsets and form rows in change forms don't clip related widgets */
fieldset.module, .inline-group, .form-row, .form-row .field-box {
    overflow: visible !important;
}

/* Related buttons (+ change delete) next to selects should be visible */
.related-widget-wrapper, .related-widget, .related-lookup, .add-related, .related-lookup a {
    position: relative !important;
    z-index: 99999 !important;
}

/* Specific: ensure the admin's select2 dropdown and action popovers are on top */
.select2-container--open, .popover, .dropdown-menu {
    z-index: 100000 !important;
}


.actions button[type="submit"],
.actions input[type="submit"],
.actions .button {
    height: 42px !important;
    line-height: 42px !important;
    padding: 0 20px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 15px !important;
    margin: 0 !important;
    background: linear-gradient(135deg, var(--accent-color) 0%, #2980b9 100%) !important;
    color: var(--white) !important;
}

.actions button[type="submit"]:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.actions label {
    display: inline-flex !important;
    align-items: center !important;
    margin-right: 10px !important;
    font-weight: 600;
}

/* ============================================
   8. FIELDSETS & SECTIONS
   ============================================ */
fieldset.module {
    background: var(--white);
    border: 2px solid var(--light-bg);
    border-radius: 8px;
    padding: 0;
    margin-bottom: 20px;
}

fieldset h2 {
    background: linear-gradient(135deg, #e8f4f8 0%, #d4e9f2 100%) !important;
    color: #2c5366 !important;
    font-size: 17px !important;
    font-weight: 600;
    padding: 12px 20px !important;
    margin: 0 !important;
    border-radius: 6px 6px 0 0;
    border-bottom: 2px solid #b8dae8;
}

fieldset .description {
    padding: 12px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid var(--light-bg);
    font-size: 14px;
    color: var(--text-muted);
}

/* ============================================
   9. HELP TEXT & MESSAGES
   ============================================ */
.help, .help-block, p.help {
    font-size: 13px !important;
    color: var(--text-muted);
    margin-top: 6px;
    font-style: italic;
}

.messagelist {
    padding: 0;
    margin: 0 0 20px 0;
}

.messagelist li {
    font-size: 15px !important;
    padding: 14px 20px !important;
    border-radius: 6px;
    margin-bottom: 10px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 10px;
}

.messagelist .success {
    background: linear-gradient(135deg, var(--success-color) 0%, #229954 100%) !important;
    color: var(--white) !important;
}

.messagelist .warning {
    background: linear-gradient(135deg, var(--warning-color) 0%, #e67e22 100%) !important;
    color: var(--white) !important;
}

.messagelist .error {
    background: linear-gradient(135deg, var(--danger-color) 0%, #c0392b 100%) !important;
    color: var(--white) !important;
}

.messagelist .info {
    background: linear-gradient(135deg, var(--accent-color) 0%, #2980b9 100%) !important;
    color: var(--white) !important;
}

/* ============================================
   10. DASHBOARD & HOME
   ============================================ */
#content-main {
    width: 100%;
}

.dashboard .module table th {
    background: var(--light-bg);
    font-weight: 600;
    padding: 12px !important;
}

.dashboard .module table td {
    padding: 12px !important;
}

/* ============================================
   11. FILTERS & SIDEBAR
   ============================================ */
#changelist-filter {
    background: var(--white);
    border-left: 3px solid var(--accent-color);
    border-radius: 8px;
    padding: 20px;
    box-shadow: var(--shadow);
}

#changelist-filter h2 {
    font-size: 16px;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--light-bg);
}

#changelist-filter h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dark);
    margin-top: 20px;
    margin-bottom: 10px;
}

#changelist-filter ul {
    padding: 0;
    list-style: none;
}

#changelist-filter li {
    padding: 8px 0;
}

#changelist-filter a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.3s ease;
    padding: 4px 8px;
    border-radius: 4px;
    display: block;
}

#changelist-filter a:hover {
    background: var(--light-bg);
    color: var(--primary-color);
}

#changelist-filter a.selected {
    background: var(--accent-color);
    color: var(--white);
    font-weight: 600;
}

/* ============================================
   12. INLINE FORMS
   ============================================ */
.inline-related {
    background: var(--white);
    border: 2px solid var(--light-bg);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
}

.inline-related h3 {
    background: var(--light-bg);
    padding: 10px 15px;
    margin: -15px -15px 15px -15px;
    border-radius: 6px 6px 0 0;
    font-weight: 600;
}

.inline-related select {
    min-width: 250px !important;
}

/* ============================================
   13. SEARCH BAR
   ============================================ */
#changelist-search {
    background: var(--white);
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

#changelist-search input[type="text"] {
    width: auto !important;
    min-width: 300px;
    max-width: 500px;
    padding: 12px 15px !important;
}

#changelist-search input[type="submit"] {
    margin-left: 10px;
}

/* ============================================
   14. PAGINATION
   ============================================ */
.paginator {
    font-size: 14px;
    padding: 15px 20px;
    background: var(--white);
    border-radius: 8px;
    margin-top: 20px;
}

.paginator a,
.paginator span {
    padding: 6px 12px;
    margin: 0 2px;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.paginator a {
    color: var(--accent-color);
    text-decoration: none;
}

.paginator a:hover {
    background: var(--accent-color);
    color: var(--white);
}

.paginator .this-page {
    background: var(--accent-color);
    color: var(--white);
    font-weight: 600;
}

/* ============================================
   15. RESPONSIVE DESIGN
   ============================================ */
@media screen and (max-width: 768px) {
    #content {
        padding: 15px !important;
    }

    select,
    select:not([multiple]),
    .form-row select,
    .actions select {
        min-width: 100% !important;
    }

    .actions {
        flex-direction: column;
        align-items: stretch !important;
    }

    .actions select,
    .actions button[type="submit"] {
        width: 100% !important;
        min-width: 100% !important;
    }
}

/* ============================================
   16. UTILITY CLASSES
   ============================================ */
.card {
    background: var(--white);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
}

.badge-success {
    background: var(--success-color);
    color: var(--white);
}

.badge-warning {
    background: var(--warning-color);
    color: var(--white);
}

.badge-danger {
    background: var(--danger-color);
    color: var(--white);
}

.badge-info {
    background: var(--accent-color);
    color: var(--white);
}

/* ============================================
   FINAL OVERRIDES - Actions dropdown must be 550px
   ============================================ */
#changelist .actions select,
#changelist select[name="action"],
.changelist-form .actions select,
form .actions select[name="action"],
.actions select[name="action"] {
    min-width: 550px !important;
    width: 550px !important;
    max-width: 550px !important;
}
