:root {
    --bg-color: #f3f4f6;
    --surface-color: #ffffff;
    --border-color: #e5e7eb;
    --primary-color: #2563eb;
    --primary-light: #dbeafe;
    --text-color: #1f2937;
    --text-muted: #6b7280;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --radius: 8px;
    --transition: 0.2s ease;
    --sidebar-width: 250px;
    --topbar-height: 60px;
}

[data-theme="dark"] {
    --bg-color: #111827;
    --surface-color: #1f2937;
    --border-color: #374151;
    --text-color: #f9fafb;
    --text-muted: #9ca3af;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
}

/* Authentication (Login) keeps its special background */
.auth-body {
    background: linear-gradient(-45deg, #1a1a2e, #16213e, #0f3460, #e94560);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

@keyframes gradientBG {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

.auth-container {
    padding: 20px;
    width: 100%;
    display: flex;
    justify-content: center;
}

.auth-card {
    background: rgba(22, 33, 62, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 50px 40px;
    border-radius: 20px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: transform 0.4s ease;
}

.auth-card:hover {
    transform: translateY(-8px);
}

.auth-header {
    text-align: center;
    margin-bottom: 35px;
}

.auth-header h1 {
    font-size: 2.2rem;
    margin-bottom: 5px;
    color: #fff;
}

.auth-header p {
    color: #aaa;
}

.form-group {
    margin-bottom: 22px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    letter-spacing: 0.5px;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 15px;
    color: #888;
    font-size: 1.1rem;
    transition: color var(--transition);
}

/* Base form control */
.form-control {
    width: 100%;
    padding: 10px 12px;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-color);
    font-size: 1rem;
    transition: all 0.3s ease;
    outline: none;
}

.form-control::placeholder {
    color: var(--text-muted);
}

.form-control:focus {
    border-color: var(--primary-color);
}

/* Ensure select dropdown options are readable */
.form-control option {
    color: var(--text-color);
    background: var(--surface-color);
}

/* Authentication (Login) keeps its special background */
.auth-body .form-control {
    padding: 14px 15px 14px 45px;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
}

.auth-body .form-control::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.auth-body .form-control:focus {
    border-color: #e94560;
    background-color: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 15px rgba(233, 69, 96, 0.3);
}

.auth-body .form-control:focus+.input-icon,
.auth-body .input-wrapper:focus-within .input-icon {
    color: #e94560;
}

.btn-glow {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 14px 20px;
    background: linear-gradient(135deg, #e94560, #ff6b81);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-glow:hover {
    box-shadow: 0 5px 15px rgba(233, 69, 96, 0.4);
    transform: translateY(-2px);
}

.alert {
    padding: 12px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 0.9rem;
    background: rgba(233, 69, 96, 0.1);
    color: #ff6b81;
    border: 1px solid rgba(233, 69, 96, 0.2);
}

.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 0.9rem;
}

.auth-footer a {
    color: #e94560;
    text-decoration: none;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* -------------------------------------------
   APP LAYOUT (Light CRM Style)
------------------------------------------- */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
    flex-shrink: 0;
}

.sidebar-header {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
}

.sidebar-header i {
    margin-right: 10px;
    font-size: 1.5rem;
}

.sidebar-user {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    border-bottom: 1px solid var(--border-color);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--primary-light);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.1rem;
}

.user-info h4 {
    font-size: 0.9rem;
    color: var(--text-color);
}

.user-info p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.sidebar-nav {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px 0;
    list-style: none;
}

.nav-item {
    padding: 5px 15px;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    color: var(--text-color);
    text-decoration: none;
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 0.95rem;
    transition: background-color 0.2s, color 0.2s;
}

.nav-link i.icon {
    width: 24px;
    font-size: 1.1rem;
    color: var(--text-muted);
    transition: color 0.2s;
}

.nav-link:hover {
    background-color: var(--bg-color);
}

.nav-link.active {
    background-color: var(--primary-light);
    color: var(--primary-color);
}

.nav-link.active i.icon {
    color: var(--primary-color);
}

.sub-menu {
    list-style: none;
    padding-left: 45px;
    display: none;
}

.has-submenu .nav-link i.caret {
    margin-left: auto;
    font-size: 0.8rem;
    transition: transform 0.2s;
}

/* Base Main ContentWrapper */
.main-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Topbar */
.topbar {
    height: var(--topbar-height);
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 25px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
}

.search-box {
    display: flex;
    align-items: center;
    background-color: var(--bg-color);
    padding: 8px 15px;
    border-radius: 20px;
    width: 300px;
    border: 1px solid var(--border-color);
}

.search-box input {
    border: none;
    background: transparent;
    outline: none;
    margin-left: 10px;
    width: 100%;
    color: var(--text-color);
}

.btn-add {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: transform 0.2s;
}

.btn-add:hover {
    transform: scale(1.05);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.topbar-icon {
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.2s;
}

.topbar-icon:hover {
    color: var(--primary-color);
}

/* Pages / Main Body */
.page-content {
    padding: 25px;
    overflow-y: auto;
    flex-grow: 1;
    background-color: var(--bg-color);
}

/* Alert */
.alert-banner {
    background-color: #fffbeb;
    border: 1px solid #fde68a;
    border-left: 4px solid var(--warning-color);
    padding: 15px 20px;
    border-radius: var(--radius);
    margin-bottom: 25px;
}

.alert-banner h4 {
    color: #b45309;
    margin-bottom: 5px;
    font-size: 0.95rem;
}

.alert-banner p {
    color: #92400e;
    font-size: 0.85rem;
}

/* Dashboard Grid */
.dash-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 25px;
}

.stat-card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.stat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 15px;
    font-weight: 500;
}

.stat-main {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.stat-main h3 {
    font-size: 1.5rem;
    color: var(--text-color);
}

.stat-main span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.progress-bar-container {
    height: 4px;
    background-color: var(--bg-color);
    border-radius: 2px;
    margin-top: 15px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    border-radius: 2px;
}

/* Main layout grid */
.main-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 25px;
}

.panel {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
}

.panel-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h3 {
    font-size: 1rem;
    color: var(--text-color);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-header a {
    font-size: 0.85rem;
    color: var(--primary-color);
    text-decoration: none;
}

.panel-body {
    padding: 20px;
}

/* Summary Lists */
.summary-list {
    list-style: none;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.summary-item:last-child {
    border-bottom: none;
}

.summary-item .label {
    font-size: 0.9rem;
    font-weight: 500;
}

.summary-item .value {
    font-size: 0.9rem;
    font-weight: 600;
}

.text-success {
    color: var(--success-color);
}

.text-danger {
    color: var(--danger-color);
}

.text-primary {
    color: var(--primary-color);
}

/* Kanban Override for Light Mode */
.kanban-board {
    display: flex;
    gap: 20px;
    overflow-x: auto;
    padding-bottom: 10px;
    height: 100%;
}

.kanban-column {
    flex: 1;
    min-width: 320px;
    background-color: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 15px;
    display: flex;
    flex-direction: column;
}

.column-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

.column-header h3 {
    font-size: 1.05rem;
    font-weight: 600;
}

.task-count {
    background-color: var(--border-color);
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-color);
}

.kanban-tasks {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.kanban-task {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 15px;
    cursor: grab;
    transition: box-shadow 0.2s, transform 0.2s;
    position: relative;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.kanban-task:hover {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    transform: translateY(-2px);
}

.kanban-task:active {
    cursor: grabbing;
}

.kanban-task.dragging {
    opacity: 0.5;
    border: 2px dashed var(--primary-color);
}

.kanban-task h4 {
    margin-bottom: 5px;
    padding-right: 40px;
    font-size: 0.95rem;
    color: var(--text-color);
}

.kanban-task p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 15px;
}

.task-dates {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--bg-color);
    padding: 4px 8px;
    border-radius: 4px;
}

.task-actions {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.kanban-task:hover .task-actions {
    opacity: 1;
}

.task-actions button {
    background: none;
    border: none;
    color: #cbd5e1;
    cursor: pointer;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.task-actions .edit-task:hover {
    color: var(--primary-color);
}

.task-actions .delete-task:hover {
    color: var(--danger-color);
}

/* Buttons */
.btn-primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: var(--radius);
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn-primary:hover {
    opacity: 0.9;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background-color: var(--surface-color);
    padding: 30px;
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content input,
.modal-content textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-color);
    margin-bottom: 15px;
    outline: none;
}

.modal-content input:focus,
.modal-content textarea:focus,
.modal-content select:focus {
    border-color: var(--primary-color);
}

.modal-content label {
    color: var(--text-color);
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 5px;
    display: block;
}

.close-modal {
    position: absolute;
    top: 20px;
    right: 20px;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.close-modal:hover {
    color: var(--danger-color);
}

.form-group-row {
    display: flex;
    gap: 20px;
}

.form-group-row .form-group {
    flex: 1;
}

textarea.form-control {
    resize: vertical;
}

/* -------------------------------------
   GANTT CHART OVERRIDES & CUSTOMIZATION
------------------------------------- */

.gantt-view-modes button {
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.gantt-view-modes button.active {
    background: var(--surface-color);
    color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.gantt .bar-wrapper:hover .bar {
    opacity: 0.8;
}

/* Base Bar Color */
.gantt .bar {
    fill: var(--primary-color);
}

.gantt .bar-progress {
    fill: rgba(0, 0, 0, 0.2);
}

.gantt .bar-label {
    fill: #1e293b !important;
    font-weight: 600 !important;
    font-size: 13px !important;
    paint-order: stroke fill;
    stroke: rgba(255, 255, 255, 0.8) !important;
    stroke-width: 4px;
    stroke-linecap: round;
    stroke-linejoin: round;
    dominant-baseline: central;
}

.gantt .bar-label.big {
    fill: #ffffff !important;
    stroke: rgba(0, 0, 0, 0.4) !important;
    stroke-width: 3px;
}

/* Custom Status Bars injected by JS */
.gantt .bar-wrapper.bar-success .bar {
    fill: var(--success-color);
}

.gantt .bar-wrapper.bar-danger .bar {
    fill: var(--danger-color);
}

.gantt .bar-wrapper.bar-warning .bar {
    fill: var(--warning-color);
}

.gantt .grid-header {
    fill: var(--surface-color) !important;
}

.gantt .grid-row {
    fill: var(--bg-color) !important;
}

.gantt .grid-row:nth-child(even) {
    fill: var(--surface-color) !important;
}

.gantt .tick {
    stroke: var(--border-color) !important;
}

.gantt .tick-text {
    fill: var(--text-color) !important;
}

.gantt .lower-text,
.gantt .upper-text {
    fill: var(--text-color) !important;
    font-size: 12px;
}

.gantt-container {
    background: var(--bg-color) !important;
    border-radius: var(--radius);
}

.gantt .today-highlight {
    fill: rgba(59, 130, 246, 0.1) !important;
}

/* -------------------------------------
   PREMIUM ACTION BUTTONS
------------------------------------- */
.btn-action-premium {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: var(--surface-color);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin: 0 4px;
}

.btn-action-premium i {
    font-size: 0.9rem;
}

.btn-edit-premium {
    color: var(--primary-color);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.btn-edit-premium:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
    border-color: var(--primary-color);
}

.btn-delete-premium {
    color: var(--danger-color);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-delete-premium:hover {
    background: var(--danger-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.3);
    border-color: var(--danger-color);
}

/* -------------------------------------------
   MOBILE RESPONSIVENESS
------------------------------------------- */
@media (max-width: 768px) {

    /* Topbar */
    #mobile-menu-btn {
        display: inline-block !important;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        z-index: 1000;
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.1);
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.open {
        left: 0;
    }

    /* Overlay for mobile sidebar */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.open {
        display: block;
        opacity: 1;
    }

    .main-wrapper {
        width: 100vw;
    }

    /* Grids & Panels */
    .dash-grid {
        grid-template-columns: 1fr !important;
    }

    .main-grid {
        grid-template-columns: 1fr !important;
        grid-template-areas:
            "left"
            "right" !important;
    }

    .panel-body {
        padding: 15px;
    }

    /* Form Adjustments */
    .form-group-row {
        flex-direction: column;
        gap: 0;
    }

    .form-group-row .form-group {
        width: 100% !important;
        margin-right: 0 !important;
    }

    /* Modal adjustments */
    .modal-content {
        margin: 5% auto;
        width: 95%;
        padding: 20px;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* Tables */
    .table-container,
    table {
        display: block;
        width: 100%;
        overflow-x: auto;
    }

    th,
    td {
        white-space: nowrap;
    }

    /* Newsletter Editor Split */
    #newsletter-view .panel {
        flex-direction: column !important;
        height: auto !important;
        overflow: visible !important;
    }

    #newsletter-view .panel>div:first-child {
        width: 100% !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border-color);
    }

    #newsletter-preview-container {
        transform: scale(0.9) !important;
        transform-origin: top center;
    }

    /* Strategy AI Chat */
    #chat-view .panel {
        flex-direction: column !important;
        height: auto !important;
    }

    #chat-view>.panel>div:first-child {
        width: 100% !important;
        margin-right: 0 !important;
        margin-bottom: 15px !important;
        height: 250px !important;
        /* Cap the height of the session list on mobile */
    }

    #ai-strategy-main-pane,
    #generic-chat-main-pane {
        min-height: 500px !important;
    }

    #chat-form {
        flex-direction: column;
    }

    #chat-input {
        border-radius: var(--radius) !important;
    }

    #chat-submit-btn {
        width: 100%;
        border-radius: var(--radius) !important;
    }

    /* Kanban Board */
    .kanban-board {
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: auto;
        padding-bottom: 20px;
    }

    .kanban-column {
        min-width: 100%;
        height: auto;
        max-height: 500px;
        margin-bottom: 15px;
    }

    /* Hide search on mobile header */
    .search-box {
        display: none;
    }
}