:root {
    /* Base Colors (Discord Theme) */
    --bg-sidebar: #0f111a;
    --bg-main: #141721;
    --bg-card: #1c202d;
    --bg-input: #0f111a;
    --surface: rgba(255, 255, 255, 0.04);
    --surface-light: rgba(255, 255, 255, 0.08);
    --border-color: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.12);
    --text-main: #ffffff;
    --text-muted: #a0a0a0;
    --text-label: #707070;
    --primary: #5865f2;
    --primary-hover: #4752c4;
    --accent: #10b981;
    --danger: #ef4444;
    --discord: #5865f2;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 8px 16px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 16px 32px rgba(0, 0, 0, 0.3);
}

body.theme-midnight {
    --bg-sidebar: #000000;
    --bg-main: #050505;
    --bg-card: #0c0c0c;
    --bg-input: #000000;
    --border-color: rgba(255, 255, 255, 0.1);
    --primary: #a855f7;
    --primary-hover: #9333ea;
    --text-label: #71717a;
}

body.theme-forest {
    --bg-sidebar: #01120f;
    --bg-main: #021a16;
    --bg-card: #04241e;
    --bg-input: #01120f;
    --border-color: rgba(16, 185, 129, 0.2);
    --primary: #34d399;
    --primary-hover: #10b981;
    --text-label: #059669;
}

body.theme-ocean {
    --bg-sidebar: #020d1a;
    --bg-main: #041426;
    --bg-card: #061d33;
    --bg-input: #020d1a;
    --border-color: rgba(56, 189, 248, 0.2);
    --primary: #7dd3fc;
    --primary-hover: #38bdf8;
    --text-label: #0284c7;
}

body.theme-sunset {
    --bg-sidebar: #1a0505;
    --bg-main: #260a0a;
    --bg-card: #331111;
    --bg-input: #1a0505;
    --border-color: rgba(248, 113, 113, 0.2);
    --primary: #fb923c;
    --primary-hover: #f97316;
    --text-label: #b91c1c;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    overflow: hidden;
    height: 100vh;
}

.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* MAIN CONTENT */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-bar {
    padding: 0.75rem 1.5rem;
    background: var(--bg-sidebar);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    min-height: 64px;
    flex-shrink: 0;
    flex-wrap: wrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 100;
}

.top-bar-left, .top-bar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    width: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-brand .logo-box {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    box-shadow: 0 2px 4px rgba(88, 101, 242, 0.2);
}

.sidebar-brand h1 {
    font-size: 1rem;
    font-weight: 900;
    letter-spacing: -0.5px;
    color: var(--text-main);
    background: linear-gradient(to bottom, #fff, #ccc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-stats {
    display: flex;
    gap: 8px;
    padding-left: 1rem;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    height: 24px;
    align-items: center;
}

.stat-pill {
    background: rgba(255, 255, 255, 0.03);
    padding: 3px 8px;
    border-radius: 6px;
    display: flex;
    align-items: baseline;
    gap: 6px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.stat-pill:hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.stat-pill label {
    font-size: 0.55rem;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-pill span {
    font-size: 0.85rem;
    font-weight: 900;
    color: var(--primary);
    text-shadow: 0 0 8px rgba(88, 101, 242, 0.2);
}

.utility-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn-icon-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    padding: 5px 10px;
    border-radius: 15px;
    transition: all 0.2s;
    background: transparent;
}

.btn-icon-label:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.08);
}

.btn-icon-label span {
    font-size: 0.9rem;
}

.data-actions {
    display: flex;
    gap: 4px;
    background: rgba(255, 255, 255, 0.03);
    padding: 2px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-icon-only {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-muted);
}

.btn-icon-only:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    transform: scale(1.05);
}

.btn-icon-only.danger:hover {
    color: #ff4d4d;
    background: rgba(255, 77, 77, 0.15);
}

.divider {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0 2px;
}

.theme-dropdown {
    height: 28px;
    padding: 0 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-main);
    cursor: pointer;
    outline: none;
    transition: all 0.2s;
}

.theme-dropdown:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
}

.page-title h2 { font-size: 1.25rem; font-weight: 800; }
.page-title p { font-size: 0.8rem; color: var(--text-muted); }

.top-stats { display: flex; gap: 0.75rem; align-items: center; }
.data-controls { display: flex; gap: 0.5rem; }

.theme-dropdown:focus {
    border-color: var(--primary);
}

/* CONTENT AREA */
.content-viewport {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* UNIFIED GRID */
.dashboard-unified-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 1.5rem;
    align-items: stretch;
    grid-auto-rows: minmax(280px, auto);
}

.dispatch-input { grid-column: span 4; }
.output-module { grid-column: span 4; }
.history-module { grid-column: span 4; }

.ingame-module { grid-column: span 6; }
.discord-ads-module { grid-column: span 6; }

.ingame-module, .discord-ads-module {
    min-height: 360px;
}

.card-form-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* MODULE CARDS */
.module-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    height: 100%; /* Ensure card fills grid cell */
}

.module-header {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.module-icon {
    width: 40px; height: 40px;
    background: var(--bg-sidebar);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem; flex-shrink: 0;
}
.module-icon.highlight { color: var(--primary); border: 1px solid var(--primary); }

.module-header h3 { font-size: 1rem; font-weight: 700; }
.module-header p { font-size: 0.75rem; color: var(--text-muted); }

.module-body { 
    padding: 1.5rem; 
    flex-grow: 1; 
    display: flex; 
    flex-direction: column; 
    gap: 1.25rem;
    overflow-y: auto; /* Allow body to scroll if content exceeds fixed height */
    min-height: 0;
}

.module-body.scrollable { 
    padding-right: 0.75rem;
}

/* Custom Scrollbar */
.module-body::-webkit-scrollbar {
    width: 6px;
}
.module-body::-webkit-scrollbar-track {
    background: transparent;
}
.module-body::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}
.module-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-label);
}

.module-footer {
    padding: 1rem 1.5rem; /* Slightly reduced vertical padding for tighter fit */
    background: var(--bg-sidebar);
    display: flex; 
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
    min-height: 64px; /* Ensure consistent footer height */
    border-top: 1px solid var(--border-color);
}

/* FORM */
.form-stack { display: flex; flex-direction: column; gap: 1.25rem; }
.input-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.input-group { display: flex; flex-direction: column; gap: 0.5rem; }
.input-group label { font-size: 0.7rem; font-weight: 800; color: var(--text-label); text-transform: uppercase; }

.multi-input-stack {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.multi-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.multi-input-row input {
    flex-grow: 1;
}

.btn-remove-input {
    background: transparent;
    border: none;
    color: var(--danger);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
}

input[type="text"], textarea {
    width: 100%; /* Ensure boxes fill the container */
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: white; padding: 0.75rem; font-size: 0.9rem; transition: all 0.2s;
}
input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(88, 101, 242, 0.15); }

textarea { font-family: 'JetBrains Mono', monospace; line-height: 1.5; resize: none; }
#output-box { 
    flex: 1;
    min-height: 180px; 
}
#discord-input { min-height: 150px; }

/* Ensure consistent button heights in footers */
.module-footer .btn {
    height: 42px;
}

/* AUTH SECTION */
.auth-group {
    height: 100%;
    display: flex;
    align-items: center;
    padding-left: 0.75rem;
}

.login-buttons {
    display: flex;
    gap: 0.5rem;
}

.btn-auth {
    padding: 0 12px;
    height: 30px;
    background: #fff;
    color: #111;
    border-radius: 15px;
    font-weight: 700;
    font-size: 0.75rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    border: none;
    cursor: pointer;
}

.btn-auth.btn-discord {
    background: #5865f2;
    color: #fff;
}

.btn-auth.btn-discord:hover {
    background: #4752c4;
}

.btn-auth img {
    width: 14px;
    height: 14px;
}

.btn-auth:hover {
    background: #f0f0f0;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.user-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 2px 2px 10px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    height: 32px;
    box-shadow: inset 0 1px 1px rgba(255,255,255,0.05);
}

.user-pill img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.2);
}

.user-pill span {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.2px;
}

.logout-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 50%;
    transition: all 0.2s;
}

.logout-icon:hover {
    background: rgba(255, 77, 77, 0.15);
    color: #ff4d4d;
}

/* BUTTONS */
.btn {
    padding: 0.6rem 1.25rem; border-radius: var(--radius-sm);
    font-weight: 700; font-size: 0.85rem; cursor: pointer; border: none;
    transition: all 0.15s; display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
}
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: transparent; color: white; border: 1px solid var(--border-color); }
.btn-secondary:hover { background: rgba(255,255,255,0.05); }
.btn-accent { background: var(--accent); color: white; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: white; }
.btn-sm { padding: 0.35rem 0.6rem; font-size: 0.7rem; }
.btn-discord { background: #5865f2; color: white; }
.btn-discord:hover { background: #4752c4; }
.btn-text { background: none; border: none; font-size: 0.75rem; font-weight: 700; cursor: pointer; }
.btn-text.danger { color: var(--danger); }

/* QUEUE */
.queue-area { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px dashed var(--border-color); }
.queue-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.queue-header h4 { font-size: 0.8rem; color: var(--text-muted); }
.queue-list { list-style: none; }
.queue-item {
    background: var(--bg-input); border-radius: 4px; padding: 0.5rem 0.75rem;
    display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.4rem; font-size: 0.8rem;
}
.queue-item button { background: none; border: none; color: var(--danger); cursor: pointer; }

/* HISTORY LIST */
.small-list .history-item { 
    padding: 0.85rem; 
    font-size: 0.75rem; 
    margin-bottom: 0.6rem; 
    border-radius: 6px;
}
.small-list .history-content { 
    font-size: 0.7rem; 
    padding: 0.6rem; 
    border-radius: 4px;
    margin-bottom: 0.6rem;
}

.history-item { 
    background: var(--bg-card); 
    border: 1px solid var(--border-color); 
    transition: border-color 0.2s;
}
.history-item:hover {
    border-color: var(--primary);
}
.history-item .meta { 
    display: flex; 
    justify-content: space-between; 
    margin-bottom: 0.4rem; 
    color: var(--text-label); 
    font-weight: 700; 
}
.history-content { 
    background: var(--bg-sidebar); 
    font-family: 'JetBrains Mono', monospace; 
    white-space: pre-wrap; 
    border: 1px solid var(--border-color);
}

/* CRAFTER TOOLBAR */
.discord-toolbar { display: flex; gap: 0.75rem; margin-bottom: 0.75rem; padding: 0.5rem 0; background: transparent; border: none; border-bottom: 1px solid var(--border-color); border-radius: 0; }
.tool-group { display: flex; gap: 0.4rem; }
.discord-toolbar button { width: 34px; height: 34px; background: var(--bg-input); border: 1px solid var(--border-color); color: white; border-radius: 4px; cursor: pointer; transition: all 0.2s; }
.discord-toolbar button:hover { border-color: var(--primary); color: var(--primary); }
.divider { width: 1px; background: var(--border-color); margin: 0 0.5rem; }

/* ADS GRID */
.ads-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1.25rem; }
.ads-grid-mini { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.25rem; }
.ad-item { 
    background: var(--bg-sidebar); 
    border-radius: var(--radius-md); 
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.2s, border-color 0.2s;
}
.ad-item:hover {
    border-color: var(--primary);
}
.ad-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem 0.5rem;
}
.ad-item-content {
    padding: 0.5rem 1.25rem 1.25rem;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}
.ad-delete-btn {
    font-size: 1.5rem;
    color: var(--danger);
    cursor: pointer;
    line-height: 1;
    background: transparent;
    border: none;
}
.ad-char-counter {
    font-size: 0.75rem;
    color: var(--text-label);
    text-align: right;
    margin-top: 0.5rem;
    font-weight: 800;
    text-transform: uppercase;
}
.ad-char-counter.limit-reached {
    color: var(--danger);
}
.ad-item input { background: transparent; border: none; font-weight: 800; color: white; font-size: 1rem; flex: 1; }
.ad-item textarea { min-height: 120px; font-size: 0.9rem; margin-bottom: 0; flex-grow: 1; background: var(--bg-input); border: 1px solid var(--border-color); color: white; padding: 1rem; border-radius: var(--radius-sm); }
.ad-footer {
    padding: 0.75rem 1.25rem;
    background: var(--bg-sidebar);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    border-top: 1px solid var(--border-color);
}

.discord-preview-box u {
    text-decoration: underline !important;
}

.app-credit {
    padding: 1rem 0;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-label);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.6;
}

@media (max-width: 1400px) {
    .dashboard-unified-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-areas: 
            "input output"
            "history history"
            "ingame crafter";
    }
}