/* ==========================================================================
    Modern & Dynamic B2B Web App Design (Blue & Purple Theme)
    ========================================================================== */

/* === Root Variables: Blue/Purple Palette & Design Tokens === */
:root {
    --primary-blue: #2563eb;
    --primary-purple: #7c3aed;
    --secondary-purple: #9333ea;
    --dark-bg: #1e1b4b;
    --text-light: #f5f3ff;
    --text-dark: #1f2937;
    --text-medium: #6b7280;
    --bg-white: #ffffff;
    --bg-light-gray: #f8fafc;
    --danger-color: #ef4444;
    --success-color: #22c55e;
    --motion-gradient: linear-gradient(-45deg, var(--primary-blue), #3b82f6, var(--primary-purple), var(--secondary-purple));
    --static-gradient: linear-gradient(90deg, var(--primary-blue) 0%, var(--primary-purple) 100%);
    --glow-effect: rgba(99, 102, 241, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.07), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
    --transition: 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    --border-radius: 12px;
}

/* === Keyframes for the animated gradient === */
@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === Base & Typography === */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
body {
    display: flex;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text-dark);
    background-color: var(--bg-light-gray);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}
h1, h2, h3 {
    font-weight: 600;
    color: var(--text-dark);
}
a {
    color: var(--primary-purple);
    text-decoration: none;
    transition: var(--transition);
}
a:hover {
    text-decoration: underline;
    filter: brightness(1.1);
}

/* === Layout: Sidebar and Main Content === */
.sidebar {
    width: 280px;
    flex-shrink: 0;
    padding: 24px;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    color: var(--text-light);
    background: var(--motion-gradient);
    background-size: 400% 400%;
    animation: gradientBG 12s ease infinite;
}
.main-content {
    flex-grow: 1;
    height: 100vh;
    overflow-y: auto;
    padding: 32px;
    background-color: var(--bg-white);
}
.container {
    max-width: 900px;
    margin: 0 auto;
}

/* === Sidebar Styling === */
.sidebar-title {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    text-align: center;
    color: var(--text-light);
}
.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    padding-top: 1rem;
}
.user-name, .user-email {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}
.user-name { font-weight: 600; color: var(--text-light); }
.user-email { font-size: 0.875rem; color: var(--text-light); opacity: 0.8; }
.user-info { margin-bottom: 1rem; }

/* === General Button Styling === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 10px 20px;
    border-radius: var(--border-radius);
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
    text-align: center;
}
.btn:active { transform: scale(0.98); }

.sidebar .btn {
    width: 100%;
    background-color: var(--bg-white);
    color: var(--primary-blue);
    border: none;
}
.sidebar .btn:hover {
    background-color: #f0f2ff;
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* === Component: Cards === */
.card {
    background-color: var(--bg-white);
    border: 1px solid #e5e7eb;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    margin-bottom: 1.5rem;
    overflow: hidden; /* Added to contain children during animation */
}
.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    font-size: 1.25rem;
    display: flex; /* Added for alignment */
    justify-content: space-between; /* Added for alignment */
    align-items: center; /* Added for alignment */
}
.card-header i {
    margin-right: 0.75rem;
    background: var(--static-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.card-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    transition: max-height 0.4s ease-in-out, padding 0.4s ease-in-out; /* Added for smooth collapse */
}

/* === NEW: Collapsible Card Styles === */
.card-toggle {
    cursor: pointer;
}
.card-arrow {
    transition: transform 0.3s ease;
    color: var(--text-medium);
}
.collapsible .card-body {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden; /* Keep this to hide content when collapsed */
    transition: max-height 0.4s ease-in-out, padding 0.4s ease-in-out, border-top 0.4s ease-in-out; /* Add border-top to transition */
}

.collapsible.open .card-body {
    max-height: 5000px; /* INCREASE THIS VALUE SIGNIFICANTLY, or use a JS-based height calculation for perfect fit */
    padding: 1.5rem;
    border-top: 1px solid #e5e7eb;
    overflow: visible; /* Allow content to be fully visible when open */
}

.collapsible.open .card-arrow {
    transform: rotate(180deg);
}
/* === End New Styles === */

/* === Form Fields & Inputs === */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.input-group label {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-medium);
}
.input-group input,
.input-group textarea,
.input-group select {
    width: 100%;
    padding: 12px 16px;
    background-color: var(--bg-white);
    color: var(--text-dark);
    border-radius: var(--border-radius);
    font-size: 1rem;
    transition: var(--transition);
    appearance: none;
    border: 2px solid #e5e7eb;
}
.input-group input:focus,
.input-group textarea:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px var(--glow-effect);
}

/* === Utility & Feedback Classes === */
.hidden { display: none !important; }

.feedback-toast {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    padding: 16px 24px;
    border-radius: var(--border-radius);
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    transition: bottom 0.5s cubic-bezier(0.25, 1, 0.5, 1);
    border: 1px solid transparent;
}
.feedback-toast.show { bottom: 20px; }
.feedback-toast.success { background-color: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.feedback-toast.error { background-color: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.feedback-toast.info { background-color: #e0e7ff; color: #3730a3; border-color: #c7d2fe; }

/* ==========================================================================
    Layout and Alignment Fixes
    ========================================================================== */

/* --- Main Layout & Centering --- */
.main-header {
    text-align: center;
    margin-bottom: 2rem;
}
.form-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 2rem;
    flex-wrap: wrap;
}
.form-actions .btn {
    background: var(--static-gradient);
    border: none;
    color: var(--text-light);
}
.form-actions .btn:hover {
    filter: brightness(1.1);
    box-shadow: 0 0 20px var(--glow-effect);
}

/* --- Sidebar Navigation List --- */
.campaign-nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1.5rem; /* Added space below the 'New Campaign' button */
}

.folder-header {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.2s ease-in-out;
    font-weight: 600;
}

.folder-header:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.folder-header .folder-icon {
    margin-right: 0.75rem;
    width: 20px;
    text-align: center;
}

.folder-header .folder-arrow {
    margin-left: auto;
    transition: transform 0.3s ease;
}

.campaigns-in-folder {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.folder-container.open .campaigns-in-folder {
    max-height: 1000px;
}

.folder-container.open .folder-arrow {
    transform: rotate(90deg);
}

.campaigns-in-folder li {
    padding: 8px 10px 8px 45px;
    margin: 2px 0;
    border-radius: 8px;
    color: var(--text-light);
    opacity: 0.8;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.campaigns-in-folder li:hover {
    background-color: rgba(255, 255, 255, 0.1);
    opacity: 1;
}
.campaigns-in-folder li.active {
    background: var(--bg-white);
    color: var(--primary-blue);
    font-weight: 600;
    opacity: 1;
}
.campaign-list-name {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.campaign-delete-btn {
    flex-shrink: 0;
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    opacity: 0.6;
    transition: var(--transition);
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.campaigns-in-folder li:hover .campaign-delete-btn {
    opacity: 0.8;
}
.campaign-delete-btn:hover {
    opacity: 1;
    color: var(--text-light);
    background-color: rgba(239, 68, 68, 0.5);
}
.campaigns-in-folder li.active .campaign-delete-btn {
    color: var(--text-medium);
}
.campaigns-in-folder li.active .campaign-delete-btn:hover {
    color: var(--bg-white);
    background-color: var(--danger-color);
}

/* --- Dynamic Form Fields & Spacing --- */
.dynamic-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.card-body:not(.grid-2-col) > .input-group + .input-group {
    margin-top: 1.5rem;
}

.dynamic-header, .sitelink-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* FINAL FIX: Use absolute positioning to avoid conflicts */
.dynamic-input-wrapper {
    position: relative; /* Creates a positioning context for the button */
}

/* Task 1: Add a subtle glow to add buttons on hover */
.dynamic-header .btn:hover {
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.15);
}

.dynamic-input-wrapper input,
.dynamic-input-wrapper textarea {
    width: 100%; /* Makes the input field fill the wrapper */
    /* Adds space on the right for the button. Overrides default padding. */
    padding-right: 44px !important;
}

/* Task 2: Style the remove button with a theme-matching red color */
.btn-remove-dynamic {
    position: absolute; /* Positions the button inside the input field's space */
    top: 50%;
    transform: translateY(-50%); /* Centers the button vertically */
    right: 8px; /* Positions the button on the far right */
    background-color: transparent;
    border: none;
    color: var(--text-medium);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    line-height: 1;
    transition: all var(--transition);
}

.btn-remove-dynamic:hover {
    background-color: var(--danger-color);
    color: var(--bg-white);
}

/* --- Grid & Sitelink Blocks --- */
.grid-2-col {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
}
.grid-span-2 {
    grid-column: span 2 / span 2;
}
.sitelink-block {
    position: relative;
    padding: 1rem;
    border: 1px solid #e5e7eb;
    border-radius: var(--border-radius);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}


.sitelink-block .btn-remove-dynamic {
    top: 0.75rem;
    right: 0.75rem;
    left: auto;
    transform: none;
}